[Haskell-cafe] Redundant/overlapping patterns?

Andreas Källberg anka.213 at gmail.com
Fri Jul 21 20:17:33 UTC 2023


I think unreachable would be instead of “overlapping”, rather than instead of “redundant”, since those refer to different things. Redundant patterns are when the constructor is already known, while overlapping is when the case unreachable.

Regards,
Andreas

> On 21 Jul 2023, at 11:57, Ben Franksen <ben.franksen at online.de> wrote:
> So the error message should talk about "unreachable pattern" instead of "redundant pattern". That would cover all situations and would be less confusing in this special one.
> 
> Cheers
> Ben
> 
> Am 20.07.23 um 06:53 schrieb Viktor Dukhovni:
>> On Wed, Jul 19, 2023 at 09:24:20PM -0700, Todd Wilson wrote:
>>> Can someone please explain this:
>>> ghci> case 1 of 2 -> 3
>>> <interactive>:1:11: warning: [-Woverlapping-patterns]
>>>     Pattern match is redundant
>>>     In a case alternative: 2 -> ...
>>> *** Exception: <interactive>:1:1-16: Non-exhaustive patterns in case
>>> The non-exhaustive patterns part is obvious, but what is redundant about
>>> this match? And how can there be overlapping patterns when there's only one?
>> The error message changed betweek 8.8 and 8.10:
>>     GHCi, version 8.8.4: https://www.haskell.org/ghc/  :? for help
>>     λ> data X = A | B
>>     λ> case A of B -> 42
>>     *** Exception: <interactive>:2:1-18: Non-exhaustive patterns in case
>>   vs.
>>     GHCi, version 8.10.5: https://www.haskell.org/ghc/  :? for help
>>     λ> data X = A | B
>>     λ> case A of B -> 42
>>     <interactive>:2:11: warning: [-Woverlapping-patterns]
>>         Pattern match is redundant
>>         In a case alternative: B -> ...
>>     *** Exception: <interactive>:2:1-17: Non-exhaustive patterns in case
>> The exception part is the same, and I hope non-controversial, the
>> pattern match is indeed non-exhaustive.  What's new is the compile-time
>> warning.  It is documented at, e.g.:
>>     https://ghc.gitlab.haskell.org/ghc/doc/users_guide/using-warnings.html#ghc-flag--Woverlapping-patterns
>> where it is explained that a pattern is considered "overlapping" when it
>> is unreachable, which is true in this case, though for reasons other
>> than redundancy wrt. a prior pattern.  And indeed we see the true
>> issue/criterion is "reachability":
>>    λ> case A of B | GHC.Exts.considerAccessible -> 42
>>     *** Exception: <interactive>:3:1-47: Non-exhaustive patterns in case
>> The same is of course seen if the warning is disabled:
>>     λ> :set -Wno-overlapping-patterns
>>     λ> case A of B -> 42
>>     *** Exception: <interactive>:6:1-17: Non-exhaustive patterns in case
>> The pattern match is redundant given the specific scrutinee.  Perhaps
>> non-reachability in this case could be reported via a different warning,
>> but we have what we have.
> 
> -- 
> I would rather have questions that cannot be answered, than answers that
> cannot be questioned.  -- Richard Feynman
> 
> 
> _______________________________________________
> 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.


More information about the Haskell-Cafe mailing list