[MLton-user] Order of evaluation of arguments to a function

rossberg at mpi-sws.org rossberg at mpi-sws.org
Thu Aug 18 08:32:21 PDT 2011


> 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.

(Note that in OCaml, evaluation order actually depends on whether you are
using byte code or native code compilation.)

/Andreas




More information about the MLton-user mailing list