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

William Yager will.yager at gmail.com
Wed Feb 1 00:05:35 UTC 2017


On Tue, Jan 31, 2017 at 12:56 PM, Li-yao Xia <li-yao.xia at ens.fr> wrote:
>
> A "default branch" seems to correspond to a wildcard overlapping a
> previous pattern. This would be a warning symmetrical to
> -Woverlapping-patterns.
>
> - A wildcard which overlaps with a pattern below it makes the latter
> unreachable, which is certainly not intentional. This is caught by
> -Woverlapping-patterns.
>
>   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
>
> Li-yao
>
>
Excellent. That also elegantly covers the case of functions which ignore
the argument, like "const x _ = x". Good thinking!

--Will
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20170131/87d43f4f/attachment.html>


More information about the Haskell-Cafe mailing list