From: skaller <skaller@users.sourceforge.net>
To: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] environment idiom
Date: 10 Dec 2004 13:30:48 +1100 [thread overview]
Message-ID: <1102645847.2611.417.camel@pelican.wigram> (raw)
In-Reply-To: <20041210.081159.105772440.garrigue@math.nagoya-u.ac.jp>
On Fri, 2004-12-10 at 10:11, Jacques Garrigue wrote:
> But you're right that in practice global variables are in general
> sufficient to solve this problem, and they are often used in ocaml for
> that. They have of course one disadvantage: they are not reentrant.
Yes but global/local is a relative thing in sane languages
like Ocaml which support nested scopes. One might even
say it is one of *the* fundamental software engineering
design problems, to try to make variables as local
as possible without pointless explicit passing.
Since software changes, this may not be the theoretically
optimal position.
A simple example is an array search in C where the loop variable
needs to be external to the loop to actually return the desired
result. For Ocaml I find often, I have repeated code handling
match cases which share variables and that when I lifted the
common code into a subroutine, I often want to make it
slightly more global than the scope containing the match,
and in doing so I have to now explicitly pass extra variables.
I often don't actually know what they are -- the compiler
reports unbound variables and I add paramaters until it
compiles, thus discovering something previously hidden.
Occasionally this procedure fails .. in one case I had
used the common Ocaml trick of hiding a more global variable
with a more local one .. and in lifting the code outside
the scope of the local one but still within the scope
of the more global one, I inadvertantly changed the
semantics of the code without breaking it, as my lifting
procedure required.. that bug took hours to find.
The lack of re-entrany Jacques mentions is thus not
limited to absolutely global variables as in C statics.
It not only applies to *all* variables in functional
languages .. it is particularly applicable in Ocaml
which is not referentially transparent.
One final point of some interest is that even
'absolutely' global variables may not be.
In Pascal, globals are actually just elements
of the deepest stack frame. In Posix C,
some variables can be designated thread local,
such as 'errno'. In Felix, all globals may be
microthread local, since they're collected into
a single struct which is passed explicitly
to all functions or stored in a C static,
depending on a compilation time switch.
I guess in Haskell with monads, global
has yet another meaning, as indeed it does
in with classes in OO languages, which provide explicit
object construction.
I would argue that data and code are categorical
duals concepts, and localistion is *the* principal
engineering issue of software design. Indeed,
it is central to lambda calculus where
lambda abstraction is the fundamental operation,
and is nothing more than a way of moving between
a local and global variable -- here the relativity
of the local/global distinction in manifest directly
as a fundamental principle.
Indeed one may say 'languages' lacking abstraction,
such as C, aren't even candidates for consideration
as 'programming' languages -- because it is impossible
to exercise the very design judgements a programmer
must make about locality.
Interestingly, I think Object Orientation -- which as
a complete paradigm I despise -- has made one of the
most important steps forward in language design.
This is because it provides a second construction
for expressing localisation which expands considerably
the programmers choices compared to the localisation
available merely from lambda abstraction (ie. function
closures/stack frames). This is because it allows
one to localise *code* with groups of data, whereas
closures allow one to localise data within a code
structure -- so given the duality of code and
data this capability seems somehow fundamental.
The fact that in Ocaml these two dual constructions
are not syntactically symmetric is an indication
of how poorly this duality is understood.
Compared to functions/lexical scoping classes
in Ocaml seem too 'heavy' -- I think I mean
that the simplicity of changing the the locality
of variables with functions is not present with
classes .. but I don't understand how locality
could be better represented: Ocaml inheritance
is somehow just tricky sugar instead of being
fundamental, as the duality principle says
it should be.
BTW: I think it is a fault to emphasise entirely the
typing theory, which somehow seems more advanced
than the theory of that which it is typing!
--
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850,
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net
next prev parent reply other threads:[~2004-12-10 2:30 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-12-09 2:07 HENRIKSON, JEFFREY
2004-12-09 4:47 ` [Caml-list] " Jacques Garrigue
2004-12-09 6:02 ` Michael Walter
2004-12-09 11:28 ` Jacques Garrigue
2004-12-09 20:02 ` pad
2004-12-09 23:11 ` Jacques Garrigue
2004-12-10 2:30 ` skaller [this message]
2004-12-09 9:09 ` Richard Jones
2004-12-09 13:12 ` [Caml-list] " Ville-Pertti Keinonen
2004-12-10 11:59 ` Richard Jones
2004-12-10 10:52 ` [Caml-list] " Andrej Bauer
2004-12-10 12:13 ` Richard Jones
2004-12-10 23:35 ` Jacques Garrigue
2004-12-11 2:30 ` skaller
2004-12-11 14:31 ` Andrej Bauer
2004-12-11 18:13 ` Markus Mottl
2004-12-11 23:56 ` skaller
2004-12-12 2:36 ` William Lovas
2004-12-12 5:33 ` skaller
2004-12-12 19:09 ` Michael Walter
2004-12-13 0:48 ` skaller
2004-12-13 2:03 ` Michael Walter
2004-12-13 2:05 ` Michael Walter
[not found] ` <877e9a170412121844b633bb8@mail.gmail.com>
2004-12-13 2:45 ` Michael Walter
2004-12-13 6:18 ` skaller
2004-12-13 7:08 ` skaller
2004-12-13 9:56 ` Michael Walter
2004-12-13 12:59 ` skaller
2004-12-13 8:56 ` Thomas Fischbacher
2004-12-13 9:21 ` Jacques Garrigue
2004-12-13 10:05 ` Michael Walter
2004-12-13 10:29 ` Thomas Fischbacher
2004-12-13 21:16 ` Michael Walter
2004-12-13 10:20 ` Thomas Fischbacher
2004-12-13 12:09 ` Jacques Garrigue
2004-12-13 12:48 ` Thomas Fischbacher
2004-12-13 14:09 ` skaller
2004-12-13 21:39 ` Michael Walter
2004-12-13 13:22 ` skaller
2004-12-13 16:54 ` Marcin 'Qrczak' Kowalczyk
2004-12-13 18:44 ` Thomas Fischbacher
2004-12-13 10:11 ` Michael Walter
2004-12-13 11:46 ` skaller
2004-12-13 5:41 ` skaller
2004-12-13 9:29 ` Michael Walter
2004-12-13 12:30 ` skaller
2004-12-13 13:49 ` Martin Berger
2004-12-12 23:03 ` Thomas Fischbacher
2004-12-13 1:26 ` skaller
2004-12-13 8:37 ` Thomas Fischbacher
2004-12-13 10:53 ` skaller
2004-12-13 11:38 ` Martin Berger
2004-12-13 13:33 ` skaller
2004-12-13 12:01 ` Thomas Fischbacher
2004-12-13 13:41 ` skaller
2004-12-11 23:29 ` skaller
2004-12-12 0:21 ` Jacques Carette
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1102645847.2611.417.camel@pelican.wigram \
--to=skaller@users.sourceforge.net \
--cc=caml-list@inria.fr \
--cc=garrigue@math.nagoya-u.ac.jp \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox