Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is function application evaluation order deterministic in SML?

Tags:

sml

ml

In OCaml, evaluation order of function application is unspecified (aka non-deterministic).

In Standard ML, is it also non-deterministic or deterministic? Can you provide a reference to the spec section that clarifies?


Edit: for those of you coming later, I also learned that like SML, in F# the order is specified and deterministic--unlike OCaml, which is even more crazy considering how close the two are in syntax. Easy to forget if you switch between them a lot.

like image 515
jayphelps Avatar asked May 10 '17 03:05

jayphelps


Video Answer


1 Answers

Yes, the evaluation rules (Section 6.7 of the Definition) fully specify evaluation order for all constructs of SML, and it always is in textual order. For application, first the function expression is evaluated and then the argument (e.g. rule 102). Similarly, records (and thus tuples) are evaluated left-to-right (rules 92/95).

Together, that implies that e.g. f(a,b)(c,d) is evaluated in the order f, a, b, f(...), c, d, g(...), where g is the result of f(...).

like image 99
Andreas Rossberg Avatar answered Sep 26 '22 16:09

Andreas Rossberg