World Library  
Flag as Inappropriate
Email this Article

Elm (programming language)

Article Id: WHEBN0037552825
Reproduction Date:

Title: Elm (programming language)  
Author: World Heritage Encyclopedia
Language: English
Subject: ELM, Functional languages, Haskell (programming language), Yesod (web framework), Reactive programming
Collection: Functional Languages, Haskell Programming Language Family, Reactive Programming Languages
Publisher: World Heritage Encyclopedia

Elm (programming language)

Paradigm(s) functional reactive, functional
Designed by Evan Czaplicki
Appeared in 2011
Stable release 0.13 / September 22, 2014 (2014-09-22)
Typing discipline static, strong, inferred
Influenced by Haskell, Standard ML, OCaml, F#
License Permissive (Revised BSD) [1]
Filename extension(s) .elm

Elm is a functional programming language for declaratively creating web browser based graphical user interfaces. Elm uses the Functional Reactive Programming style and purely functional graphical layout to build user interface without any destructive updates.


  • History 1
  • Features 2
    • Signals 2.1
    • Immutability 2.2
    • Static Types 2.3
    • Module System 2.4
    • Interoperability with HTML, CSS, and JavaScript 2.5
  • Tools 3
  • Example Code 4
  • References 5
  • External links 6


Elm was designed by Evan Czaplicki as his thesis in 2012.[2] The first release of Elm came with many examples and an online editor that made it easy to try out in a web browser.[3] Evan Czaplicki now works on Elm at Prezi.[4]

The initial implementation of the Elm compiler targets HTML, CSS, and JavaScript.[5] The set of core tools has continued to expand, now including a REPL,[6] package manager,[7] time-traveling debugger,[8] and installers for Mac and Windows.[9] Elm also has an ecosystem of community created libraries.[10]


Elm has a small but expressive set of language constructs, including if-expressions, let-expressions, case-expressions, anonymous functions, and list interpolation.[11][12] From there the key features include signals, immutability, static types, and interoperability with HTML, CSS, and JavaScript.


The key abstraction in Elm is called a Signal. It is a value that changes over time.[13] For example, the Mouse.position signal in the following code acts on "the current position of the mouse", so the programmer does not need to manually handle an event each time the mouse moves:[14]

import Mouse

main : Signal Element
main =
    lift asText Mouse.position

The Signal library allow users to model change over time without resorting to callbacks and shared mutable memory.[15] This leads to an architecture that centralizes state, making it much harder for parts of your model to get out of sync.[16]


All values in Elm are immutable, meaning that a value cannot be modified after it is created. Elm uses persistent data structures to implement its Array, Dict, and Set libraries.[17]

Static Types

Elm is statically typed. Every definition in Elm can be given a type annotation that describes the exact shape of the value. Types include:

  • primitive types such as integers and strings
  • basic data structures such as lists, tuples, and extensible records
  • custom types called ADTs that let you build entirely new types[18]

Elm also supports full type inference, so the compiler can verify that your program is type-safe without any type annotations.

Module System

Elm has a module system that allows users to break their code into smaller parts called modules. Users can import and export values, making it possible to hide implementation details that other programmers do not need to think about. Modules form the basis of Elm's community library website, the Elm Public Library.

Interoperability with HTML, CSS, and JavaScript

Elm uses an abstraction called ports to communicate with JavaScript.[19] It allows values to flow in and out of Elm programs, making it possible to communicate between Elm and JavaScript.

Elm also has a library called elm-html which lets you use HTML within Elm and allows you to style it with CSS.[20] It uses a Virtual DOM approach to make updates efficient.[21]


  • Online editor at for easy experimentation
  • Elm Platform for installing the core tools locally
  • Time-Traveling Debugger
  • Learning resources and examples
  • Core Libraries and Community Libraries

Example Code

-- This is a single line comment
{- This is a multi-line comment.
   It can span multiple lines.
{- It is possible to {- nest -} multi-line comments -}

-- Here we define a value named `greeting`. The type will be inferred as a String.
greeting = "Hello World!"

 -- It is best to add type annotations to top-level declarations.
hello : String
hello = "Hi there."

-- Functions are declared the same way, with arguments following the function name.
add x y = x + y

-- Again, it is best to add type annotations.
hypotenuse : Float -> Float -> Float
hypotenuse a b =
    sqrt (a^2 + b^2)

-- If-expressions are used to branch on values
absoluteValue : Int -> Int
absoluteValue number =
    if number < 0 then -number else number

 -- Records are used to hold values with named fields
book : { title:String, author:String, pages:Int }
book =
    { title = "Steppenwolf"
    , author = "Hesse"
    , pages = 237 

-- We can create entirely new types with the `data` keyword.
-- The following value represents a binary tree.
data Tree a
    = Empty
    | Node a (Tree a) (Tree a)

-- It is possible to inspect these types with case-expressions.
depth : Tree a -> Int
depth tree =
    case tree of
        Empty -> 0
        Node value left right ->
            1 + max (depth left) (depth right)


  1. ^
  2. ^ Evan Czaplicki's thesis on Elm
  3. ^ Elm's Online Editor
  4. ^ Elm joins Prezi
  5. ^ Elm compiler source code
  6. ^ Elm REPL announcement
  7. ^ Elm Package Manager announcement
  8. ^ Elm's Time-Traveling Debugger
  9. ^ Elm Platform
  10. ^ Elm Public Libraries
  11. ^ The Syntax of Elm
  12. ^ About Elm Elm features
  13. ^ Elm - What is FRP?
  14. ^ Mouse Position
  15. ^ Signal library
  16. ^ Architecture in Elm
  17. ^ Elm Standard Libraries
  18. ^ Elm - Getting started with Types
  19. ^ Ports
  20. ^ elm-html documentation
  21. ^ Blazing Fast Html

External links

  • Elm official website
This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.

Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.