caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Chet Murthy <murthy.chet@gmail.com>
To: Oliver Bandel <oliver@first.in-berlin.de>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] a question about syntax
Date: Wed, 14 Feb 2018 15:02:59 -0800	[thread overview]
Message-ID: <CA++P_gekkG3hdKFA=L6qyS+LQVR0vpM3+GMfxn_Q6xezWj6mdw@mail.gmail.com> (raw)
In-Reply-To: <20180214195046.Horde.mSIwdxq5Yo9xUKgfzIss4Ey@webmail.in-berlin.de>

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

I remember back in the day Pierre Weis explaining to me that this syntactic
trade-off was made in order to allow that
"let" and "match" didn't have ending key-words (e.g. "end").  Unlike in
SML/NJ.

--chet--


On Wed, Feb 14, 2018 at 10:50 AM, Oliver Bandel <oliver@first.in-berlin.de>
wrote:

>
> Zitat von Tim Leonard <Tim@timleonard.us> (Tue, 13 Feb 2018 22:31:14
> -0500)
>
> 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?
>>
>
> No.
> You can use semicolon to put more then one expression together.
> So the "field2 = 2" is seen as part of the match.
>
> If you have a pattern matching, this way you can put multiple
> commands/expressions in a row,
> without the need to use begin/end or ( ) in any match-case.
> It's the other way around: you need to put begin/end or ( ) around a
> match-statement.
>
> This way you have to add one such enclosing around a match-statement,
> instead of one such enclosing in any match-case of such a statement.
>
>
>
>> type my_record = { field1 : bool; field2 : int };;
>>
>> let f x = { field1 =   match x with _ -> true  ; field2 = 2 };; (* this
>> fails *)
>>
>
> Here I get "Error: Unbound value field2",
> which is, because the match-case reaches until the }.
>
>
>
>
>> let f x = { field1 = ( match x with _ -> true ); field2 = 2 };; (* this
>> is ok *)
>>
>
> Here it works, because the match-statement is sorrounded / enclosed by (
> and ).
>
> Ciao,
>   Oliver
>
>
>
> --
> 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: 3120 bytes --]

  reply	other threads:[~2018-02-14 23:03 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
2018-02-14 18:50 ` Oliver Bandel
2018-02-14 23:02   ` Chet Murthy [this message]
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='CA++P_gekkG3hdKFA=L6qyS+LQVR0vpM3+GMfxn_Q6xezWj6mdw@mail.gmail.com' \
    --to=murthy.chet@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=oliver@first.in-berlin.de \
    /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).