Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Range checking in Haskell's case?

Tags:

case

haskell

Is there a valid way to do the following in Haskell:

case n of
    0     -> doThis
    1     -> doThat
    2     -> doAnother
    3..99 -> doDefault

other than to have 97 lines of "doDefault" ?

like image 277
me2 Avatar asked Mar 11 '10 08:03

me2


1 Answers

case n of
    0     -> doThis
    1     -> doThat
    2     -> doAnother
    _     -> doDefault

If you really need a range,

case n of
    0     -> doThis
    1     -> doThat
    2     -> doAnother
    x | 3 <= x && x < 100 -> doDefault
    _     -> reallyDoDefault
like image 129
kennytm Avatar answered Sep 22 '22 02:09

kennytm