Actually, yes, they give rise to various errors. The lack of conformity to the pattern in the let binding causes a match to the error pattern whenever this match is evaluated if there is no match to the pattern from (<-) , just calls the Monad instance fail function
As a simple example, consider the Maybe monad where
instance Monad Maybe where ... fail _ = Nothing test1 :: Maybe (Maybe ()) test1 = do Just a <- return Nothing return a test2 :: Maybe (Maybe ()) test2 = do ma <- return Nothing let Just a = ma return a
If we call them both, we get completely different behavior
> test1 Nothing > test2 Just *** Exception: PM.hs:23:7-17: Irrefutable pattern failed for pattern Data.Maybe.Just a
In the general case, an irrefutable match is a bad idea if you are really not sure about the impossibility of getting the missing templates, but if you have to do it in Monad , then sometimes an irrefutable match on a binding is better than let .
source share