News for hackers. Stuff that matters.
Re:Elm by Example by ekidd on Sunday December 13, 2015 @11:04AM (#10726648)
Elm is a profoundly interesting language, but I've had mixed experiences developing in it. I've been working on a small-but-hairy web app using Elm, and my first reactions are:

1. Elm encourages highly-rigorous state handling, thanks to the React-like "Elm Architecture" https://github.com/evancz/elm-architecture-tutorial/ and features like the Maybe type and ADTs. I rarely worry that I've overlooked some horrible, asynchronous corner case or that something might be null.

2. The Elm architecture requires a considerable amount of boilerplate code, at least relative to something like Ember.js. It's often necessary to thread significant amounts of application state through parameters, for reasons similar to the ones here: https://docs.google.com/presentation/d/1afMLTCpRxhJpurQ97VBH... But when you combine that with the need to use "case" matches everywhere to destructure ADTs, and the fact that you can't define guard expressions (or destructure things nested inside record types), it tends to result in a lot of extra typing.

3. The Elm tooling is a mixed bag. The error message are the best I've ever seen, but the sweet time-travelling debugger just refused to run when I tried to use it with the Elm architecture tutorials. This pattern of brilliance and brokenness feels fairly pervasive at this point.

4. The Elm community can occasionally be a bit frustrating to work with as an outsider. Sometimes, when I run into an issue, I eventually find a GitHub discussion like this: https://github.com/evancz/start-app/pull/37 , where somebody is trying to address an actual issue (one that was biting me, too), and the community is more-or-less throwing up its hands. Also, the Elm community has an occasionally surprising tendency to close GitHub issues quickly, even if it's known that they'll probably need to fix something someday: https://github.com/evancz/start-app/issues/35#issuecomment-1...

5. For me, Elm feels considerably more restrictive than programming in Haskell.

6. Elm's type checker and design do have one huge payoff: Even very complicated apps with lots of tricky asynchronous state tend to work on the first run after they make it past the type checker. This is hugely valuable, and it makes me more inclined to forgive Elm's limitations elsewhere.

Overall, Elm is exploring some really important ideas, and it's pushing the general React-style architecture to its logical limits. I think I'd consider it for small- to medium-sized apps with lots of tricky state, and with developers who are strong at functional programming.

Re:Elm by Example by pka on Sunday December 13, 2015 @12:31PM (#10727009)
I've had a similar experience. I was ok with it though, because the pure data -> DOM nature of Elm's architecture was better than anything else.

Until I found PureScript. Especially purescript-halogen [0], which is basically how one might make React in Haskell. Everything is still pure, but you can define nested state (not to be confused with React-style local mutable state!) without Elm's boilerplate wiring.

The "update" function runs in the continuation monad, which means that one can do something like this:

        modify (\(State s) -> State $ s { loadingUsers = true })
        users <- liftAff' $ fetchUsers
        modify (\(State s) -> State $ s { users = users, loadingUsers = false })
and this runs asynchronously, but it still modifies one global state. Compare with Elm's "return fetch effect, fire event, react on event in update function".

There's everything one might need in PureScript: functors, applicatives, monads, so the language feels much less constraining than Elm.

Drawbacks:

- they use bower for package management - it's ok, but elm-package's enforced semversioning is really nice.

- no default imports, so imports can get verbose [1]

- the error messages might not be as nice as Elm's, but I haven't had a problem so far, at all

- no elm-reactor - though since halogen is just a library, the UI is pure and there's no magic state-isolating runtime, you can probably roll your own relatively easily

- not as easy to pick up as Elm - but no problem for a Haskell programmer. Elm definitely focuses more on user-friendliness and Javascript converts.

...but these are minor nitpicks - I am in the process of making the switch and porting an app from Elm right now, and it definitely was the right decision.

[0] https://github.com/slamdata/purescript-halogen

[1] https://github.com/slamdata/purescript-halogen/blob/master/s...

Re:Elm by Example by pka on Sunday December 13, 2015 @01:24PM (#10727219)
One more thing that just made my life easier: Purescript recently got generic deriving [0], which means that one can derive Eq, Ord, JSON etc instances easily now!

[0] https://github.com/purescript/purescript-generics

Re:Elm by Example by masklinn on Sunday December 13, 2015 @11:13AM (#10726687)
With respect to (2), I've found non-trivial forms to be an especially annoying example. There seems to be lot of fairly trivial repetition in elm architecture code which I can't really manage to extract.
Re:Elm by Example by purescript on Sunday December 13, 2015 @11:15AM (#10726695)
I've found lenses (for zooming state) and prisms (for zooming actions) to be very useful for solving this problem.
Re:Elm by Example by vagif on Sunday December 13, 2015 @01:08PM (#10727152)
Can you comment on your latest approach in purescript-thermite to use lenses (focus, foreach) vs halogen architecture? Pros / Cons?
Re:Elm by Example by purescript on Sunday December 13, 2015 @01:40PM (#10727293)
I haven't used latest Halogen yet, so I can't give a detailed comparison, but the approach in Thermite [1] is indeed what I am referring to above. It was based on some work in the OpticUI library [2], and has worked out quite nicely for the few projects I have applied it to.

I will say that the types in Halogen seem more complex, but they can be justified by the fact that the coproduct machinery helps ensure all actions get handled somewhere. This may be possible with prisms, I'm not sure yet. This library [3] seems relevant.

One issue I've found, which I understand the Halogen folks are also finding, is that it is tricky to wire up action handlers such that a subcomponent can invoke an action and have a parent act on it and invoke its own action in response. Granted, this is a relatively infrequent use case, and you can always push such logic into some shared parent.

[1]: https://github.com/paf31/purescript-thermite/ [2]: https://github.com/zrho/purescript-optic-ui [3]: https://github.com/joneshf/purescript-totally

Re:Elm by Example by tel on Sunday December 13, 2015 @11:56AM (#10726872)
Does Elm have a lens library?
Re:Elm by Example by purescript on Sunday December 13, 2015 @12:30PM (#10727002)
I know there is the Focus library [1]. I'm not sure about prisms, traversals etc.

[1] http://package.elm-lang.org/packages/evancz/focus/1.0.1/Focu...

Re:Elm by Example by vagif on Sunday December 13, 2015 @11:18AM (#10726708)
Do you have experience with similar languages for frontend development? Like purescript or ghcjs? Did you chose elm just because it was the first thing you tried or because you had frustrating experience with others?