Elm, an alternative to Javascript

Published on 11/05/2022

What is Elm ?

Elm is a pure functional programming language with a strong type system. It is Open Source (released under BSD-3-Clause license) and this year is 10 years old.

The current version is 0.19.1 and it is surrounded by an active community.

Elm is “domain-specific”, its goal is to help you building front-end web applications. The compiler produces optimized Javascript code to run into the browser. It supports developer with a detailed and more clear as possible output to help resolve errors.

An example of compiler output:

naming error
Line 44, Column 12
I cannot find a `Timestamp` type:

44|       ts : Timestamp,
               ^^^^^^^^^
These names seem close though:

    Timstamp
    Time.Zone
    Task.Task
    Time.Month

Hint: Read <https://elm-lang.org/0.19.1/imports> to see how `import`
declarations work in Elm.

There is an online editor, named Ellie, to play with the language without the need to install anything on your machine. Ellie permits to install dependencies for your code, so you can prototype an entire project with it.

Applications in Elm follow the TEA (The Elm Architecture), an architectural pattern based on the following concepts:

  • Model: the state of the application.
  • View: transforms model into HTML code.
  • Update: updates the model intercepting messages which came from the user interaction with the view.

Why Elm ?

I started using Elm because I wanted to experience with the functional paradigm. I tried it using Javascript, but its multi-paradigm nature didn’t help me in having a focused functional experience, so I decided to try with an only-functional language and I discovered Elm, described as a good first step into the functional world.

To take practice with Elm I implemented a tiny project ts-converter: a browser extension to translate timestamps into human readable dates. Ts-converter is released as a libre software under GPLv3 license.

  • Article is published under CC-BY 4.0
  • If not explicitly declared code snippets are published under MIT license