
On Tue, Jun 01, 2021 at 08:50:43PM +0200, Andreas Abel wrote:
On 6/1/21 2:57 AM, Henrik Nilsson wrote:
But every now and then the reason, say, a list is non-empty is just a little bit too subtle to capture in a reasonable way ..., and the use of functions like foldl1 is entirely appropriate, along with a comment in the code explaining why it is safe.
A bit off topic (my apologies for the hijacking), but if you my fellow Haskellers think you understand when the use of such a partial function is safe, I challenge you to look at:
https://gitlab.haskell.org/ghc/ghc/-/issues/19917
I thought that e.g. `last (x : xs)` can never throw the error `Prelude.last: empty list` but I had to learn otherwise...
(So my conviction is that `List.head`, `List.last` and the like should be eradicated entirely and any step that brings us closer to this goal gets my approval.)
Wow, this is *very* interesting. So when someone grumbles
I got the very unhelpful error message "Prelude.last: empty list" and I can't even see how an empty list can have entered my program
they may be completely correct: the error can be printed when there is no empty list at all! Tom