
Hi there, Let's say I have something like this (it is an artificial example just for illustration): case x of 1 -> doThis 5 -> doThis 76 -> doThis 112 -> doThat 21 -> doThat _ -> doOtherwise I would like to have something like this (which is illegal) case x of 1 | 5 | 76 -> doThis 112 | 21 -> doThat _ -> doOtherwise Is something like this possible to do? The only idea I got is: processX x | x `elem` [ 1, 5, 76 ] = doThis | x `elem` [ 112, 21 ] = doThat | otherwise = doOtherwise -- Manfred

On Thu, Jun 23, 2011 at 11:02, Manfred Lotz
The only idea I got is:
processX x | x `elem` [ 1, 5, 76 ] = doThis | x `elem` [ 112, 21 ] = doThat | otherwise = doOtherwise
That's the correct way to do it. The trick is to remember that the above is really a "case of":
case x of _ | x `elem` [1, 5, 76] -> doThis | x `elem
-- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms

On Thu, Jun 23, 2011 at 11:29, Brandon Allbery
On Thu, Jun 23, 2011 at 11:02, Manfred Lotz
wrote: The only idea I got is:
processX x | x `elem` [ 1, 5, 76 ] = doThis | x `elem` [ 112, 21 ] = doThat | otherwise = doOtherwise
That's the correct way to do it. The trick is to remember that the above is really a "case of":
(with the cat off my arm so I'm not whacking the wrong keys...)
case x of _ | x `elem` [1, 5, 76] -> doThis | x `elem` [112, 21] -> doThat | otherwise -> doSomethingElse
-- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms

On Thu, 23 Jun 2011 11:32:50 -0400
Brandon Allbery
On Thu, Jun 23, 2011 at 11:29, Brandon Allbery
wrote: On Thu, Jun 23, 2011 at 11:02, Manfred Lotz
wrote: The only idea I got is:
processX x | x `elem` [ 1, 5, 76 ] = doThis | x `elem` [ 112, 21 ] = doThat | otherwise = doOtherwise
That's the correct way to do it. The trick is to remember that the above is really a "case of":
(with the cat off my arm so I'm not whacking the wrong keys...)
:-)
case x of _ | x `elem` [1, 5, 76] -> doThis | x `elem` [112, 21] -> doThat | otherwise -> doSomethingElse
Thanks. That is interesting. -- Manfred
participants (2)
-
Brandon Allbery
-
Manfred Lotz