
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":
data T = A | B -- Later, C could be added which might need special handling
case ... of
[] -> ...
(A : xs) -> ...
(_ : xs) -> ...
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:
case ... of
0 -> ...
1 -> ...
_ -> ...
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.
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.
Erik
On 31 January 2017 at 18:31, Eric Seidel
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.
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.
case ... of [] -> ... _ -> ...
would be rejected.
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. _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.