let p = let x = 1 in x + 1, let y = 2 in y + 1, 4
Since comma , have the lowest precedence, I would image p has 3 elements: (2, 3, 4).
But in fact, p has only 2 elements: (2, (3, 4))
Why?
Why the last , belongs to let y expression, but not outside of it?
I would expect
let...in...to have the following syntaxand the block goes as far to the right as possible.
In your example, the OCaml parser expects
to be an expression and parses it as
(3, 4)successfully.An equivalent of your example with explicit brackets is
If you would like to return final result
(2, 3, 4), you should put a bracket to stoplet...in...block in the appropriate place: