[Haskell-cafe] ghc should be able to deduce correct use of partial functions and not give a warning in such cases
Olaf Klinke
olf at aatal-apotheke.de
Thu Apr 18 07:39:16 UTC 2024
> ghc should be able to deduce correct use of partial functions and not
> give
> a warning in such cases, e.g. in 9.8.2
>
> if null ys then [] else [(xs,tail ys)])
>
> gets a warning
>
> warning: [GHC-63394] [-Wx-partial]
>
> but it is clear that this use of tail will never be a problem so IMHO
> that
> line of code should not get a warning.
>
> Does anybody know if there is a plan or enhancement request to
> eliminate
> such warnings?
>
> Cheers
> George
The problem is that both partiality checks and checks for incomplete
pattern matches are undecidable in general, that is, without assistance
the compiler can not infer partiality without risking infinite loops.
Checks for incomplete pattern matches could be decidable, if it was not
for view patterns, where you can hide arbitrary function applications
(think unsafePerformIO) in. Currently GHC plays the safe card, see this
thread:
https://mail.haskell.org/pipermail/haskell-cafe/2024-January/136545.html
With the help of special annotation such as Liquid Haskell you might be
able to teach the compiler that your use of partial functions is fine.
https://ucsd-progsys.github.io/liquidhaskell/
However, I second Henning in that a -Wx-partial warning hints at the
necessity of a code re-factoring.
Olaf
More information about the Haskell-Cafe
mailing list