From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: "Daniel Bünzli" <daniel.buenzli@erratique.ch>
Cc: OCaml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Suboptimal pattern matching specification
Date: Thu, 7 Apr 2016 12:36:09 -0400 [thread overview]
Message-ID: <CAPFanBF=AFMzHD5XaA=9C6nkR5HE1CwJhxfEpQGxBJkJpE9XPA@mail.gmail.com> (raw)
In-Reply-To: <91DFDE4DE82E4A8B983A7822E695BBA4@erratique.ch>
No, indeed you have to use a local definition to avoid code
duplication in this case.
My understanding of the design stance of pattern-matching in OCaml is
as follows: the syntax of patterns is bounded by what can be matched
efficiently. This explains why "when" has a second-class status
(first-class when cannot be matched efficiently); sometimes the user
has to pay for this rigidity. But, on the positive side, it is a
simple and clear stance, and it correlates with the availability of
good tooling, namely exhaustivity and useless-clause warnings.
On Thu, Apr 7, 2016 at 9:36 AM, Daniel Bünzli
<daniel.buenzli@erratique.ch> wrote:
> Hello,
>
> Something I run quite often is the following pattern matching
>
> match v with
> | None | Some c when sat c -> expr
> | Some …
>
> which doesn't compile and forces me to write
>
> match v with
> | None -> expr
> | Some c when sat c -> expr
> | Some …
>
> and leads to code duplication or the introduction of a definition to avoid it.
>
> Am I missing a syntax bit ?
>
> Best,
>
> Daniel
>
>
>
> --
> 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
prev parent reply other threads:[~2016-04-07 16:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-07 13:36 Daniel Bünzli
2016-04-07 16:36 ` Gabriel Scherer [this message]
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='CAPFanBF=AFMzHD5XaA=9C6nkR5HE1CwJhxfEpQGxBJkJpE9XPA@mail.gmail.com' \
--to=gabriel.scherer@gmail.com \
--cc=caml-list@inria.fr \
--cc=daniel.buenzli@erratique.ch \
/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