Thank you, Yawar. I’m familiar with using semicolon for sequencing, but it hadn’t occurred to me that it might be interpreted that way here, and that explains the failure perfectly.

Tim

On Feb 13, 2018, at 11:12 PM, Yawar Amin <yawar.amin@gmail.com> wrote:

Hi,

On Tue, Feb 13, 2018 at 10:31 PM, Tim Leonard <Tim@timleonard.us> wrote:
[...]
type my_record = { field1 : bool; field2 : int };;

let f x = { field1 =   match x with _ -> true  ; field2 = 2 };; (* this fails *)

This fails because OCaml overloads ';' in a few different ways, significantly: (1) as a field separator in a record, and (2) as a sequencing operator between two expressions. In case of ambiguity OCaml parses as the latter, but you really meant the former.

(2) 'sequencing operator' means that something like:

let x = print_endline "Hi!"; 1

... will evaluate whatever is on the left of the ';', throw away its value (in this case 'unit'), then evaluate whatever is on the right of the ';' and return its value as the final value of the compound expression.

Regards,

Yawar