[Haskell-cafe] Guards (Was: Some random newbie questions)

Christian Maeder maeder at tzi.de
Fri Jan 7 10:35:19 EST 2005

Henning Thielemann wrote:
> What about dropping Guards? :-) Are they necessary? Do they lead to more
> readable source code? Do they lead to more efficient code? I could
> perfectly live without them up to now.

I hardly need guards too, but their advantage is that they let pattern 
matching fail, resulting in trying out following patterns.

case l of
   [i] | i /= 0 -> (/i)
   _ -> error "a single message here for all other cases"

Cheers Christian

More information about the Haskell-Cafe mailing list