[Haskell-cafe] Ensuring all values of an ADT are explicitly handled OR finding all occurrences of type X in my app

Li-yao Xia li-yao.xia at ens.fr
Tue Jan 31 18:56:04 UTC 2017

>> You'd instead want to warn about "default branch", e.g.
>>   case <foo>
>>   | [] -> ...
>>   | (1 : xs) -> ...
>>   | (_ : xs) -> ...
>> here the wildcard pattern does correspond to a "default branch" and
>> might hence deserve a warning.
> This sounds promising, but how would you define “default branch”? Seems like it could be an involved definition, which could make the warning unpredictable for users.

A "default branch" seems to correspond to a wildcard overlapping a 
previous pattern. This would be a warning symmetrical to 

- A wildcard which overlaps with a pattern below it makes the latter 
unreachable, which is certainly not intentional. This is caught by 

   case x of
     _ -> y
     C -> z

- A wildcard which overlaps with a pattern above it has the risk 
mentionned in this thread, that it will catch any new constructor added 
to the corresponding ADT, and thus the programmer may forget to update 
some case expressions when the new constructor is to be handled differently.

   case x of
     C -> y
     _ -> z


More information about the Haskell-Cafe mailing list