Browse thread
ANN: pattern guards
-
Jeremy Yallop
-
skaller
-
Jeremy Yallop
- Brian Hurt
-
skaller
-
Arnaud Spiwack
- Jeremy Yallop
-
Arnaud Spiwack
-
Jeremy Yallop
-
skaller
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Jeremy Yallop <jeremy.yallop@e...> |
| Subject: | Re: [Caml-list] ANN: pattern guards |
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.