Elm (programming language)
Elm is a domain-specific programming language for declaratively creating web browser-based graphical user interfaces. Elm is purely functional, and is developed with emphasis on usability, performance, and robustness. It advertises "no runtime exceptions in practice",[10] made possible by the Elm compiler's static type checking.
History[edit]
Elm was initially designed by Evan Czaplicki as his thesis in 2012.[11] The first release of Elm came with many examples and an online editor that made it easy to try out in a web browser.[12] Mr. Czaplicki joined Prezi in 2013 to work on Elm,[13] and in 2016 moved to NoRedInk as an Open Source Engineer, also starting the Elm Software Foundation.[14]
The initial implementation of the Elm compiler targets HyperText Markup Language (HTML), Cascading Style Sheets (CSS), and JavaScript.[15] The set of core tools has continued to expand, now including a read–eval–print loop (REPL),[16] package manager,[17] time-travelling debugger,[18] and installers for macOS and Windows.[19] Elm also has an ecosystem of community created libraries,[20] and Ellie, an advanced online editor that allows saved work and including community libraries.[21]
The Elm Architecture is a software design pattern for building interactive web applications. Elm applications are naturally constructed in that way, but other projects may find the concept useful.
An Elm program is always split into three parts:
Those are the core of the Elm Architecture.
For example, imagine an application that displays a number and a button that increments the number when pressed.[31] In this case, all we need to store is one number, so our model can be as simple as type alias Model = Int
. The view
function would be defined with the Html
library and display the number and button. For the number to be updated, we need to be able to send a message to the update
function, which is done through a custom type such as type Msg = Increase
. The Increase
value is attached to the button defined in the view
function such that when the button is clicked by a user, Increase
is passed on to the update
function, which can update the model by increasing the number.
In the Elm Architecture, sending messages to update
is the only way to change the state. In more sophisticated applications, messages may come from various sources: user interaction, initialization of the model, internal calls from update
, subscriptions to external events (window resize, system clock, JavaScript interop...) and URL changes and requests.
Limits[edit]
Elm does not support higher-kinded polymorphism,[32] which related languages Haskell and PureScript offer, nor does Elm support the creation of type classes.
This means that, for example, Elm does not have a generic map
function which works across multiple data structures such as List
and Set
. In Elm, such functions are typically invoked qualified by their module name, for example calling List.map
and Set.map
. In Haskell or PureScript, there would be only one function map
. This is a known feature request that is on Mr. Czaplicki's rough roadmap since at least 2015.[33]
Another outcome is a large amount of boilerplate code in medium to large size projects as illustrated by the author of "Elm in Action" in their single page application example[34] with almost identical fragments being repeated in update, view, subscriptions, route parsing and building functions.