[Haskell-cafe] ghc should be able to deduce correct use of partial functions and not give a warning in such cases

Henning Thielemann lemming at henning-thielemann.de
Fri Apr 19 07:07:06 UTC 2024


On Fri, 19 Apr 2024, Ben via Haskell-Cafe wrote:

> I'm not 100% sure what Safe.tailErr function you are using (Hoogle only 
> finds tailErr :: e -> [a] -> Either e [a],  which doesn't appear 
> compatible with the way you're using it since it takes an "error 
> message" as first argument).

I found this one:
   https://hackage.haskell.org/package/safe-0.3.21/docs/Safe.html#v:tailErr

It is problematic in even more ways. First, the reader of the code does 
not know, which tailErr the programmer means. We must look it up. Even if 
there would be only one candidate, we must look up what it does.

Second, the documentation says, tailErr is meant to suppress the new 
warning on 'tail' in GHC>=9.8, but is still partial. Not a good idea to 
suppress a warning that has a purpose.

Third, the naming of the 'safe' package and 'Safe' module is misleading, 
because there is nothing unsafe in 'tail'&Co. in the sense of SafeHaskell 
or unsafePerformIO. 'tail' is partial, that is, for some inputs it is 
undefined, read: it may run into an infinite loop. But it will not cause 
memory corruption or ignite nukes while pretending to stay away from IO.


More information about the Haskell-Cafe mailing list