Hello Elm and Haskell!

February 21, 2017

Briefly describe my first Elm application and list the reasons why I decided to programming exclusively in Elm.

Two men standing and four men seated around table under large elm tree. class=
© circa 1916 Anonymous for Library of Congress

Why Elm?

I am by no means a JavaScript expert. I’ve built a total of four commercial applications; one with Backbone and three with ExtJS. For my day job I primarily code in Java and ExtJS.

My Elm experience was a side-project where I wanted a calendar widget where people could quickly pick multiple dates from the next three months as a way of filtering local events.

Over the course of a month or so, I was able to learn enough of Elm that I could build this date picker. I enjoyed programming in Elm so much that I decided to work 100% with Elm and to learn Haskell.

Here are the reasons why.

There are great learning materials.

I started with the free, on-line class Elm For Beginners, Start Building Web Apps using Elmlang Today. Short video lessons, ranging in length from three to eleven minutes long, each focusing on one specific topic was a great introduction.

I made it up through lesson 13 (out of 18) before I started coding.

The compiler was a revelation

It is hard to overstate this. I ended up writing about 600 lines of Elm code in all to accept today’s date, render the next three months, respond to clicks on the dates and keep track of which dates were currently selected.

The process of writing in Elm was different than any other language I have written in before. Typically, I use TDD: write a stubbed function, write a test, and then flesh out the feature. In Elm, I wrote the code and then “just” had to get the code to compile. Just is in quotes because it initially it took me a long time to figure out the compilation issues.

So … write a basic feature, spend a long time getting it to compile. Then, write the next feature, and spend a little less time getting it to compile. Finally, after getting the last feature to compile, I tested it in a browser.

It worked.

Java is strongly typed, but Elm felt so different.

Similarities with CQRS

The whole model/view/update pattern felt very similar to the command/query pattern. The Elm model defines state, the update step takes a command and updates state, and the view step takes state and renders a view.

In the command/query responsibility separation pattern, one object processes commands and a different object responds to view requests. Very similar in how responsibilities are split up.

I’m a fan of CQRS, so this was a plus.

And now onto Haskell!

I think people in the Haskell world that criticize Elm do Haskell a disservice. Elm is an easy gateway to Haskell and there are lots of JavaScript programmers. Perhaps the visual of a herd of JavaScript programmers flooding to Haskell is not a pretty picture.

After my experience with the Elm compiler, I wanted to get the same benefits when writing back end code, so I picked up Haskell. My experience with Elm (and Erlang before that) made it easier to start being productive with Haskell.


If you see an error or something that could be improved, please let me know. This is a blog about me learning, so I expect I will get some stuff wrong. The best way to reach me is by email: mkbucc1234@gmail.com (after deleting all the numbers).

To make a comment, check for a thread on the elm subreddit and if there isn't one, then start one up.

Follow on Twitter: @mbucc

Back to the index.