|
|
|
|
|
by lisperforlife
4081 days ago
|
|
In addition to the lexical change, the result now returns a Maybe instead of the actual element. This was done to avoid runtime crashes when head encounters an empty list. However, this means that everytime you have to use head, you will have to pattern match on Just x/Nothing to consume it. However, you can still use the (x::xs) pattern matching syntax to obtain head and tail and pattern match on [] for empty lists. Absence of applicatives or monads mean that you have to explicitly pattern match on Just/Nothing everytime. There is a proposal to add `?` as an operator to obtain the head of the list without the Maybe and provide a default value if it is Nothing. Also there is another proposal to allow `unsafe` for the program to crash if the result is Nothing. |
|
It seems to me that most real uses can probably be solved by map, and withDefault if you really need to get out of the Maybe monad for some reason (though map should make it so that you don't have to for most things.)
> There is a proposal to add `?` as an operator to obtain the head of the list without the Maybe and provide a default value if it is Nothing.
Since elm supports user-defined operators, can't you just do that yourself. Something like: