No, it's keywords "in" that assigns the terminus to the current phrase so to speak.

The first would look like this, if I understand you correctly:

let f x = { field1 = match x with _ -> true | field2 = 2} in

But there are several problems with the above statement. First, you used a semicolon in place of a |, and a | expresses to the match statement what the various cases are. As in,

match x with | case1 ... | case 2 | ... 

Second, alternatively to that interpretation, you might want it to be that you match within the assignment like this:

let f x = { field1 = (match x with ... ); field2 = ... } in

A problem is that you used match x with _ -> true | field2, but the _ is the catchall keyword, so field2 is never going to get hit. What you've expressed in the second let statement is equivalent to this:

let f1 = match x with _ -> true in
let f x = { field1 = f1; field2.... }

On Tue, Feb 13, 2018 at 10:31 PM, Tim Leonard <Tim@timleonard.us> wrote:
A simple question of syntax: why does the first definition of function f cause a syntax error?
Shouldn’t the semicolon syntactically terminate the match expression?

type my_record = { field1 : bool; field2 : int };;

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

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


--
Caml-list mailing list.  Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs