id,summary,reporter,owner,description,type,status,priority,milestone,component,version,resolution,keywords,cc,os,architecture,failure,difficulty,testcase,blockedby,blocking,related
5813,Offer a compiler warning for failable pattern matches,snoyberg,,"This started off with a mailing list discussion: [http://www.mail-archive.com/haskell-cafe@haskell.org/msg96517.html]. The problem is that the following code produces no compile-time warning and results in a runtime error:


{{{
data MyType = Foo | Bar
    deriving Show

test :: Monad m => m MyType -> m ()
test myType = do
    Foo <- myType
    return ()

main :: IO ()
main = test $ return Bar
}}}

This is in contrast to the rest of pattern matching, which would warn about unmatched patterns, e.g.:

{{{
data MyType = Foo | Bar
    deriving Show

test :: Monad m => m MyType -> m ()
test myType = do
    x <- myType
    case x of
        Foo -> return ()

main :: IO ()
main = test $ return Bar
}}}

I understand that this style of code may be very useful in some circumstances when paired with a Monad providing a sensible fail implementation, and is especially used in list comprehensions. However, this is allowing an easily catchable static error to slip through our fingers.

I recommend we add a new compiler warning to catch incomplete patterns in do-notation binding. I believe this warning should not apply to list comprehensions. Ideally, this warning would be turned on by -Wall.",feature request,new,normal,7.6.2,Compiler,7.2.2,,,Christian.Maeder@…,Unknown/Multiple,Unknown/Multiple,None/Unknown,Unknown,,,,
