So, let's go to the point:
f :: Eq a => a -> [(a,[a])] -> [(a,[a])]
f x list = [(a,[m]) | (a,[m]) <- list, x == a]
so:
f 1 [(1,[1])] = [(1,[1])]
but
f 1 [(1,[1,1])] = []
Why is that?? Thank you!
(I'm a newbie, so I apologize if it's a too dumb question, but I really can't find an explanation)
That's because [1,1]
does not match the pattern [m]
. The latter means a list of one item (unless used where a type name should be). Haskell already knows that second element of the pair is a list, (by looking at the type of list
parameter) and does not need to be told that explicitly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With