There are two issues going on here.
1. Should pattern variables be permitted in the guard?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Haskell's reply: yes, but the result is always bottom.
After all,
- you need to evaluate the guard to discover which
RHS to bind the pattern to
- but you need to choose a particular RHS in order to evaluate
the guard
Consider:
(x,y) | x>1 = (2,3)
| otherwise = (0,4)
(this example is mildly amusing, because it has two incomparable fixpoints
other than x=y=bot)
2. If the RHS chosen by the first guard to return True does not match
the pattern, should the next RHS with a valid guard by tried.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
We didn't consider this during the design process. Since the
guards can be simply True, one could write rather odd programs like:
[x,y] | True = e1
| True = e2
| True = e3
which would pick the first of e1,e2,e3 to evaluate to a list of two elements.
I'm far from convinced that this is a feature though.
Simon