From: Jeremy Yallop <jeremy.yallop@ed.ac.uk>
To: Arnaud Spiwack <aspiwack@lix.polytechnique.fr>
Cc: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] ANN: pattern guards
Date: Tue, 03 Jul 2007 10:29:03 +0100 [thread overview]
Message-ID: <468A16DF.5070506@ed.ac.uk> (raw)
In-Reply-To: <4685DFA0.7000306@lix.polytechnique.fr>
Arnaud Spiwack wrote:
> A (too) quick answer could of course be: "in the absence of a 'with
> clause', it is considered the identity 'with clause'". But I'm not sure
> it's that satisfying in practice. (it precisely and accurately adresses
> this very case John Skaller is raising, but not the same example with an
> additional variable in each constructor...).
>
> A suitable solution for nested guarded patterns could be, instead of
> saying "all the branches of the or-pattern must agree on the variable",
> to use a less coercive, but more compromising law : "only the variable
> common in all the branches of the or-pattern are bound in the match
> branch".
This seems like a good rule. I think it should be refined a little,
though. The refinement is: "any variables which occur free in the
expression must be bound in either all or no branches of the pattern".
For example, this should be an error:
let z = 3
let f = function
| A x with z = 10
| B x -> x + z
Without the refinement `f (A 5)' evaluates to 8, which is pretty
confusing (even with an unused variable warning).
Jeremy.
prev parent reply other threads:[~2007-07-03 9:25 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
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 [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=468A16DF.5070506@ed.ac.uk \
--to=jeremy.yallop@ed.ac.uk \
--cc=aspiwack@lix.polytechnique.fr \
--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