<div dir="ltr">λ: data X = A|B<br>λ: let x = A in case x of A -> True; B -> False<br>True<br>λ: case A of A -> True ; B -> False<br><br><interactive>:3:23: warning: [-Woverlapping-patterns]<br> Pattern match is redundant<br> In a case alternative: B -> ...<br>True<br><div><br></div><div>Isn't this violating referential transparency (in a way)?</div><div><br></div><div>--Todd</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jul 21, 2023 at 3:15 AM Jeff Clites via Haskell-Cafe <<a href="mailto:haskell-cafe@haskell.org">haskell-cafe@haskell.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I think it’s saying it’s redundant because you already known what constructor it is; I’m guessing you’d get the same error from “case A of A -> …”.<br>
<br>
Jeff<br>
<br>
> On Jul 21, 2023, at 2:57 AM, Ben Franksen <<a href="mailto:ben.franksen@online.de" target="_blank">ben.franksen@online.de</a>> wrote:<br>
> <br>
> 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.<br>
> <br>
> Cheers<br>
> Ben<br>
> <br>
>> Am 20.07.23 um 06:53 schrieb Viktor Dukhovni:<br>
>>> On Wed, Jul 19, 2023 at 09:24:20PM -0700, Todd Wilson wrote:<br>
>>> Can someone please explain this:<br>
>>> <br>
>>> ghci> case 1 of 2 -> 3<br>
>>> <br>
>>> <interactive>:1:11: warning: [-Woverlapping-patterns]<br>
>>> Pattern match is redundant<br>
>>> In a case alternative: 2 -> ...<br>
>>> *** Exception: <interactive>:1:1-16: Non-exhaustive patterns in case<br>
>>> <br>
>>> The non-exhaustive patterns part is obvious, but what is redundant about<br>
>>> this match? And how can there be overlapping patterns when there's only one?<br>
>> The error message changed betweek 8.8 and 8.10:<br>
>> GHCi, version 8.8.4: <a href="https://www.haskell.org/ghc/" rel="noreferrer" target="_blank">https://www.haskell.org/ghc/</a> :? for help<br>
>> λ> data X = A | B<br>
>> λ> case A of B -> 42<br>
>> *** Exception: <interactive>:2:1-18: Non-exhaustive patterns in case<br>
>> vs.<br>
>> GHCi, version 8.10.5: <a href="https://www.haskell.org/ghc/" rel="noreferrer" target="_blank">https://www.haskell.org/ghc/</a> :? for help<br>
>> λ> data X = A | B<br>
>> λ> case A of B -> 42<br>
>> <interactive>:2:11: warning: [-Woverlapping-patterns]<br>
>> Pattern match is redundant<br>
>> In a case alternative: B -> ...<br>
>> *** Exception: <interactive>:2:1-17: Non-exhaustive patterns in case<br>
>> The exception part is the same, and I hope non-controversial, the<br>
>> pattern match is indeed non-exhaustive. What's new is the compile-time<br>
>> warning. It is documented at, e.g.:<br>
>> <a href="https://ghc.gitlab.haskell.org/ghc/doc/users_guide/using-warnings.html#ghc-flag--Woverlapping-patterns" rel="noreferrer" target="_blank">https://ghc.gitlab.haskell.org/ghc/doc/users_guide/using-warnings.html#ghc-flag--Woverlapping-patterns</a><br>
>> where it is explained that a pattern is considered "overlapping" when it<br>
>> is unreachable, which is true in this case, though for reasons other<br>
>> than redundancy wrt. a prior pattern. And indeed we see the true<br>
>> issue/criterion is "reachability":<br>
>> λ> case A of B | GHC.Exts.considerAccessible -> 42<br>
>> *** Exception: <interactive>:3:1-47: Non-exhaustive patterns in case<br>
>> The same is of course seen if the warning is disabled:<br>
>> λ> :set -Wno-overlapping-patterns<br>
>> λ> case A of B -> 42<br>
>> *** Exception: <interactive>:6:1-17: Non-exhaustive patterns in case<br>
>> The pattern match is redundant given the specific scrutinee. Perhaps<br>
>> non-reachability in this case could be reported via a different warning,<br>
>> but we have what we have.<br>
> <br>
> -- <br>
> I would rather have questions that cannot be answered, than answers that<br>
> cannot be questioned. -- Richard Feynman<br>
> <br>
> <br>
> _______________________________________________<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-bin/mailman/listinfo/haskell-cafe</a><br>
> Only members subscribed via the mailman list are allowed to post.<br>
_______________________________________________<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-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div>