Freom the documentation on OrPatterns:
[…] they may not bind any variables or constraints. This prohibits code like
value :: Either a a -> a value (Left x; Right x) = x -- binds a variable
I see that it would be problematic in a general case, e.g. the code is broken if I change Either a a to Either a b, and one would have to write a RHS that can deals with both a and b and returns one type.
But what about doing other useful stuff to limit the matching of the patters further, e.g. guards? Consider something like this:
value :: Either a b -> c
value (Left x | x < 0; Right y | foo y) = _ -- still binds variables
It obviously doesn’t parse because it suffers the same issue, i.e. the patterns are binding variables.
I wonder if a symbol other than | could be used to mean “don’t actually bind stuff”, then it could be desugared to the more cumbersome
value :: Either a b -> c
value (Left ((<0) -> True); Right (foo -> True)) = _ -- doesn't bind variables