<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jun 4, 2021, 12:12 PM Henrik Nilsson <<a href="mailto:Henrik.Nilsson@nottingham.ac.uk">Henrik.Nilsson@nottingham.ac.uk</a>> wrote:</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
And besides those, there are other perfectly reasonable functions<br>
like (!!) and foldr1 that I'd definitely would not say never should<br>
be used, just as I would not say that array indexing or integer<br>
divisions must be shunned because they are partial.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">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:</div><div dir="auto"><br></div><div dir="auto"> fr1 :: (a -> b -> b) -> (a -> b) -> NonEmpty a -> b</div><div dir="auto"><br></div><div dir="auto">which is best matched to</div><div dir="auto"><br></div><div dir="auto"> data NonEmpty a = End a | Cons a (NonEmpty a)</div><div dir="auto"><br></div><div dir="auto">but which can be adapted to Data.List.NonEmpty with a bit of laziness muddling.</div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>