
29 Aug
2001
29 Aug
'01
12:16 p.m.
On 27 Aug 2001, Mike Gunter wrote: (snip)
Or, if you need several cases, you can use something like:
funcGuard n | n `elem` [2,5,9] = 5 | n `elem` [4,18] = 1 | otherwise = 7
or, if you want an expression:
caseGuard n = case undefined of _ | n `elem` [2,5,9] -> 5 | n `elem` [4,18] -> 1 | otherwise -> 7
Thanks - that's very helpful! (-: I hadn't thought of using 'elem'. Most of the cases are going to be ones like "if x = 5 or x = 7" instead of "if x = 6 or y = 'a'" so that should work well. -- Mark