Completeness of pattern matching
Fri, 6 Dec 2002 13:26:02 +0100
I wonder if the compiler could check, if all possible combinations have been
checked in a pattern match.
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