[Haskell-beginners] The case expression

Erik de Castro Lopo mle+cl at mega-nerd.com
Thu Jan 22 22:17:00 EST 2009


David Morse wrote:

> So you could really hammer it with blunt force:
> 
> case x of
>   0 -> "zero"
>   n | n `elem` [1,3,5,7] -> "odd"
>      | n `elem` [2, 4, 6, 8] -> "even"
>      | otherwise -> "bad number"

Ah, that's was what I was after. Thanks.

> By the way, zero is even. http://en.wikipedia.org/wiki/Zero_is_even

I did warn people this was a naive example. Did I really need to
make people aware this it was a *silly, completely contrived and
possibly incorrect* example ;-).

Cheers,
Erik
-- 
-----------------------------------------------------------------
Erik de Castro Lopo
-----------------------------------------------------------------
"Therapists typically base the nuttiness of a patient on the
strength of their convictions, on which basis this 43,000 word
opus alone stands as a kind of testament to Bill's (Gates)
madness." - The Register


More information about the Beginners mailing list