According to the OCaml manual
let pattern_1 = expr_1 and … and pattern_n = expr_n in expr
.... evaluatesexpr_1 … expr_n
in some unspecified order ....`
Does any compiler or rutnime for OCaml take advantage of the order being unspecified?For example, ocamlopt
and ocamlc
+ocamlrun
in practice use a distinct evaluation order for function arguments and I was wondering if something similar arises for let ... and
.
I wasn't able to find any case where the evaluation order isn't left-to-right, here's some code that prints 123
whether I use ocaml
or ocamlopt
:
let p = Printf.printf "%d%!"let rec spin = function | 0 -> () | n -> spin (n - 1)let () = let x0 = spin 99999999; and x1 = p 2 and x2 = p 3 in let _ = x0, x1, x2 in ()