From: ls-ocaml-developer-2006@m-e-leypold.de
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] How must we teach lexical scope?
Date: Thu, 29 Mar 2007 12:59:30 +0200 [thread overview]
Message-ID: <t4odmciact.fsf@hod.lan.m-e-leypold.de> (raw)
In-Reply-To: <6f9f8f4a0703290117qf0fa062n6430a168e7acf5b7@mail.gmail.com> (Loup Vaillant's message of "Thu, 29 Mar 2007 10:17:28 +0200")
"Loup Vaillant" <loup.vaillant@gmail.com> writes:
> 2007/3/28, ls-ocaml-developer-2006@m-e-leypold.de
> <ls-ocaml-developer-2006@m-e-leypold.de>:
>> But perhaps I understand your problem better now: The difference
>> you're wanting to make is the substitution of symbols by values at
>> definition time vs. at evaluation time (I hope it is clear what I want
>> to say).
>
> Exactly.
>
>> But you'll have to explain substitution at evaluation time
>> anyway (when a function is called and the formal parameters are
>> bound). I don't understand what your attempt to avoid to talk about an
>> environment (from which a comes in the example above) will buy you.
>
> Substitution at definition time is how I naturally thought of it. That
> is, the definition:
> # f x = a + x;;
> was automatically replaced by:
> # f x = 3 + x;;
> in my head, so there were no more need for any environment.
>
> However, I must admit such a way of thinking has its limits:
Yes. One of the limits is that with way of thinking you cannot explain
invocation of functions. Furthermore you cannot explain:
let make_adder a =
fun x -> x + a
;;
which exemplifies the very essence of "functional programming".
> as long as the substitution is simple, that is easy. When a free
> variable is some complicated piece of data (or even code), one (I)
> must switch to an environment representation.
No, it doesn't depend on the complexity. It just depends on wether
variables / identifiers are bound during the specific evaluation
you're looking at. As soon as you use functions in functions it
becomes really difficult -- if you start to return closure, it is
impossible to explain what happens without talking about environments.
> In that case, the
> environment I think about is only the set of free variables actually
> used by the function. The environments our professors talked about
> included all values, including the useless ones.
Well, of course, after you have enclosed a environment in a closure
you can -- technically -- leave out all "unnecessary" variables. But
the point is, that all the unnecesarry variables just define which
variables are "valid" ro be used in a give context. Consider:
...[1]
let f x y =
...[2]
...
Which identifiers can be used in [2]? x and y certainly -- but what
about k, t and foo? That of course depends on the context inherited
from [1] -- and the best expression of the context is the environment
which contains all bindings that have been made in [1]
> I thought it was unnecessary, but I see the trade-of, now: their
> process is quite long (not to mention the syntactic burden of
> describing each environment) but it is systematic, and simple.
As I said: I wouldn't consider more than (at most) a week to be
necessary for the whole shebang, so I'm ready to concede they are
perhaps overdoing it (on the other side it's their course and it's not
my position to judge them). Perhaps they also miss giving the big
picture (how evaluation, free variables, definition and environments
mesh together). I wouldn't know. On the other side my experience with
beginners is, that they are often, unfortunately, missing the niceties
and the big picture even when they are told about them. So the whole
thing is perhaps more one of the usual didactic misunderstandings
rather the a bad course.
> Because it is, it looks silly. I don't like environments, but you
> convinced me I haven't came up with a better solution.
:-) Good to hear. Now let me buy some stock of Toulouse 3, so ... damn
-- they haven't gone public yet? What a waste ...
Regards -- Markus
next prev parent reply other threads:[~2007-03-29 10:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-28 7:59 Loup Vaillant
2007-03-28 8:49 ` [Caml-list] " Luc Maranget
2007-03-28 14:34 ` Loup Vaillant
2007-03-28 15:43 ` ls-ocaml-developer-2006
2007-03-28 17:09 ` Loup Vaillant
2007-03-28 19:24 ` ls-ocaml-developer-2006
2007-03-29 8:17 ` Loup Vaillant
2007-03-29 10:59 ` ls-ocaml-developer-2006 [this message]
2007-03-28 9:49 ` Pierre-Evariste Dagand
2007-03-28 17:41 ` Pal-Kristian Engstad
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=t4odmciact.fsf@hod.lan.m-e-leypold.de \
--to=ls-ocaml-developer-2006@m-e-leypold.de \
--cc=caml-list@yquem.inria.fr \
/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