Elm 0.15: Asynchrony with Tasks
elm-lang.org
elm-lang.org
head : List a -> Maybe a
Compare that with the same function in Haskell. head :: [a] -> a
To me, the Elm version makes more sense. (It also avoids having to explain that "[a]" means "list of 'a's".)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:
list ? default = withDefault default (head list) withDefault 0 (head listOfNumbers)
No need to pattern match every time. :)Docs for withDefault: http://package.elm-lang.org/packages/elm-lang/core/1.0.0/May...
In this case, I definitely prefer the correct version Elm implements. I think Haskell just doesn't want to admit it's type system can't model everything. :)
singleton : a -> NonEmpty a
cons : a -> NonEmpty a -> NonEmpty a
head : NonEmpty a -> a
last : NonEmpty a -> a
init : NonEmpty a -> Maybe (NonEmpty a)
tail : NonEmpty a -> Maybe (NonEmpty a)"This release introduces tasks, a way to define complex asynchronous operations. Similar to C#’s tasks and JavaScript’s promises, tasks make it simple to describe long-running effects and keep things responsive. They also provide a way to wrap up tons of browser APIs in Elm."
However, there is no way to work with monads in the abstract in Elm (yet), there is only the concrete API.
It seems like lots of people in the functional community are fans.
I spent some time trying to get it, and I got part of it, but I'm not yet a fan.