caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Kenneth Adam Miller <kennethadammiller@gmail.com>
To: Tim Leonard <Tim@timleonard.us>
Cc: caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] a question about syntax
Date: Tue, 13 Feb 2018 22:41:00 -0500	[thread overview]
Message-ID: <CAK7rcp_gqpvdvgpbSpqBgC=XnPF3oWAMCQMxwaXJ4=ic2A0iMw@mail.gmail.com> (raw)
In-Reply-To: <21BC6EDE-DB27-460B-A4D5-BBD583C9E899@TimLeonard.us>

[-- Attachment #1: Type: text/plain, Size: 1646 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 2412 bytes --]

  reply	other threads:[~2018-02-14  3:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-14  3:31 Tim Leonard
2018-02-14  3:41 ` Kenneth Adam Miller [this message]
2018-02-14  4:12 ` Yawar Amin
2018-02-14  4:32   ` Tim Leonard
2018-02-14 18:50 ` Oliver Bandel
2018-02-14 23:02   ` Chet Murthy
2018-02-14 23:40     ` Ian Zimmerman
2018-02-15  0:17       ` Evgeny Roubinchtein
2018-02-15  1:17       ` Chet Murthy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAK7rcp_gqpvdvgpbSpqBgC=XnPF3oWAMCQMxwaXJ4=ic2A0iMw@mail.gmail.com' \
    --to=kennethadammiller@gmail.com \
    --cc=Tim@timleonard.us \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).