Description #
Elm is a functional language for front-end web development that compiles to JavaScript. It emphasizes simplicity, type safety, and maintainability, making it ideal for building reliable and fast single-page applications (SPAs).
History #
Elm was created by Evan Czaplicki in 2012 as part of his thesis at Harvard. It quickly gained a reputation for producing bug-free web apps, thanks to its no-runtime-errors promise and elegant architecture.
Key milestones:
- Released in 2012 with a focus on functional UI programming
- Introduced the Elm Architecture, which influenced frameworks like Redux
- Rapid growth in the React ecosystem as a model for robust UI state handling
- Now supported by a strong open-source community and used in production by startups and enterprises
Hello World #
module Main exposing (main)
import Browser
import Html exposing (text)
main =
Browser.sandbox { init = (), update = \_ model -> model, view = \_ -> text "Hello, World!" }
How to Run #
Online: #
- Go to https://elm-lang.org/try
- Paste the code and run it directly in the browser
Locally: #
- Install Elm:
npm install -g elm
Create a file named Main.elm
and paste the code
Compile and view in browser:
elm make Main.elm --output=index.html
Open index.html
in your browser
Key Concepts #
Browser.sandbox
— simple structure for front-end Elm appsview
— returns the HTML to displayupdate
— updates the model based on messagesinit
— initial state of the app- No null or undefined — Elm replaces them with types like
Maybe
- Strong static types — errors caught at compile time
- Pure functions — no side effects in functions
- Immutability — all data is immutable by default
- Elm Architecture — update-view-message model
- Friendly compiler — known for readable and helpful error messages
Try It Online #
🔗 Try Elm Online
🔗 Ellie – Online Elm Editor
🔗 Replit – Elm
Fun Facts #
- Elm compiles to JavaScript, but eliminates runtime errors
- The Redux state management library was inspired by Elm
- Elm’s compiler messages are widely praised as the best in the industry
- Many Elm users report dramatically fewer bugs in production
- Elm encourages no side effects, resulting in very stable UIs