[Prev][Next][Index][Thread]

Re: small Q




Thant Tessman <thant@acm.org> writes:
{stuff deleted}
> What seems to make this single value idea work (i.e. convenient) in SML
> is:
> 
> 	1) tuple is a full-fleged type
> 	2) pattern matching
> 	3) the syntax for a tuple just happens to match 
>            what people want to see when invoking a function
> 
Ahh you forgot 4

       4) Smart compiler that does does lots of local pattern matching 
          and plays other games to compile this efficiently.

I won't go into details, but it would make it easier to generate efficient
code if ML had functions with both multiple arguments and return values. In
fact the compiler for SML/NJ uses functions with multiple
arguments and return values in it's internal representation. 
An early phase just uses some heuristics to convert the nice single argument
single return ML code into an internal form with multiple arguments and
multiple return values. 

 I'm willing to expose some slight semantic complexity at the source level,
 if it lets me eliminate one more phase from the compiler. 

Also note...ML pop-quiz

 fun f(x,y) = (x + y,x - y)
 fun id(x) = x
 
 val (sum,diff) = id(f(10,20))

So how much memory does the ML program above allocate? 
There's no good answer as it depends on the compiler. This may or may not
bother you... 
  

Compiler issues aside... I do like the ML view of things when programming 



References: