RFC: Add HasCallStack constraint to partial Data.List functions.

Oliver Charles ollie at ocharles.org.uk
Tue Jun 8 18:10:52 UTC 2021



On Tue, 8 Jun 2021, at 6:36 PM, Richard Eisenberg wrote:
> I've been very much of two minds in this debate: On the one hand, having these constraints is very practically useful. On the other, what we're doing here is very un-Haskellish, in that we're letting operational concerns leak into a declarative property (a function's type). The reason we're doing this is another un-Haskellish thing -- partiality -- but that ship has sailed.
> 
> So, may I propose a slightly different way forward?
> 
> Instead of adding a HasCallStack constraint on these functions, add an IsPartial constraint. For example:
> 
> > head :: IsPartial => [a] -> a
> 
> This is slightly awkward, still, because IsPartial is a class-constraint-like-thing, but it has no parameter. But it has a few very nice properties:
> * IsPartial is declarative: it describes a property of the function without worrying about its operation.
> * If we think about the way constraints propagate, IsPartial has the right semantics: the caller of a partial function would itself become partial.

I don't think this is true.

Take:

foo :: Int -> Bool
foo _ = head [True]

Clearly foo is total - it is defined for all of its inputs. That it uses a partial function in its body isn't observable. So it's a shame that IsPartial leaks out.

I guess here you'd have me say

foo _ = partialityIsOk $ head [True]

?

Ollie
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20210608/87f5ec7e/attachment.html>


More information about the Libraries mailing list