[Haskell-cafe] conflicting variable definitions in pattern
ganesh.sittampalam at credit-suisse.com
Fri May 15 04:11:18 EDT 2009
Martin Hofmann wrote:
> It is pretty clear, that the following is not a valid Haskell pattern:
> foo (x:x:xs) = x:xs
> My questions is _why_ this is not allowed. IMHO, the semantics should
> clear: The pattern is expected to succeed, iff 'x' is each time bound
> to the same term.
How do you define the "same term"?
One natural way of compiling it would be to
foo (x:y:xs) | x == y = x:xs
but then pattern matching can introduce Eq constraints which some might
see as a bit odd.
> Isn't this allowed, because this would require a strict evaluation of
> the 'x' variables?
The translation into == would probably introduce some strictness, for
most implementations of Eq. I don't think this is a huge problem in
Please access the attached hyperlink for an important electronic communications disclaimer:
More information about the Haskell-Cafe