[MLton-user] Order of evaluation of arguments to a function
ivan.tomac at gmail.com
Thu Aug 18 07:06:04 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?
The following code works the same in all 4 SML compilers (but
different in OCaml):
val _ = (print "1\n"; 1) + (print "2\n"; 2)
It seems to me like SML/NJ, MLton and PolyML evaluate all function
arguments left to right, OCaml evaluates them right to left, and
Moscow ML seems inconsistent.
More information about the MLton-user