With GHC, I can enable -Wincomplete-patterns to catch likely erroneous situations like these two.
problem1 :: Either Int String -> Int
problem1 (Left x) = x
problem2 :: Either Int String -> Int
problem2 x = case x of
Left x' -> x'
Clearly, I've forgotten to handle the Right case in both of these functions, and GHC will tell me that. However, the compiler seems to let me off without even a warning in these two cases.
problem3 :: Either Int String -> Int
problem3 x = let Left x' = x in x'
problem4 :: Either Int String -> Int
problem4 = \(Left x) -> x
I still forgot to handle a case, but GHC doesn't seem bothered. Is there a compiler flag I can set to catch situations like this where I use let or lambda pattern matching but didn't handle all of the cases? Ideally, I want to be warned if I do something like this so I can refactor it into a case statement or the like.
Of course, for the sake of completeness and posterity, answers relevant to other compilers are highly appreciated as well.