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

David Feuer david.feuer at gmail.com
Fri Jun 4 16:38:18 UTC 2021


On Fri, Jun 4, 2021, 12:12 PM Henrik Nilsson <
Henrik.Nilsson at nottingham.ac.uk> wrote:

> And besides those, there are other perfectly reasonable functions
> like (!!) and foldr1 that I'd definitely would not say never should
> be used, just as I would not say that array indexing or integer
> divisions must be shunned because they are partial.
>

FWIW, I think (!!) tends to show up an awful lot (maybe mostly) in code
written by beginners who aren't yet thinking of lists structurally. foldr1
is deceptiveā€”it's easy to think it can do more than it can, and I've seen
its laziness characteristics confuse even an experienced Haskeller. It's
not even really nice for non-empty list types. Much clearer:

  fr1 :: (a -> b -> b) -> (a -> b) -> NonEmpty a -> b

which is best matched to

  data NonEmpty a = End a | Cons a (NonEmpty a)

but which can be adapted to Data.List.NonEmpty with a bit of laziness
muddling.

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20210604/a91d6f01/attachment.html>


More information about the Libraries mailing list