My old notes on ML say that
let (₁, … , ₙ) = (₁, … , ₙ) in ′
is a syntactic sugar for
(λ ₙ. … (λ ₁. ′)₁ … )ₙ
and that
let (₁, ₂) = ′ in ″
is equivalent to
let = ′ in
let ₂ = snd in
let ₁ = fst in
″
where
- each
(with or without a subscript) stands for a variable,
- each
(with or without a sub- or a superscript) stands for a term, and
fst
andsnd
deliver the first and second component of a pair, respectively.
I'm wondering whether I got the evaluation order right because I didn't note the original reference. Could anyone ((confirm or reject) and (supply a reference))?
It shouldn't matter whether it's:
Or:
Since neither
fst
norsnd
have any side-effects. Side-effects may exist in the evaluation of′
but that's done before the let binding takes place.Additionally, as in:
Neither
₁
nor₂
is reliant on the value bound to the other to determine its value, so the order in which they're bound is again seemingly irrelevant.All of that said, there may be an authoritative answer from those with deeper knowledge of the SML standard or the inner workings of OCaml's implementation. I simply am uncertain of how knowing it will provide any practical benefit.
Practical test
As a practical test, running some code where we bind a tuple of multiple expressions with side-effects to observe order of evaluation. In OCaml (5.0.0) the order of evaluation is observed to be right-to-left. We observe tthe same when it comes to evaluating the contents of a list where those expressions have side-effects as well.
In SML (SML/NJ v110.99.3) we observe the opposite: left-to-right evaluation of expressions.