Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Viewing all articles
Browse latest Browse all 518

Do any OCaml compilers take advantage of the unspecified order of evaluation of let ... and bindings?

$
0
0

According to the OCaml manual

let pattern_1 = expr_1 and … and pattern_n = expr_n in expr .... evaluates expr_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    ()

Viewing all articles
Browse latest Browse all 518

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>