Exhaustive Pattern-Matching

Christian Maeder maeder@tzi.de
Fri, 29 Aug 2003 12:44:27 +0200


>>GHC tries to do so, but sometimes gets it wrong.  See the
>>-fwarn-incomplete-patterns flag.  We'd appreciate it if 
> 
> someone could
> 
>>overhaul this code - it's been on the wish list for a long time.

Indeed, I always try to avoid all warnings in my sources by using the 
flag "-Wall", because I consider this to be good programming style. (In 
particular warnings about unused and shadowed variables prevented a lot 
of errors.) However some warnings are difficult to avoid. So how 
difficult would it be to implement non-exhaustive pattern warnings for 
nested patterns?

data Color = Red | Green | Blue

f :: Color -> String
f x = case x of
       Red -> "r"
       _   -> " " ++ case x of
	            Green -> "g"
	            Blue  -> "b"

     Warning: Pattern match(es) are non-exhaustive
	     In a case alternative: Patterns not matched: Red


"Red" in the second case is unreachable (and this should also be worth a 
warning.)

Christian