[Haskell-cafe] Spurious [-Woverlapping-patterns] -- [cont] ghc should be able to deduce correct use of partial functions

Anthony Clayden anthony.d.clayden at gmail.com
Sat Apr 27 06:24:32 UTC 2024


I think this is a similar 'failure to deduce' partiality as last week's
thread; but the other way round (and with ViewPatterns) -- at GHC 8.10.7:

GHCi> :set -XViewPatterns
GHCi> :set -Wincomplete-patterns        -- also warns overlapping
GHCi> (\x -> case x of {((\(Just j) -> j) -> j2) -> j2;  Nothing -> 'N'})
Nothing

===> <interactive>: warning: [-Woverlapping-patterns]
    Pattern match is redundant
    In a case alternative: Nothing -> ...
*** Exception: <interactive>:16:21-34: Non-exhaustive patterns in lambda

(Same Warning then same Exception if I compile the code.)

So GHC isn't smart enough, despite the explicit `(\(Just j) -> ...)`, to
see that ViewPattern usage is incomplete?

I thought ViewPatterns got desugarred into clunky chains of nested `case`s,
so that the pattern coverage checker could see what's going on? I was
testing this because if anything I expected it to report coverage was
incomplete.

To get both a claim "Pattern match is redundant" and "Non-exhaustive" seems
particularly unhelpful.

AntC
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20240427/c09d70a6/attachment.html>


More information about the Haskell-Cafe mailing list