Completeness of pattern matching

Hi there, I wonder if the compiler could check, if all possible combinations have been checked in a pattern match. For example: data Colour = Red | Yellow | Green | Blue; trafficlight Red = True; trafficlight Yellow = True; trafficlight Green = True; trafficlight Blue = False; This is complete and okay. But, if somebody adds Magenta to Colour, then the function trafficlight becomes incomplete and the program might terminate at runtime whereas before it could not. (Of course, there could be dozens of more complicated case scattered over multiple files ...) If this could be checked, shouldn't it be an compile time error to have incomplete functions? Cheers, Ingo

Malcolm Wallace
Ingo Wechsung
writes: I wonder if the compiler could check, if all possible combinations have been checked in a pattern match.
In ghc, use the compile-time option -fwarn-incomplete-patterns
Is there a warning to warn if a block is delimited (or not) with a mix of tabs and spaces? Or somehow otherwise warn against dangerously looking layout? -kzm -- If I haven't seen further, it is by standing in the footprints of giants
participants (3)
-
Ingo Wechsung
-
ketil@ii.uib.no
-
Malcolm Wallace