3 ms·
'head' is a function that returns the first element of a list. On empty lists, it raises an exception. I'm not sure what's the origin of this, I know that stand
by Zababa 5y ago
'head' is a function that returns the first element of a list. On empty lists, it raises an exception. I'm not sure what's the origin of this, I know that standard ML also does that. The thing is that ~20 years ago exceptions in functional programming languages were seen as something normal, whereas these days people tend to prefer sum types. So what they would want is for head on a list of number to return a Maybe number, which can be Just number, or Nothing. This would allow the compiler to check for errors, and allow for easier composition since Maybe is monadic (if you don't know what monads are, think of them as an ubiquitous interface, like Iterator in another language).