These are called disjunctive patterns, and Haskell does not have them. (OCaml and F# do.) There are a few typical workarounds, however. If your type is an enumeration, you can use equality, with for example elem
:
case cond of
c
| c `elem` [C1, C2, C3] -> foo
| c `elem` [C10, C11, C12] -> bar
| otherwise -> baz
And of course, if foo
or bar
are long expressions, thanks to laziness you can simply factor them into local definitions, so you only have to repeat the name and any pattern variables you need as arguments:
case cond of
C1 x -> foo x
C2 y -> foo y
...
C10 -> bar
C11 -> bar
...
where
foo x = something long (involving x, presumably)
bar = if you please then something else quite long