[Haskell-cafe] Is there a null statement that does nothing?

Henning Thielemann lemming at henning-thielemann.de
Sat Oct 24 17:30:55 EDT 2009


Dan Weston schrieb:
> If you have a long if/else if/else chain, you might consider a trivial
> case statement with guards. Whether you think this is attractive is a
> matter of taste, but it has the fall-through semantics you want and ghc
> optimizes the _ pattern matching away:
> 
> f x = case () of
>   _| x == 2    -> 22
>   _| x == 4    -> 44
>   _| x == 7    -> 77
>   _| otherwise -> 55
> 
>> f 4
> 44
>> f 9
> 55

http://www.haskell.org/haskellwiki/Case



More information about the Haskell-Cafe mailing list