What about
case a of _ | a == 3 || a == 4 || a == 5 -> print "hello" 6 -> print "hello something else"
It will be less tiring to write
case a of _ | a `elem` [3, 4, 5] -> print "hello" 6 -> print "hello something else"
or
case a of _ | 3 <= a && a <= 5 -> print "hello" 6 -> print "hello something else"
or even if your real program had many possible values ββfor you, for example:
import qualified Data.Set as S valuesToMatchAgainst :: S.Set Int valuesToMatchAgainst = S.fromList [3, 4, 5] -- ... case a of _ | a `S.elem` valuesToMatchAgainst -> print "hello" 6 -> print "hello something else"
(I assume you already realized that _ is a wildcard that matches any value, and that | introduces protection .)
source share