[comp.lang.functional] ML's wierdness in interactive script.

shail@miura.lcs.mit.edu (Shail Aditya Gupta) (05/04/91)

Okay, here is my $0.02 worth. The program in question is:

> val a = 1;
> a ;
| 1 : int ;
> fun b c = c * a ;
> b 2 ;
| 2 : int ;
> val a = 3;
> b 2 ;
| 2 : int ;
^^^^^^^^^^ Why does it do it like this.. 

ML's interactive script can be viewed like a giant, never ending ML
program, with each statement being defined in the lexical scope of all
the previous ones. If you view it this way, as it was pointed out by
others, it is logical and reasonable that the second definition of "a"
shadows the first, but the first had been "closed over" in the lexical
closure environment of the function "b", which can never be destroyed,
only further shadowed, (unless "a" happened to be a "ref" variable and
you side-effected it).

In this sense, I view ML's interactive script as non-incremental, by
which I mean no forward references are allowed, explicit grouping of
mutually recursive definitions is required via "let rec" declarations
(as against simple "let" bound polymorphic definitions), and it is not
possible to edit existing definitions (only shadow them with new
ones).

One way to look at this is that ML does not support "dynamic linking"
at the toplevel script. Note this is not the same as "dynamic scoping"
which can also do this job but does more. There are other languages in
the same class as ML, notably Miranda and Id, that do support forward
references in their scripts etc. Still, Miranda does not measure up to
my concept of incremental program development, since it supports only
environmentally "closed" files to be compiled as a unit (correct me if
I am wrong). 

Id, on the other hand, is no less flexible and incremental than Lisp
or Scheme even though it does fully static ML-style, and SOUND type
inferencing. (I should know, this was my MS thesis). For those who do
not know, "Id" was developed at MIT, and it is an incrementally
compiled, non-strict, parallel programming language with ML-style type
inference system, NICE syntax, pattern matching, and what have you.

It is unclear to me why ML's top-level script was chosen not to
incorporate dynamic linking. The only reason I can think of is really
historical, that it started as a Meta-language for LCF, and its
designers never though it would be used in interactive sessions as a
real programming language which it has now grown up to be. I believe
they thought all that would be required of this language was to
construct program like proofs. There, it was obvious to keep things
clean and simple by disallowing any incrementality and progamming
language issues such as dynamic linking and editor flexibility. 

Cheers,
			Shail Aditya.
			shail@abp.lcs.mit.edu.