[Haskell-beginners] using the joker "_" on a constructor
TP
paratribulations at free.fr
Wed Sep 18 16:08:24 CEST 2013
Hi,
I have a question about pattern matching.
Consider the following code:
------------------
data Foo = Bar Int
| Foo Int
f :: Foo -> Bool
f (Foo n)
| even n = True
| odd n = False
f (Bar n)
| even n = True
| odd n = False
main = do
print $ f $ Bar 1
print $ f $ Bar 2
print $ f $ Foo 1
print $ f $ Foo 2
------------------
Why is it not possible to simply write for f:
f v = case v of
_ n | even n -> True
_ n | odd n -> False
or
f (_ n)
| even n = True
| odd n = False
(in both cases we get a parse error)?
Thanks,
TP
More information about the Beginners
mailing list