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

Stefan Monnier monnier at iro.umontreal.ca
Tue Jan 31 17:11:50 UTC 2017


> I think the best solution here would be a new warning,
> say -fwarn-wildcard-patterns. This would be a simple syntactic check
> for a wildcard pattern anywhere in the module.

Note that

   case <foo>
   | [] -> ...
   | (_ : xs) -> ...

also contains a wildcard-pattern.  So emitting a warning for every use
of wildcard patterns would likely lead to a lot of pain.

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.


        Stefan



More information about the Haskell-Cafe mailing list