cs3110 / textbook

The CS 3110 Textbook, "OCaml Programming: Correct + Efficient + Beautiful"
Other
720 stars 132 forks source link

Correct function application order #118

Closed favonia closed 1 year ago

favonia commented 1 year ago

OCaml intentionally does not specify the evaluation order of functions and their arguments. The current implementation uses the anti-texual order (at least in most cases). It is technically possible that it will one day adopt the textual order used by Standard ML. Relevant text in the manual: https://v2.ocaml.org/manual/expr.html#sss:expr-functions-application

The same code will raise the other exception in any languages using the textual order. For example, the following code will raise B in Standard ML:

exception A
exception B
val _ : int = (raise B) (raise A)

This PR attempts to restore correctness with minimum changes. Again, thanks for the textbook.

clarksmr commented 1 year ago

Good catch, thanks!