[Haskell-cafe] Non-Overlapping Patterns

Jules Bean jules at jellybean.co.uk
Tue May 6 02:02:20 EDT 2008

PR Stanley wrote:
> Hi
> isZero :: Int -> Bool
> isZero 0 = True
> isZero n | n /= 0 = False
> The order in which the above equations appear makes no difference to the 
> application of isZero. Does the Haskell interpreter rewrite patterns 
> into one single definition using some sort of switch or if construct?

Something a bit like that.

> Why does an equation without a guard have to be placed after the more 
> specific cases?

It doesn't. You could write the above the other way around if you wished.

 > To put it another way, why doesn't the interpreter
> identify the more specific cases and put them before the general ones.

Because it general it's convenient to have overlapping cases, where the 
order matters, and be able to choose the order.


More information about the Haskell-Cafe mailing list