From: Jeremy Yallop <jeremy.yallop@ed.ac.uk>
To: skaller <skaller@users.sourceforge.net>
Cc: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] ANN: pattern guards
Date: Fri, 29 Jun 2007 19:56:57 +0100 [thread overview]
Message-ID: <468555F9.7090005@ed.ac.uk> (raw)
In-Reply-To: <1183141562.5305.19.camel@rosella.wigram>
skaller wrote:
> On Fri, 2007-06-29 at 15:19 +0100, Jeremy Yallop wrote:
>> I'm pleased to announce the initial release of `patterns', an OCaml
>> extension providing general-purposes additions to pattern matching.
>
> I want to do this:
>
> match x with
> | Y x with a=x and b=x
> | X (y,z) with a=y and b=z
> -> f a b
Interesting. Do you want 'z' to be in scope in the guards ("a=y" etc.)
but not in the expression ("f a b")? Or do you just generally want to
allow or-patterns where the branches have different bindings as long as
the expression only uses variables that are bound in every branch?
> This won't work at the moment for two reasons:
>
> * I assume the precedence of 'with' is the same as 'when',
> which is not convenient
Right: "with" scopes over an entire match-case, which might include
or-patterns, just as with "when".
> * the variables in the basic patterns don't agree
>
> The whole point of the above is to switch all the branches
> to normalised variables. At the moment I have to write:
>
> match x with
> | Y x -> f x x
> | X (y,z) -> f y z
Unless I'm mistaken you can write this as
match x with
| Y (y as z)
| X (y,z) -> f y z
Is there some more general case for which this won't work out?
Jeremy.
next prev parent reply other threads:[~2007-06-29 18:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-29 14:19 Jeremy Yallop
2007-06-29 18:26 ` [Caml-list] " skaller
2007-06-29 18:56 ` Jeremy Yallop [this message]
2007-06-29 19:31 ` Brian Hurt
2007-06-30 4:09 ` skaller
2007-06-30 4:44 ` Arnaud Spiwack
2007-07-03 9:29 ` Jeremy Yallop
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=468555F9.7090005@ed.ac.uk \
--to=jeremy.yallop@ed.ac.uk \
--cc=caml-list@inria.fr \
--cc=skaller@users.sourceforge.net \
/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