From: Tim Leonard <Tim@TimLeonard.us>
To: Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] a question about syntax
Date: Tue, 13 Feb 2018 23:32:43 -0500 [thread overview]
Message-ID: <541FB585-B037-4BDF-AC9F-30E47EA1D181@TimLeonard.us> (raw)
In-Reply-To: <CAJbYVJK3JdFEeq63s65viKes8c5PvLnjMpdWrD8eFXWAMyPq-g@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1155 bytes --]
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 <mailto: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
[-- Attachment #2: Type: text/html, Size: 2341 bytes --]
next prev parent reply other threads:[~2018-02-14 4:32 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
2018-02-14 4:12 ` Yawar Amin
2018-02-14 4:32 ` Tim Leonard [this message]
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=541FB585-B037-4BDF-AC9F-30E47EA1D181@TimLeonard.us \
--to=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).