Practical Elm for a Busy Developer

You get excited about Elm, so you breeze through the Elm guide, and get a few simple examples running. Then you come up with a great project idea, make a start on it and… things grind to a halt.

Now that you need a real world data model, a sophisticated UI and fully fleshed out interactions, Elm starts to feel truly cryptic and you start getting really frustrated. You want to make progress, but you just keep hitting one brick wall after another.

You start working out how to handle URL changes in your single-page app, and you find the signature for Browser.application:

application :
    { init : flags -> Url -> Key -> ( model, Cmd msg )
    , view : model -> Document msg
    , update : msg -> model -> ( model, Cmd msg )
    , subscriptions : model -> Sub msg
    , onUrlRequest : UrlRequest -> msg
    , onUrlChange : Url -> msg
    }
    -> Program flags model msg

Whatever is this supposed to mean?! What are you supposed to populate all these fields with? You find yourself staring at the docs and trying to reason it out, again and again.

Then you have to write a JSON decoder for nested arrays within objects within arrays:

[{"type":"FeatureCollection", 
  "features": [
    {"type": "Feature", 
     "geometry":
      {"type": "Polygon", 
       "coordinates": [[
           [173.6522,-42.3883,0], 
           [173.6349,-42.39488,0], 
           [173.6333,-42.4081,0], 
           [173.6366,-42.4255,0], 
           [173.6627,-42.4351,0], 
           [173.7003,-42.4453,0], 
           [173.7265,-42.4346,0], 
           [173.7327,-42.4202,0], 
           [173.7151,-42.3980,0], 
           [173.6995,-42.3823,0], 
           [173.6522,-42.3883,0]
           ]]
      }, 
     "properties": 
       {"name": "Polygon", 
        "styleUrl": "#m_ylw-pushpin",
        "styleHash": "-37e2b4ca"
       }
    }
  ]
  }, 
  {"type": "FeatureCollection", 
   "features": [
    {...

You spend half a day combining JSON functions this way and that, but you just can’t seem to get it right. You start getting a new appreciation for JSON.parse.

Turn your attention to styling your pages, and it threatens to turn into another headache. There are so many options:

- Inline styles
- Separate stylesheet
- elm-css
- elm-bootstrap
- elm-tachyons
- elm-ui
- ...

This doesn’t look straightforward! What is the right way to handle styles?

You haven’t even got to figuring out ports to do JavaScript interop with that cool chart library, or understanding how to organise your code once you go beyond a handful of pages.

You realise that the change of mindset required to switch to Elm is way broader than you thought. But going back to familiar JavaScript would feel like a defeat.

“I still don’t feel like I really understand
how to write code in Elm”

I know how that feels. When I first found out about Elm, I was excited by its potential to eliminate runtime errors and make development a more fun experience for my team. I was super motivated to learn it. There are plenty of beginner Elm tutorials, and it’s easy to learn the Elm syntax and concepts (it’s simple by design after all!).

However, I still found myself flailing when I tried to go beyond the simple counter and TODO list examples, because information available online quickly gets sparse.

There is still a chasm between learning the basic concepts of Elm, and using it to create complex real world applications - the kind that you’d release into production at work.

What if you could skip the frustration of figuring things out from meandering blog posts, scant tutorials, and terse package READMEs?

Practical Elm for a Busy Developer will help you get to the point where writing Elm code feels as comfortable as writing JavaScript.

It will guide you through the practical tasks of creating applications with Elm: building UIs, styling, working with JSON, interacting with JavaScript code, testing and so on. It will also show you the power user features of Elm, beyond the basic syntax.

You will start to benefit from Elm’s type system and write reliable, exception-free code.

It will NOT rehash the basics that you can easily pick up from the Elm guide and other online resources: no explaining why functional programming is great, or why we want currying, or what union types are. I don’t want to waste your time on stuff you already know.

What does the book cover?

The focus of the book is on practical topics:

  • A discussion of options for creating UIs and styling
  • Approaches and tools for preventing and finding bugs
  • JSON parsing (the most commonly reported problem Elm newcomers face)
  • Making server requests and working with commands
  • JS interop and ports
  • A discussion of code organisation as your application grows
  • An example of integrating a rich editor with the help of custom elements
  • A detailed introduction to elm-ui, a UI package that liberates you from HTML and CSS
  • A discussion of integrating Elm into a JS application
  • An in-depth look at language features such as pattern matching
  • Tools for being more productive when writing Elm code
(I will also send you updates when I publish an Elm related post.)

What do people say about the book?

Here are some of the things people had to say about the book:

“I’ve only started it, but chapter one blew my mind! I thought I knew Elm well, but I never used point-free style or those special placeholder variable types (though I’ve seen those in other packages).”

— Robert Swirsky

“What I really appreciate and enjoy in the book is the way you incrementally refactor the application to introduce a different way to model the data that solves the problem. I like when the type system can prevent bugs, and completely eliminate some bugs. I like the way you introduce the sub-update thing. I had to look long and hard at some of Richard Feldman’s [SPA example] code to arrive to this conclusion, and spent a long time shouting WTF while trying to understand what was going on. I would have loved to have this chapter back then…

I would definitely recommend your book. I am looking forward to the next chapters about how to use the type system.”

Christophe Graniczny

“While I usually find the Elm documentation on the web excellent, I find the stuff in your book more directly transferrable to real-world tasks. I look forward to reading about saving session IDs to localStorage or Custom Elements, for example. Thanks a lot for your book, I find it a valuable resource.”

Andreas Wagner

“I’m liking the book so far and am looking forward to what you have in store for the rest of the chapters. Being introduced to elm-analyse made me go back to previous projects, start linting them, and add elm-analyse to their build pipelines.”

Paul Fioravanti

“It’s really helped me grasp a lot of concepts that I was aware of before, but didn’t quite feel confident in myself. Your book has been a godsend. Thanks so much for your hard work.”

/bin/bash

“My most valuable take-aways are the phrase (my paraphrasing) “Elm is just a collection of types and functions” and the discussions on packaging/splitting to individual files, etc. Absolutely I will recommend your book; it is genuinely practical, dare I say pragmatic, it is Elm from quite a different perspective to, for example, the Elm Guide.”

— Bruce

Yes, I would definitely recommend the book. It is the best of all the books I’ve tried (which are both Richard Feldman’s and Jeremy Fairbank’s book).

I love your book, because it is, as you state, not for pure beginners and that is awesome. There are enough free tutorials online to learn the basics, nobody needs a book for that in my opinion but your book offers a real value added addressing the slightly advanced programmers.

— Josef

Your book and blog posts have been super helpful to me as a designer learning Elm. I’ll be speaking about my experience learning to code via Elm at Elm Europe. So you were a part of making that a possibility. Thank you!

Jono Mallanyk

Read your book 2 times already. Love your book, it is the first one that talk about problems that you start to see only on big projects and how to organize your code. The two things in the book that where most valuable for me are how to organize modules and testing. Thank you very much for writing this book.

— Barak Bar Orion

Honestly i was aha-ing throughout the entire book, but to be specific there were two moments that stood out to me and were extremely useful; the first was elm-ui and browser package, I don’t know how to express how happy I had felt when elm-ui finally became clear to me, and your book was a great example and reference to put all the pieces together, the second was server requests and JSON, it was the reason why I bought this book in the first place, all the examples that I had found online were outdated and I couldn’t understand how they worked.

— Yousof Hafiz

There is a long and painful distance from the “Todo app tutorial” to your app’s 3rd release in production, whatever language/framework one might consider. Your book is the map + sign poles + backpack checklist for the Elm journey!

— Leo Nistor

I devoured that book over the weekend after purchasing it. It was an awesome read. The chapter on a few useful bits of functional programming theory was worth the price of the book for me. I spend a decent amount of time with functional programming, but that part of Elm is poorly documented. I also loved the more practical workflow tips.

— Barnaby

More testimonials
“I really like it, the practical approach of skipping through lots of information already present elsewhere. The chapter “beyond basic syntax” was great, I’m also very interested in using elm-ui, nice chapter also. Overall yes I would highly recommend it.”

— Francisco Dibar
“Bought your book Practical Elm. Very early into the content, only gotten to page 65 but already had quite a bit clarified. Must say I was sceptical buying your book as I couldn’t find much info about you, you know confs, talks etc but I’m very pleased so far.”

Napoleon Ahiable
“I’m reading your Elm book and really like it — it answers several questions/problems I was facing. Thank you for writing the book, I really appreciate it!”

— Andreas Pehnack
The aha moment was when I’ve read about the flip function. I even smiled. Because I had struggled a bit with that function in Haskell. The example in the book demonstrates the essence very well.

— Anton Rich
Would I recommend Practical Elm…? Most definitely. The Official Guide in the Elm docs is great but Practical Elm… goes beyond the language and discusses tooling and libraries too. The style is clear and digestible. It takes Elm from a well-designed language to something I can use to get stuff done.

— Tim Sharples
First, I really like your style of writing and the high concentration of useful information. Second — this book is practical but yet there are really useful bits of theory in it and I like this balance. I found chapters about Point-free style and Phantom types very useful. Also “Adding Input Validation” helped me to understand the elm-validate package better.

Andrey Miskov
I felt like I’d grokked the language and the Elm architecture, but the way the JSON decoders work still looked like voodoo to me. The way you explained it definitely helped. The explanation of JSON.Decode.Pipeline was really good here too. The early chapters around syntax, types, destructuring etc. has some great stuff. Even if we’re not using it all right now I know I can refer back to these when we need to. These are now “tools in our belt” so to speak.

— Alex Justus


Feel like you’re in the future of frontend development
with Elm

You’ll be able to glide up the learning curve and enjoy Elm’s well thought out simplicity and reliability.

Even if you can’t use Elm full time, you will probably find that the “Elm mindset” improves how you develop software in other languages like JavaScript.

And as functional programming is only getting more popular, having an Elm project or two on your resume will also look good when it’s time to get a promotion or switch jobs!


Buy Practical Elm

Formats
PDF, Mobi, EPUB
Pages
220
Money back guarantee
30 days
Elm version
0.19
Tons of code samples
Sample app code included
No rehashing of basics
Get the book now for $39
Get your Elm projects off the ground with confidence!
Practical Elm cover

Combine Practical Elm with elm-ui: The CSS Escape Plan

Would you like to build UIs in Elm without relying on CSS and HTML?

elm-ui is a package that provides an intuitive and elegant model for building UIs, and of course you also get compiler support when using it. I’ve written a guide about elm-ui, elm-ui: The CSS Escape Plan, and you can get it at a discount together with the purchase of Practical Elm.

Practical Elm gives you an introduction to elm-ui, while elm-ui: The CSS Escape Plan is a comprehensive guide to the package and includes a showcase of examples as well.

Not ready to buy yet?

Check out the sample chapter to see if the style of the book works for you:

(I will also send you updates when I publish an Elm related post.)

About the author

Alex Korban Hi, I’m Alex Korban. I’m an author and software consultant with an interest in functional programming, databases, and geospatial applications.

I promote Elm and run several projects to make it easier for people to learn it and use it:

  • I’m the editor of Elm Weekly, a weekly Elm newsletter
  • I made Elmstatic, a static site generator that allows you to make sites with Elm
  • I created and maintain Elm Catalog to help people find Elm packages & tools
  • I write about Elm on this site (35+ posts as of last count).

Previously, I co-founded a company to help the heavy construction industry improve safety and productivity when building highways, tunnels, and other infrastructure. We did this by collecting geospatial data via mobiles and Bluetooth beacons, and then analysing and visualising it.

I’ve also written several books about C++, and a book about working with time in PostgreSQL.

Prior to that I worked on a wide range of software, such as pre-iPhone mobile applications, a flight simulator, GPS-based vehicle fleet tracking, and automatic control software for construction machines (bulldozers, excavators, and self-driving kerb laying machines).

FAQ

Can I pay with PayPal?

Yes, you can pay either via PayPal or with a credit card. For credit card payments, I use Stripe, so your information is secure either way.

What if the book isn’t useful to me?

I offer a 30-day money back guarantee, so there is no risk in buying.

What format is the book in?

The book is provided in PDF format, and also EPUB and Mobi. Note, however, that EPUB and Mobi versions are formatted for tablets and provided for convenience only. I don’t test them extensively, so formatting may be off – in particular, code samples may wrap awkwardly.

What version of Elm is the book written for?

The book is up to date with Elm 0.19 and packages like mdgriffith/elm-ui (1.1.0), elm-explorations/test (1.2.0) and elm/http (2.0.0). In case you’re still using Elm 0.18, I’ve also included the Elm 0.18 version of the book and sample code in the download.

Will I get updates?

I will update the book if I discover errors, and you will get those updates free.