
24 Oct
2009
24 Oct
'09
5:30 p.m.
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