News for hackers. Stuff that matters.
Re:Failing in Haskell by bspammer on Saturday February 26, 2022 @01:26PM (#30480228)
Haskell has had non-empty lists as a type for a long time: https://hackage.haskell.org/package/base-4.16.0.0/docs/Data-...

Having partial functions in the Prelude is, as far as I know, widely regarded as a mistake and they are only kept around for backwards compatibility. Anyone writing code nowadays should be using safeHead or non-empty lists.

Re:Failing in Haskell by oats on Saturday February 26, 2022 @02:37PM (#30481023)
Or pattern matching that takes account of the empty list case. Orrrrr using a fold! I usually find when I start matching on list values that the function could be better expressed with a fold instead.
Re:Failing in Haskell by Tainnor on Sunday February 27, 2022 @06:24AM (#30487289)
Sure, but non-empty lists don't generalise easily to the case where you need the nth element, unless you nest them awkwardly.