<div dir="ltr"><div><div><div><div><div><div><div><div>I feel like there's no good technical solution here. For example, this is potentially dangerous in the face of a changing data type, but presumably wouldn't fall under the definition of a "default branch":<br><br></div><div>data T = A | B -- Later, C could be added which might need special handling<br></div>case ... of<br> [] -> ...<br></div> (A : xs) -> ...<br></div> (_ : xs) -> ...<br><br></div>On the other hand, this would presumably be a "default branch" but I challenge you to replace the wildcard pattern with an exhaustive list of pattern matches:<br><br></div>case ... of<br> 0 -> ...<br> 1 -> ...<br> _ -> ...<br><br></div>Of course this is a special case, but there are many data types in the wild with a large number of constructors: think of generated enumerations, for example.<br><br></div>I'd say education is the best option here. I thought wildcards were convenient, until I realized their effect on maintainability in the face of future data type changes.<br><br></div>Erik<br><div><div><div><div><div><div><br></div></div></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 31 January 2017 at 18:31, Eric Seidel <span dir="ltr"><<a href="mailto:eric@seidel.io" target="_blank">eric@seidel.io</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> Note that<br>
><br>
> case <foo><br>
> | [] -> ...<br>
> | (_ : xs) -> ...<br>
><br>
> also contains a wildcard-pattern. So emitting a warning for every use<br>
> of wildcard patterns would likely lead to a lot of pain.<br>
<br>
</span>Yes, good point, that would be too restrictive. When I said wildcard-pattern I was thinking specifically of a top-level wildcard, so your example would be accepted, but e.g.<br>
<br>
case ... of<br>
[] -> ...<br>
_ -> ...<br>
<br>
would be rejected.<br>
<span class=""><br>
> You'd instead want to warn about "default branch", e.g.<br>
><br>
> case <foo><br>
> | [] -> ...<br>
> | (1 : xs) -> ...<br>
> | (_ : xs) -> ...<br>
><br>
> here the wildcard pattern does correspond to a "default branch" and<br>
> might hence deserve a warning.<br>
<br>
</span>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.<br>
<div class="HOEnZb"><div class="h5">______________________________<wbr>_________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/haskell-<wbr>cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</div></div></blockquote></div><br></div>