Possible duplicate:
Why can’t the Haskell list be recognized when a pattern matching error occurs?
Today I saw the following code:
Prelude> [a | Just a <- [Just 10, Nothing, Just 20]]
[10, 20]
It works. But I thought the above list comprehension is just syntactic sugar for ...
[Just 10, Nothing, Just 20] >>= (\(Just x) -> return x)
... for which Haskell encounters an Nothingerror *** Exception: Non-exhaustive patterns in lambda.
So my question is: what does it mean [a | Just a <- [Just 10, Nothing, Just 20]](in terms of monadic code), what makes it ignore Nothing?
source
share