New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
multiple match + guards #2856
Comments
Comment author: administrator
Basically, the guard is not a part of the pattern, but a part of the matching Hence, the error is correct (!), since x is not a variable bound
But, anyway, in your exemple, variable ``x'' is used (in the guard).
The general solution (consider guards as patterns up to the point of Note that this issue was not relevant in the good old days when
Best regards, --Luc Maranget |
Comment author: administrator On Wed, 25 Jul 2001, Luc Maranget wrote:
Ok, I see, I thought that guards work on a per pattern basis, which may
That's not quite what I meant: I thought that the scope could be limited Unfortunately, the present rules require copying of right hand sides or
I have never needed this generality anyway. In fact, I'd even find such Thanks for the explanations! Best regards, -- |
Comment author: administrator User accepted our explanation of why things are the way they are :-) |
Original bug ID: 453
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)
Bug description
Hello,
the following is not accepted by the compiler though it makes perfect
sense:
let f p = function
| None | Some x when p x -> ()
| Some x -> ()
The compiler complains that:
File "bla.ml", line 2, characters 4-17:
Variable x must occur on both sides of this | pattern
It might be better to check whether variables contained in the patterns
are actually used on the right hand side of the match. Otherwise it is
impossible to use guards as presented above.
Best regards,
Markus Mottl
--
Markus Mottl markus@oefai.at
Austrian Research Institute
for Artificial Intelligence http://www.oefai.at/~markus
The text was updated successfully, but these errors were encountered: