A friend and I recently discussed why patterns in Haskell are
restricted to be linear. He found it unintuitive due to his background 
in term rewriting and logic. And he noted that it is easy to compile
away as in: 

f (x, x) = e
==>> 
f (x, x') | x == x' = e

It is also easy to transform away in list comprehensions:

(x, x) <- e
==>>
(x, x') <- e, x == x'

My main argument against it was a language design issue, namely that
suddenly x is required to have an Eq type which cannot be explained by 
looking at its uses in e.

Another problem is that comparing x with x' makes this kind of pattern 
matching super-strict (since x may be reduced to normal form).

Can someone enlighten me on other arguments for or against non-linear
patterns? 

NB:
If I remember the Haskell98 discussion correctly, there was a
discussion on Monad and (the now dead) MonadZero, where the MonadZero
appeared "magically" in the context, whenever someone used (refutable) 
patterns in the do-notation. This discussion (which was resolved by
hacking class Monad and dropping class MonadZero) is imho related to
the question raised above; in both cases, the use of some language
feature changes/restricts the type.

-Peter


Reply via email to