
On Fri, Jun 4, 2021, 12:12 PM Henrik Nilsson < Henrik.Nilsson@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.