On Fri, Aug 19, 2011 at 1:32 AM, rossberg@mpi-sws.org wrote:
Is the following code supposed to print 1 followed by 2 or 2 followed by 1?
val _ = (fn () => (print "1\n"; fn x => x)) () (print "2\n"; ())
In SML/NJ, MLton and PolyML it does the former, while in Moscow ML it does the latter. Is this specified somewhere in the standard? I noticed equivalent code in OCaml behaves the way Moscow ML does which is not very surprising seeing how Moscow ML was based on Caml Light. Could this be a bug in Moscow ML?
It is specified, and the deviation a (known) bug/limitation of Moscow ML. It's due to its implementation being based on the Caml VM, which chose this semantics in order to be able to implement curried functions more efficiently.
Interesting and very useful to know.
(Note that in OCaml, evaluation order actually depends on whether you are using byte code or native code compilation.)
That sounds bad.