Elixir (programming language)
Appearance
Text
Small
Standard
Large
Width
Standard
Wide
Color (beta)
Automatic
Light
Dark
From Wikipedia, the free encyclopedia
This article relies excessively on references (Abre numa nova janela) to primary sources (Abre numa nova janela). Please improve this article by adding secondary or tertiary sources (Abre numa nova janela).
Find sources: "Elixir" programming language (Abre numa nova janela) – news (Abre numa nova janela) · newspapers (Abre numa nova janela) · books (Abre numa nova janela) · scholar (Abre numa nova janela) · JSTOR (Abre numa nova janela) (June 2023) (Learn how and when to remove this message (Abre numa nova janela))
Elixir
(Abre numa nova janela)Elixir
Paradigms (Abre numa nova janela)multi-paradigm (Abre numa nova janela): functional (Abre numa nova janela), concurrent (Abre numa nova janela), distributed (Abre numa nova janela), process-oriented (Abre numa nova janela)Designed by (Abre numa nova janela)José ValimFirst appeared2012; 13 years agoStable release (Abre numa nova janela)
1.18.4[1] (Abre numa nova janela)
/ 21 May 2025; 4 days ago
Typing disciplinedynamic (Abre numa nova janela), strong (Abre numa nova janela)Platform (Abre numa nova janela)Erlang (Abre numa nova janela)License (Abre numa nova janela)Apache License 2.0 (Abre numa nova janela)[2] (Abre numa nova janela)Filename extensions (Abre numa nova janela).ex, .exsWebsiteelixir-lang.org (Abre numa nova janela)Influenced byClojure (Abre numa nova janela), Erlang (Abre numa nova janela), Ruby (Abre numa nova janela)InfluencedGleam (Abre numa nova janela), LFE (Abre numa nova janela)
Elixir is a functional (Abre numa nova janela), concurrent (Abre numa nova janela), high-level (Abre numa nova janela) general-purpose (Abre numa nova janela) programming language (Abre numa nova janela) that runs on the BEAM (Abre numa nova janela) virtual machine (Abre numa nova janela), which is also used to implement the Erlang (Abre numa nova janela) programming language.[3] (Abre numa nova janela) Elixir builds on top of Erlang and shares the same abstractions for building distributed (Abre numa nova janela), fault-tolerant (Abre numa nova janela) applications. Elixir also provides tooling and an extensible (Abre numa nova janela) design. The latter is supported by compile-time metaprogramming (Abre numa nova janela) with macros (Abre numa nova janela) and polymorphism (Abre numa nova janela) via protocols.[4] (Abre numa nova janela)
The community organizes yearly events in the United States,[5] (Abre numa nova janela) Europe,[6] (Abre numa nova janela) and Japan,[7] (Abre numa nova janela) as well as minor local events and conferences.[8] (Abre numa nova janela)[9] (Abre numa nova janela)
History
José Valim created the Elixir programming language as a research and development (Abre numa nova janela) project at Plataformatec. His goals were to enable higher extensibility and productivity in the Erlang VM while maintaining compatibility with Erlang's ecosystem.[10] (Abre numa nova janela)[11] (Abre numa nova janela)
Elixir is aimed at large-scale sites and apps. It uses features of Ruby (Abre numa nova janela), Erlang, and Clojure (Abre numa nova janela) to develop a high-concurrency and low-latency language. It was designed to handle large data volumes. Elixir is also used in telecommunications, e-commerce, and finance.[12] (Abre numa nova janela)
In 2021, the Numerical Elixir effort was announced with the goal of bringing machine learning, neural networks, GPU compilation, data processing, and computational notebooks to the Elixir ecosystem.[13] (Abre numa nova janela)
Versioning
Each of the minor versions supports a specific range of Erlang/OTP (Abre numa nova janela) versions.[14] (Abre numa nova janela) The current stable release version is 1.18.4[1] (Abre numa nova janela) .
Features
Compiles (Abre numa nova janela) to bytecode (Abre numa nova janela) for the BEAM virtual machine (Abre numa nova janela) of Erlang (Abre numa nova janela).[15] (Abre numa nova janela) Full interoperability with Erlang code, without runtime (Abre numa nova janela) impact.
Scalability and fault-tolerance, thanks to Erlang's lightweight concurrency mechanisms[15] (Abre numa nova janela)
Built-in tooling (Abre numa nova janela) for managing dependencies, code compilation, running tests, formatting code, remote debugging and more.
An interactive REPL (Abre numa nova janela) inside running programs, including Phoenix (Abre numa nova janela) web servers, with code reloading and access to internal state
Everything is an expression (Abre numa nova janela)[15] (Abre numa nova janela)
Pattern matching (Abre numa nova janela)[15] (Abre numa nova janela) to promote assertive code[16] (Abre numa nova janela)
Type hints for static analysis tools
Immutable data, with an emphasis, like other functional (Abre numa nova janela) languages, on recursion (Abre numa nova janela) and higher-order functions (Abre numa nova janela) instead of side-effect (Abre numa nova janela)-based looping (Abre numa nova janela)
Shared nothing concurrent programming (Abre numa nova janela) via message passing (actor model (Abre numa nova janela))[17] (Abre numa nova janela)
Lazy (Abre numa nova janela) and async collections (Abre numa nova janela) with streams
Railway oriented programming via the
withconstruct[18] (Abre numa nova janela)Hygienic metaprogramming (Abre numa nova janela) by direct access to the abstract syntax tree (Abre numa nova janela) (AST).[15] (Abre numa nova janela) Libraries often implement small domain-specific languages (Abre numa nova janela), such as for databases or testing.
Code execution at compile time. The Elixir compiler also runs on the BEAM, so modules that are being compiled can immediately run code which has already been compiled.
Polymorphism (Abre numa nova janela) via a mechanism called protocols. Dynamic dispatch (Abre numa nova janela), as in Clojure (Abre numa nova janela), however, without multiple dispatch (Abre numa nova janela) because Elixir protocols dispatch on a single type.
Support for documentation via Python-like docstrings in the Markdown (Abre numa nova janela) formatting language[15] (Abre numa nova janela)
Unicode (Abre numa nova janela) support and UTF-8 (Abre numa nova janela) strings
Examples
The following examples can be run in an iex shell (Abre numa nova janela) or saved in a file and run from the command line (Abre numa nova janela) by typing elixir <filename>.
Classic Hello world (Abre numa nova janela) example:
iex> IO.puts("Hello World!")
Hello World!
Pipe operator:
iex> "Elixir" |> String.graphemes() |> Enum.frequencies()
%{"E" => 1, "i" => 2, "l" => 1, "r" => 1, "x" => 1}
iex> %{values: 1..5} |> Map.get(:values) |> Enum.map(& &1 * 2)
[2, 4, 6, 8, 10]
iex> %{values: 1..5} |> Map.get(:values) |> Enum.map(& &1 * 2) |> Enum.sum()
30
Pattern matching (Abre numa nova janela) (a.k.a. destructuring):
iex> %{left: x} = %{left: 5, right: 8}
iex> x
5
iex> {:ok, [_ | rest]} = {:ok, [1, 2, 3]}
iex> rest
[2, 3]
Pattern matching with multiple clauses:
iex> case File.read("path/to/file") do
iex> {:ok, contents} -> IO.puts("found file: #{contents}")
iex> {:error, reason} -> IO.puts("missing file: #{reason}")
iex> end
List comprehension (Abre numa nova janela):
iex> for n <- 1..5, rem(n, 2) == 1, do: n*n
[1, 9, 25]
Asynchronously reading files with streams:
1..5
|> Task.async_stream(&File.read!("#{&1}.txt"))
|> Stream.filter(fn {:ok, contents} -> String.trim(contents) != "" end)
|> Enum.join("\n")
Multiple function bodies with guards (Abre numa nova janela):
def fib(n) when n in [0, 1], do: n
def fib(n), do: fib(n-2) + fib(n-1)
Relational databases with the Ecto library:
schema "weather" do
field :city # Defaults to type :string
field :temp_lo, :integer
field :temp_hi, :integer
field :prcp, :float, default: 0.0
end
Weather |> where(city: "Kraków") |> order_by(:temp_lo) |> limit(10) |> Repo.all
Sequentially spawning a thousand processes:
for num <- 1..1000, do: spawn fn -> IO.puts("#{num * 2}") end
Asynchronously (Abre numa nova janela) performing a task:
task = Task.async fn -> perform_complex_action() end
other_time_consuming_action()
Task.await task
[citation needed (Abre numa nova janela)]
See also
References
"Release 1.18.4" (Abre numa nova janela). 21 May 2025. Retrieved 25 May 2025.
"elixir/LICENSE at master · elixir-lang/elixir · GitHub" (Abre numa nova janela). GitHub.
"Most Popular Programming Languages of 2018 - Elite Infoworld Blog" (Abre numa nova janela). 2018-03-30. Archived from the original (Abre numa nova janela) on 2018-05-09. Retrieved 2018-05-08.
"Elixir" (Abre numa nova janela). José Valim. Retrieved 2013-02-17.
"ElixirConf" (Abre numa nova janela). Retrieved 2018-07-11.
"ElixirConf" (Abre numa nova janela). Retrieved 2018-07-11.
"Erlang & Elixir Fest" (Abre numa nova janela). Retrieved 2019-02-18.
"Elixir LDN" (Abre numa nova janela). Retrieved 2018-07-12.
"EMPEX - Empire State Elixir Conference" (Abre numa nova janela). Retrieved 2018-07-12.
Elixir - A modern approach to programming for the Erlang VM (Abre numa nova janela). Retrieved 2013-02-17.
José Valim - ElixirConf EU 2017 Keynote (Abre numa nova janela). Archived (Abre numa nova janela) from the original on 2021-11-17. Retrieved 2017-07-14.
"Behinde the code: The One Who Created Elixir" (Abre numa nova janela). Retrieved 2019-11-25.
"Numerical Elixir (Nx)" (Abre numa nova janela). GitHub (Abre numa nova janela). Retrieved 2024-05-06.
Elixir is a dynamic, functional language designed for building scalable and maintainable applications: elixir-lang/elixir (Abre numa nova janela), Elixir, 2019-04-21, retrieved 2019-04-21
"Elixir" (Abre numa nova janela). Retrieved 2014-09-07.
"Writing assertive code with Elixir" (Abre numa nova janela). 24 September 2014. Retrieved 2018-07-05.
Loder, Wolfgang (12 May 2015). Erlang and Elixir for Imperative Programmers (Abre numa nova janela). "Chapter 16: Code Structuring Concepts", section title "Actor Model": Leanpub. Retrieved 7 July 2015.
Wlaschin, Scott (May 2013). "Railway Oriented Programming" (Abre numa nova janela). F# for Fun and Profit. Archived (Abre numa nova janela) from the original on 30 January 2021. Retrieved 28 February 2021.
Further reading
Simon St. Laurent; J. Eisenberg (December 22, 2016). Introducing Elixir: Getting Started in Functional Programming 2nd Edition. O'Reilly Media (Abre numa nova janela). ISBN (Abre numa nova janela) 978-1491956779 (Abre numa nova janela).
Sasa Juric (January 12, 2019). Elixir in Action 2nd Edition. Manning Publications (Abre numa nova janela). ISBN (Abre numa nova janela) 978-1617295027 (Abre numa nova janela).
Programming languages (Abre numa nova janela)
Authority control databases (Abre numa nova janela): National
Categories (Abre numa nova janela):
Pattern matching programming languages (Abre numa nova janela)
Programming languages created in 2012 (Abre numa nova janela)
Elm (programming language)
Tools
Appearance
Text
Small
Standard
Large
Width
Standard
Wide
Color (beta)
Automatic
Light
Dark
From Wikipedia, the free encyclopedia
This article relies excessively on references (Abre numa nova janela) to primary sources (Abre numa nova janela). Please improve this article by adding secondary or tertiary sources (Abre numa nova janela).
Find sources: "Elm" programming language (Abre numa nova janela) – news (Abre numa nova janela) · newspapers (Abre numa nova janela) · books (Abre numa nova janela) · scholar (Abre numa nova janela) · JSTOR (Abre numa nova janela) (May 2019) (Learn how and when to remove this message (Abre numa nova janela))
Elm
The Elm tangram
Paradigm (Abre numa nova janela)functional (Abre numa nova janela)FamilyHaskell (Abre numa nova janela)Designed by (Abre numa nova janela)Evan CzaplickiFirst appearedMarch 30, 2012; 13 years ago[1] (Abre numa nova janela)Stable release (Abre numa nova janela)
0.19.1 / October 21, 2019; 5 years ago[2] (Abre numa nova janela)
Typing discipline (Abre numa nova janela)static (Abre numa nova janela), strong (Abre numa nova janela), inferred (Abre numa nova janela)Platform (Abre numa nova janela)x86-64 (Abre numa nova janela)OS (Abre numa nova janela)macOS (Abre numa nova janela), Windows (Abre numa nova janela)License (Abre numa nova janela)Permissive (Abre numa nova janela) (Revised BSD (Abre numa nova janela))[3] (Abre numa nova janela)Filename extensions (Abre numa nova janela).elmWebsiteelm-lang.org (Abre numa nova janela)
Influenced byHaskell (Abre numa nova janela), Standard ML (Abre numa nova janela), OCaml (Abre numa nova janela), F# (Abre numa nova janela)InfluencedRedux (Abre numa nova janela),[4] (Abre numa nova janela) Rust (Abre numa nova janela),[5] (Abre numa nova janela) Vue (Abre numa nova janela),[6] (Abre numa nova janela) Roc,[7] (Abre numa nova janela) Derw,[8] (Abre numa nova janela) Gren[9] (Abre numa nova janela)
Elm is a domain-specific (Abre numa nova janela) programming language (Abre numa nova janela) for declaratively (Abre numa nova janela) creating web browser (Abre numa nova janela)-based graphical user interfaces (Abre numa nova janela). Elm is purely functional (Abre numa nova janela), and is developed with emphasis on usability (Abre numa nova janela), performance, and robustness (Abre numa nova janela). It advertises "no runtime (Abre numa nova janela) exceptions (Abre numa nova janela) in practice",[10] (Abre numa nova janela) made possible by the Elm compiler's static type checking (Abre numa nova janela).
History
Elm was initially designed by Evan Czaplicki as his thesis in 2012.[11] (Abre numa nova janela) The first release of Elm came with many examples and an online editor that made it easy to try out in a web browser (Abre numa nova janela).[12] (Abre numa nova janela) Czaplicki joined Prezi (Abre numa nova janela) in 2013 to work on Elm,[13] (Abre numa nova janela) and in 2016 moved to NoRedInk (Abre numa nova janela) as an Open Source Engineer, also starting the Elm Software Foundation.[14] (Abre numa nova janela)
The initial implementation of the Elm compiler targets HyperText Markup Language (HTML (Abre numa nova janela)), Cascading Style Sheets (Abre numa nova janela) (CSS), and JavaScript (Abre numa nova janela).[15] (Abre numa nova janela) The set of core tools has continued to expand, now including a read–eval–print loop (Abre numa nova janela) (REPL),[16] (Abre numa nova janela) package manager (Abre numa nova janela),[17] (Abre numa nova janela) time-travelling debugger,[18] (Abre numa nova janela) and installers for macOS (Abre numa nova janela) and Windows (Abre numa nova janela).[19] (Abre numa nova janela) Elm also has an ecosystem of community created libraries (Abre numa nova janela),[20] (Abre numa nova janela) and Ellie, an advanced online editor that allows saved work and including community libraries.[21] (Abre numa nova janela)
Features
Elm has a small set of language constructs, including traditional if-expressions, let-expressions for storing local values, and case-expressions for pattern matching (Abre numa nova janela).[22] (Abre numa nova janela) As a functional language, it supports anonymous functions (Abre numa nova janela), functions as arguments, and functions can return functions, the latter often by partial application of curried (Abre numa nova janela) functions. Functions are called by value. Its semantics include immutable values, stateless functions (Abre numa nova janela), and static typing with type inference. Elm programs render HTML through a virtual DOM, and may interoperate with other code by using "JavaScript as a service".
Immutability
All values in Elm are immutable (Abre numa nova janela), meaning that a value cannot be modified after it is created. Elm uses persistent data structures (Abre numa nova janela) to implement its arrays, sets, and dictionaries in the standard library.[23] (Abre numa nova janela)
Static types
Elm is statically typed. Type annotations are optional (due to type inference) but strongly encouraged. Annotations exist on the line above the definition (unlike C-family languages where types and names are interspersed). Elm uses a single colon to mean "has type".
Types include primitives like integers and strings, and basic data structures such as lists, tuples, and records. Functions have types written with arrows, for example round : Float -> Int. Custom types (Abre numa nova janela) allow the programmer to create custom types to represent data in a way that matches the problem domain.[24] (Abre numa nova janela)
Types can refer to other types, for example a List Int. Types are always capitalized; lowercase names are type variables. For example, a List a is a list of values of unknown type. It is the type of the empty list and of the argument to List.length, which is agnostic to the list's elements. There are a few special types that programmers create to interact with the Elm runtime. For example, Html Msg represents a (virtual) DOM tree whose event handlers all produce messages of type Msg.
Rather than allow any value to be implicitly nullable (such as JavaScript's undefined or a null pointer (Abre numa nova janela)), Elm's standard library defines a Maybe a type. Code that produces or handles an optional value does so explicitly using this type, and all other code is guaranteed a value of the claimed type is actually present.
Elm provides a limited number of built-in type classes (Abre numa nova janela): number which includes Int and Float to facilitate the use of numeric operators such as (+) or (*), comparable which includes numbers, characters, strings, lists of comparable things, and tuples of comparable things to facilitate the use of comparison operators, and appendable which includes strings and lists to facilitate concatenation with (++). Elm does not provide a mechanism to include custom types into these type classes or create new type classes (see Limits (Abre numa nova janela)).
Module system
Elm has a module system (Abre numa nova janela) that allows users to break their code into smaller parts called modules. Modules can hide implementation details such as helper functions, and group related code together. Modules serve as a namespace for imported code, such as Bitwise.and. Third party libraries (or packages) consist of one or more modules, and are available from the Elm Public Library (Abre numa nova janela). All libraries are versioned according to semver (Abre numa nova janela), which is enforced by the compiler and other tools. That is, removing a function or changing its type can only be done in a major release.
Interoperability with HTML, CSS, and JavaScript
Elm uses an abstraction called ports to communicate with JavaScript (Abre numa nova janela).[25] (Abre numa nova janela) It allows values to flow in and out of Elm programs, making it possible to communicate between Elm and JavaScript.
Elm has a library called elm/html that a programmer can use to write HTML and CSS within Elm.[26] (Abre numa nova janela) It uses a virtual DOM (Abre numa nova janela) approach to make updates efficient.[27] (Abre numa nova janela)
Backend
Elm does not officially support server-side development. Czaplicki does consider it a primary goal at this point, but public progress on this front has been slow. Nevertheless, there are several independent projects which attempt to explore Elm on the backend.
The primary production-ready full-stack Elm platform is Lamdera, an open-core "unfork" of Elm.[28] (Abre numa nova janela)[29] (Abre numa nova janela)[30] (Abre numa nova janela) Czaplicki has also teased Elm Studio, a potential alternative to Lamdera, but it isn't available to the public yet.[31] (Abre numa nova janela) Current speculation is that Elm Studio will use a future version of Elm that targets C, uses Emscripten to compile to WASM, and supports type-safe Postgres (Abre numa nova janela) table generation.[32] (Abre numa nova janela)[33] (Abre numa nova janela)
For full-stack frameworks, as opposed to BaaS (Abre numa nova janela) products, elm-pages is perhaps the most popular fully open-source option.[34] (Abre numa nova janela) It does not extend the Elm language, but just runs the compiled JS on Node.js (Abre numa nova janela). It also supports scripting. There is also Pine, an Elm to .NET compiler, which allows safe interop with C#, F#, and other CLR (Abre numa nova janela) languages.[35] (Abre numa nova janela)
There were also some attempts in Elm versions prior to 0.19.0 to use the BEAM (Erlang virtual machine) (Abre numa nova janela) to run Elm, but they are stuck due to the removal of native code in 0.19.0 and changes to the package manager. One of the projects executed Elm directly on the environment,[36] (Abre numa nova janela) while another one compiled it to Elixir.[37] (Abre numa nova janela)
Finally, the Gren programming language started out a fork of Elm primarily focused on backend support, although its goals have since shifted.
The Elm Architecture (TEA pattern)
The Elm Architecture is a software design pattern (Abre numa nova janela) and as a TLA (Abre numa nova janela) called TEA 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:
Model - the state of the application
View - a function that turns the model into HTML
Update - a function that updates the model based on messages
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.[38] (Abre numa nova janela) 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
Elm does not support higher-kinded polymorphism (Abre numa nova janela),[39] (Abre numa nova janela) which related languages Haskell (Abre numa nova janela), Scala (Abre numa nova janela) and PureScript (Abre numa nova janela) offer, nor does Elm support the creation of type classes (Abre numa nova janela).
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 Czaplicki's rough roadmap since at least 2015.[40] (Abre numa nova janela) On the other hand, implementations of TEA pattern in advanced languages like Scala (Abre numa nova janela) does not suffer from such limitations and can benefit from Scala (Abre numa nova janela)'s type classes, type-level (Abre numa nova janela) and kind-level (Abre numa nova janela) programming constructs.[41] (Abre numa nova janela)
Another outcome is a large amount of boilerplate code (Abre numa nova janela) in medium to large size projects as illustrated by the author of "Elm in Action," a former Elm core team member, in his single page application example[42] (Abre numa nova janela) with almost identical fragments being repeated in update, view, subscriptions, route parsing and building functions.
Example code
-- This is a single line comment.
{-
This is a multi-line comment.
It is {- nestable. -}
-}
-- Here we define a value named `greeting`. The type is 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)
-- We can create lambda functions with the `\[arg] -> [expression]` syntax.
hello : String -> String
hello = \s -> "Hi, " ++ s
-- Function declarations may have the anonymous parameter names denoted by `_`,
-- which are matched but not used in the body.
const : a -> b -> a
const k _ = k
-- Functions are also curried; here we've curried the multiplication
-- infix operator with a `2`
multiplyBy2 : number -> number
multiplyBy2 =
(*) 2
-- If-expressions are used to branch on `Bool` values
absoluteValue : number -> number
absoluteValue number =
if number < 0 then negate 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
}
-- Record access is done with `.`
title : String
title =
book.title
-- Record access `.` can also be used as a function
author : String
author =
.author book
-- We can create tagged unions with the `type` keyword.
-- The following value represents a binary tree.
type 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 _ left right ->
1 + max (depth left) (depth right)
See also
PureScript (Abre numa nova janela) – A strongly-typed, purely-functional programming language that compiles to JavaScript
Reason (Abre numa nova janela) – A syntax extension and toolchain for OCaml that can also transpile to JavaScript
References
Czaplicki, Evan (30 March 2012). "My Thesis is Finally Complete! "Elm: Concurrent FRP for functional GUIs"" (Abre numa nova janela). Reddit (Abre numa nova janela).
"Releases: elm/Compiler" (Abre numa nova janela). GitHub (Abre numa nova janela).
"elm/compiler" (Abre numa nova janela). GitHub. 16 October 2021.
"Prior Art - Redux" (Abre numa nova janela). redux.js.org. 28 April 2024.
"Uniqueness Types" (Abre numa nova janela). Rust Blog. Retrieved 2016-10-08. Those of you familiar with the Elm style may recognize that the updated --explain messages draw heavy inspiration from the Elm approach.
"Comparison with Other Frameworks — Vue.js" (Abre numa nova janela).
"roc/roc-for-elm-programmers.md at main · roc-lang/roc" (Abre numa nova janela). GitHub (Abre numa nova janela). Retrieved 2024-02-17. Roc is a direct descendant of the Elm programming language. The two languages are similar, but not the same!
"Why Derw: an Elm-like language that compiles to TypeScript?" (Abre numa nova janela). 20 December 2021.
"Elm: Concurrent FRP for Functional GUIs" (Abre numa nova janela) (PDF).
"Try Elm" (Abre numa nova janela). elm-lang.org. Retrieved 2025-04-26.
"elm and prezi" (Abre numa nova janela). elm-lang.org.
"new adventures for elm" (Abre numa nova janela). elm-lang.org.
"elm/compiler" (Abre numa nova janela). GitHub. 16 October 2021.
"repl" (Abre numa nova janela). elm-lang.org.
"package manager" (Abre numa nova janela). elm-lang.org.
"Home" (Abre numa nova janela). elm-lang.org.
"Install" (Abre numa nova janela). guide.elm-lang.org.
"Elm packages" (Abre numa nova janela). Elm-lang.org.
"Ellie" (Abre numa nova janela). Ellie-app.com.
"syntax" (Abre numa nova janela). elm-lang.org. Retrieved 2025-04-26.
"elm/core" (Abre numa nova janela). package.elm-lang.org.
"Model The Problem" (Abre numa nova janela). Elm. Retrieved 4 May 2016.
"JavaScript interop" (Abre numa nova janela). elm-lang.org.
"elm/html" (Abre numa nova janela). package.elm-lang.org.
"Blazing Fast HTML" (Abre numa nova janela). elm-lang.org.
Elm Europe (2019-11-28). Mario Rogic - Elm as a Service (Abre numa nova janela). Retrieved 2025-03-27 – via YouTube.
Elm Online Meetup (2021-07-23). Building a Meetup clone on Lamdera - Martin Stewart (Abre numa nova janela). Retrieved 2025-03-27 – via YouTube.
"Episode 38: Lamdera" (Abre numa nova janela). Elm Radio Podcast. Retrieved 2025-03-27.
"Elm Studio" (Abre numa nova janela). www.elm.studio. Retrieved 2025-03-27.
"Status Update - 3 Nov 2021" (Abre numa nova janela). Elm. 2021-11-03. Retrieved 2025-03-27.
Cesarini, Francesco (22 May 2023). "@evancz tempting the demo gods…" (Abre numa nova janela). Twitter (Abre numa nova janela). Retrieved 26 March 2025.
"elm-pages - pull in typed elm data to your pages" (Abre numa nova janela). elm-pages. Retrieved 2025-03-27.
"Pine — Run Elm Everywhere" (Abre numa nova janela). pine-vm.org. Retrieved 2025-03-27.
"Kofigumbs/Elm-beam" (Abre numa nova janela). GitHub (Abre numa nova janela). 24 September 2021.
"What is it?" (Abre numa nova janela). GitHub (Abre numa nova janela). 24 September 2021.
"Buttons · An Introduction to Elm" (Abre numa nova janela). guide.elm-lang.org. Retrieved 2020-10-15.
"Higher-Kinded types Not Expressible? #396" (Abre numa nova janela). github.com/elm-lang/elm-compiler. Retrieved 6 March 2015.
"Higher-Kinded types Not Expressible #396" (Abre numa nova janela). github.com/elm-lang/elm-compiler. Retrieved 19 November 2019.
"The Elm Architecture" (Abre numa nova janela). tyrian.indigoengine.io. Retrieved 2024-09-07.
"Main.elm" (Abre numa nova janela). github.com/rtfeldman/elm-spa-example. Retrieved 30 June 2020.
External links
Haskell (Abre numa nova janela) programming
Programming languages (Abre numa nova janela)
Categories (Abre numa nova janela):
Domain-specific programming languages (Abre numa nova janela)
Pattern matching programming languages (Abre numa nova janela)
Programming languages created in 2012 (Abre numa nova janela)
Statically typed programming languages (Abre numa nova janela)
Gleam (programming language)
Tools
Text
Small
Standard
Large
Width
Standard
Wide
Color (beta)
Automatic
Light
Dark
From Wikipedia, the free encyclopedia
The topic of this article may not meet Wikipedia's general notability guideline (Abre numa nova janela). Please help to demonstrate the notability of the topic by citing reliable secondary sources (Abre numa nova janela) that are independent (Abre numa nova janela) of the topic and provide significant coverage of it beyond a mere trivial mention. If notability cannot be shown, the article is likely to be merged (Abre numa nova janela), redirected (Abre numa nova janela), or deleted (Abre numa nova janela).
Find sources: "Gleam" programming language (Abre numa nova janela) – news (Abre numa nova janela) · newspapers (Abre numa nova janela) · books (Abre numa nova janela) · scholar (Abre numa nova janela) · JSTOR (Abre numa nova janela) (March 2024) (Learn how and when to remove this message (Abre numa nova janela))
Gleam
Lucy, the starfish mascot for Gleam[1] (Abre numa nova janela)
Paradigm (Abre numa nova janela)Multi-paradigm (Abre numa nova janela): functional (Abre numa nova janela), concurrent (Abre numa nova janela)[2] (Abre numa nova janela)Designed by (Abre numa nova janela)Louis PilfoldDeveloper (Abre numa nova janela)Louis PilfoldFirst appearedJune 13, 2016; 8 years agoStable release (Abre numa nova janela)
1.10.0[3] (Abre numa nova janela)
/ 14 April 2025
Typing discipline (Abre numa nova janela)Type-safe (Abre numa nova janela), static (Abre numa nova janela), inferred (Abre numa nova janela)[2] (Abre numa nova janela)Memory management (Abre numa nova janela)Garbage collected (Abre numa nova janela)Implementation languageRust (Abre numa nova janela)OS (Abre numa nova janela)FreeBSD (Abre numa nova janela), Linux (Abre numa nova janela), macOS (Abre numa nova janela), OpenBSD (Abre numa nova janela), Windows (Abre numa nova janela)[4] (Abre numa nova janela)License (Abre numa nova janela)Apache License 2.0 (Abre numa nova janela)[5] (Abre numa nova janela)Filename extensions (Abre numa nova janela).gleamWebsitegleam.run (Abre numa nova janela)Influenced by
Alpaca
Gleam is a general-purpose (Abre numa nova janela), concurrent (Abre numa nova janela), functional (Abre numa nova janela) high-level (Abre numa nova janela) programming language (Abre numa nova janela) that compiles to Erlang (Abre numa nova janela) or JavaScript (Abre numa nova janela) source code.[2] (Abre numa nova janela)[7] (Abre numa nova janela)[8] (Abre numa nova janela)
Gleam is a statically-typed language,[9] (Abre numa nova janela) which is different from the most popular languages that run on Erlang’s virtual machine BEAM (Abre numa nova janela), Erlang (Abre numa nova janela) and Elixir (Abre numa nova janela). Gleam has its own type-safe implementation of OTP, Erlang's actor framework.[10] (Abre numa nova janela) Packages are provided using the Hex package manager, and an index for finding packages written for Gleam is available.[11] (Abre numa nova janela)
History
The first numbered version of Gleam was released on April 15, 2019.[12] (Abre numa nova janela) Compiling to JavaScript was introduced with version v0.16.[13] (Abre numa nova janela)
In 2023 the Erlang Ecosystem Foundation funded the creation of a course for learning Gleam on the learning platform Exercism (Abre numa nova janela).[14] (Abre numa nova janela)
Version v1.0.0 was released on March 4, 2024.[15] (Abre numa nova janela)
Features
Gleam includes the following features, many common to other functional programming languages:[8] (Abre numa nova janela)
Result type (Abre numa nova janela) for error handling
Example
A "Hello, World!" (Abre numa nova janela) example:
import gleam/io
pub fn main() {
io.println("hello, world!")
}Gleam supports tail call (Abre numa nova janela) optimization:[16] (Abre numa nova janela)
pub fn factorial(x: Int) -> Int {
// The public function calls the private tail recursive function
factorial_loop(x, 1)
}
fn factorial_loop(x: Int, accumulator: Int) -> Int {
case x {
1 -> accumulator
// The last thing this function does is call itself
_ -> factorial_loop(x - 1, accumulator * x)
}
}Implementation
Gleam's toolchain is implemented in the Rust programming language (Abre numa nova janela).[17] (Abre numa nova janela) The toolchain is a single native binary executable which contains the compiler, build tool, package manager, source code formatter, and language server (Abre numa nova janela). A WebAssembly (Abre numa nova janela) binary containing the Gleam compiler is also available, enabling Gleam code to be compiled within a web browser.
References
"gleam-lang/gleam Issues – New logo and mascot #2551" (Abre numa nova janela). GitHub (Abre numa nova janela).
"Release 1.10.0" (Abre numa nova janela). April 14, 2025. Retrieved April 15, 2025.
"Gleam License File" (Abre numa nova janela). GitHub (Abre numa nova janela). December 5, 2021.
Pilfold, Louis (February 7, 2024). "Gleam: Past, Present, Future!" (Abre numa nova janela). Fosdem 2024 – via YouTube.
Krill, Paul (March 5, 2024). "Gleam language available in first stable release" (Abre numa nova janela). InfoWorld. Retrieved March 26, 2024.
Eastman, David (June 22, 2024). "Introduction to Gleam, a New Functional Programming Language" (Abre numa nova janela). The New Stack. Retrieved July 29, 2024.
De Simone, Sergio (March 16, 2024). "Erlang-Runtime Statically-Typed Functional Language Gleam Reaches 1.0" (Abre numa nova janela). InfoQ. Retrieved March 26, 2024.
Getting to know Actors in Gleam – Raúl Chouza (Abre numa nova janela). Code BEAM America. March 27, 2024. Retrieved May 6, 2024 – via YouTube.
"Introducing the Gleam package index – Gleam" (Abre numa nova janela). gleam.run (Abre numa nova janela). Retrieved May 7, 2024.
"Hello, Gleam! – Gleam" (Abre numa nova janela). gleam.run (Abre numa nova janela). Retrieved May 6, 2024.
"v0.16 – Gleam compiles to JavaScript! – Gleam" (Abre numa nova janela). gleam.run (Abre numa nova janela). Retrieved May 7, 2024.
Alistair, Woodman (December 2023). "Erlang Ecosystem Foundation Annual General Meeting 2023 Chair's Report" (Abre numa nova janela).
"Gleam version 1 – Gleam" (Abre numa nova janela). gleam.run (Abre numa nova janela). Retrieved May 7, 2024.
"Tail Calls" (Abre numa nova janela). The Gleam Language Tour. Retrieved March 26, 2024.
"gleam-lang/gleam" (Abre numa nova janela). Gleam. May 6, 2024. Retrieved May 6, 2024.
External links
This programming-language (Abre numa nova janela)-related article is a stub (Abre numa nova janela). You can help Wikipedia by expanding it (Abre numa nova janela).
Categories (Abre numa nova janela):
Multi-paradigm programming languages (Abre numa nova janela)
Pattern matching programming languages (Abre numa nova janela)
Programming languages created in 2016 (Abre numa nova janela)
Statically typed programming languages (Abre numa nova janela)
Erlang (programming language)
Tools
Text
Small
Standard
Large
Width
Standard
Wide
Color (beta)
Automatic
Light
Dark
From Wikipedia, the free encyclopedia
Erlang
Paradigms (Abre numa nova janela)Multi-paradigm (Abre numa nova janela): concurrent (Abre numa nova janela), functional (Abre numa nova janela)Designed by (Abre numa nova janela)
Robert Virding
Mike Williams
Developer (Abre numa nova janela)Ericsson (Abre numa nova janela)First appeared1986; 39 years agoStable release (Abre numa nova janela)
27.3.4[1] (Abre numa nova janela)
/ 8 May 2025; 9 days ago
Typing disciplineDynamic (Abre numa nova janela), strong (Abre numa nova janela)License (Abre numa nova janela)Apache License 2.0 (Abre numa nova janela)Filename extensions (Abre numa nova janela).erl, .hrlWebsitewww.erlang.org (Abre numa nova janela)Major implementations (Abre numa nova janela)ErlangInfluenced byLisp (Abre numa nova janela), PLEX (Abre numa nova janela),[2] (Abre numa nova janela) Prolog (Abre numa nova janela), Smalltalk (Abre numa nova janela)InfluencedAkka (Abre numa nova janela), Clojure (Abre numa nova janela),[3] (Abre numa nova janela) Dart (Abre numa nova janela), Elixir (Abre numa nova janela), F# (Abre numa nova janela), Opa (Abre numa nova janela), Oz (Abre numa nova janela), Reia (Abre numa nova janela), Rust (Abre numa nova janela),[4] (Abre numa nova janela) Scala (Abre numa nova janela), Go (Abre numa nova janela)
Erlang Programming (Abre numa nova janela) at Wikibooks
Erlang (/ˈɜːrlæŋ/ (Abre numa nova janela) UR-lang (Abre numa nova janela)) is a general-purpose (Abre numa nova janela), concurrent (Abre numa nova janela), functional (Abre numa nova janela) high-level (Abre numa nova janela) programming language (Abre numa nova janela), and a garbage-collected (Abre numa nova janela) runtime system (Abre numa nova janela). The term Erlang is used interchangeably with Erlang/OTP, or Open Telecom Platform (Abre numa nova janela) (OTP), which consists of the Erlang runtime system (Abre numa nova janela), several ready-to-use components (OTP) mainly written in Erlang, and a set of design principles (Abre numa nova janela) for Erlang programs.[5] (Abre numa nova janela)
The Erlang runtime system (Abre numa nova janela) is designed for systems with these traits:
Highly available (Abre numa nova janela), non-stop (Abre numa nova janela) applications
Hot swapping (Abre numa nova janela), where code can be changed without stopping a system.[6] (Abre numa nova janela)
The Erlang programming language (Abre numa nova janela) has immutable (Abre numa nova janela) data, pattern matching (Abre numa nova janela), and functional programming (Abre numa nova janela).[7] (Abre numa nova janela) The sequential subset of the Erlang language supports eager evaluation (Abre numa nova janela), single assignment (Abre numa nova janela), and dynamic typing (Abre numa nova janela).
A normal Erlang application is built out of hundreds of small Erlang processes.
It was originally proprietary software (Abre numa nova janela) within Ericsson (Abre numa nova janela), developed by Joe Armstrong (Abre numa nova janela), Robert Virding, and Mike Williams in 1986,[8] (Abre numa nova janela) but was released as free and open-source software (Abre numa nova janela) in 1998.[9] (Abre numa nova janela)[10] (Abre numa nova janela) Erlang/OTP is supported and maintained by the Open Telecom Platform (OTP) product unit at Ericsson (Abre numa nova janela).
History
The name Erlang, attributed to Bjarne Däcker, has been presumed by those working on the telephony switches (for whom the language was designed) to be a reference to Danish mathematician and engineer Agner Krarup Erlang (Abre numa nova janela) and a syllabic abbreviation (Abre numa nova janela) of "Ericsson Language".[8] (Abre numa nova janela)[11] (Abre numa nova janela)[12] (Abre numa nova janela) Erlang was designed with the aim of improving the development of telephony applications.[13] (Abre numa nova janela) The initial version of Erlang was implemented in Prolog (Abre numa nova janela) and was influenced by the programming language PLEX (Abre numa nova janela) used in earlier Ericsson exchanges. By 1988 Erlang had proven that it was suitable for prototyping telephone exchanges, but the Prolog interpreter was far too slow. One group within Ericsson estimated that it would need to be 40 times faster to be suitable for production use. In 1992, work began on the BEAM (Abre numa nova janela) virtual machine (VM), which compiles Erlang to C using a mix of natively compiled code and threaded code (Abre numa nova janela) to strike a balance between performance and disk space.[14] (Abre numa nova janela) According to co-inventor Joe Armstrong, the language went from laboratory product to real applications following the collapse of the next-generation AXE telephone exchange (Abre numa nova janela) named AXE-N (Abre numa nova janela) in 1995. As a result, Erlang was chosen for the next Asynchronous Transfer Mode (Abre numa nova janela) (ATM) exchange AXD.[8] (Abre numa nova janela)
(Abre numa nova janela)In February 1998, Ericsson Radio Systems banned the in-house use of Erlang for new products, citing a preference for non-proprietary languages.[15] (Abre numa nova janela) The ban caused Armstrong and others to make plans to leave Ericsson.[16] (Abre numa nova janela) In March 1998 Ericsson announced the AXD301 switch,[8] (Abre numa nova janela) containing over a million lines of Erlang and reported to achieve a high availability (Abre numa nova janela) of nine "9"s (Abre numa nova janela).[17] (Abre numa nova janela) In December 1998, the implementation of Erlang was open-sourced and most of the Erlang team resigned to form a new company, Bluetail AB.[8] (Abre numa nova janela) Ericsson eventually relaxed the ban and re-hired Armstrong in 2004.[16] (Abre numa nova janela)
In 2006, native symmetric multiprocessing (Abre numa nova janela) support was added to the runtime system and VM.[8] (Abre numa nova janela)
Processes
Erlang applications are built of very lightweight Erlang processes in the Erlang runtime system. Erlang processes can be seen as "living" objects (object-oriented programming (Abre numa nova janela)), with data encapsulation and message passing (Abre numa nova janela), but capable of changing behavior during runtime. The Erlang runtime system provides strict process isolation (Abre numa nova janela) between Erlang processes (this includes data and garbage collection, separated individually by each Erlang process) and transparent communication between processes (see Location transparency (Abre numa nova janela)) on different Erlang nodes (on different hosts).
Joe Armstrong, co-inventor of Erlang, summarized the principles of processes in his PhD (Abre numa nova janela) thesis (Abre numa nova janela):[18] (Abre numa nova janela)
Everything is a process.
Processes are strongly isolated.
Process creation and destruction is a lightweight operation.
Message passing is the only way for processes to interact.
Processes have unique names.
If you know the name of a process you can send it a message.
Processes share no resources.
Error handling is non-local.
Processes do what they are supposed to do or fail.
Joe Armstrong remarked in an interview with Rackspace in 2013: "If Java (Abre numa nova janela) is 'write once, run anywhere (Abre numa nova janela)', then Erlang is 'write once, run forever'."[19] (Abre numa nova janela)
Usage
In 2014, Ericsson (Abre numa nova janela) reported Erlang was being used in its support nodes, and in GPRS (Abre numa nova janela), 3G (Abre numa nova janela) and LTE (Abre numa nova janela) mobile networks worldwide and also by Nortel (Abre numa nova janela) and Deutsche Telekom (Abre numa nova janela).[20] (Abre numa nova janela)
Erlang is used in RabbitMQ (Abre numa nova janela). As Tim Bray (Abre numa nova janela), director of Web Technologies at Sun Microsystems (Abre numa nova janela), expressed in his keynote at O'Reilly Open Source Convention (Abre numa nova janela) (OSCON) in July 2008:
If somebody came to me and wanted to pay me a lot of money to build a large scale message handling system that really had to be up all the time, could never afford to go down for years at a time, I would unhesitatingly choose Erlang to build it in.
Erlang is the programming language used to code WhatsApp (Abre numa nova janela).[21] (Abre numa nova janela)
It is also the language of choice for Ejabberd (Abre numa nova janela) – an XMPP (Abre numa nova janela) messaging server.
Elixir (Abre numa nova janela) is a programming language that compiles into BEAM byte code (via Erlang Abstract Format).[22] (Abre numa nova janela)
Since being released as open source, Erlang has been spreading beyond telecoms, establishing itself in other vertical markets such as FinTech, gaming, healthcare, automotive, Internet of Things and blockchain. Apart from WhatsApp, there are other companies listed as Erlang's success stories, including Vocalink (Abre numa nova janela) (a MasterCard company), Goldman Sachs (Abre numa nova janela), Nintendo (Abre numa nova janela), AdRoll, Grindr (Abre numa nova janela), BT Mobile (Abre numa nova janela), Samsung (Abre numa nova janela), OpenX (Abre numa nova janela), and SITA (Abre numa nova janela).[23] (Abre numa nova janela)[24] (Abre numa nova janela)
Functional programming examples
Factorial
A factorial (Abre numa nova janela) algorithm implemented in Erlang:
-module(fact). % This is the file 'fact.erl', the module and the filename must match
-export([fac/1]). % This exports the function 'fac' of arity 1 (1 parameter, no type, no name)
fac(0) -> 1; % If 0, then return 1, otherwise (note the semicolon ; meaning 'else')
fac(N) when N > 0, is_integer(N) -> N * fac(N-1).
% Recursively determine, then return the result
% (note the period . meaning 'endif' or 'function end')
%% This function will crash if anything other than a nonnegative integer is given.
%% It illustrates the "Let it crash" philosophy of Erlang.
Fibonacci sequence
A tail recursive algorithm that produces the Fibonacci sequence (Abre numa nova janela):
%% The module declaration must match the file name "series.erl"
-module(series).
%% The export statement contains a list of all those functions that form
%% the module's public API. In this case, this module exposes a single
%% function called fib that takes 1 argument (I.E. has an arity of 1)
%% The general syntax for -export is a list containing the name and
%% arity of each public function
-export([fib/1]).
%% ---------------------------------------------------------------------
%% Public API
%% ---------------------------------------------------------------------
%% Handle cases in which fib/1 receives specific values
%% The order in which these function signatures are declared is a vital
%% part of this module's functionality
%% If fib/1 receives a negative number, then return the atom err_neg_val
%% Normally, such defensive coding is discouraged due to Erlang's 'Let
%% it Crash' philosophy, but here the result would be an infinite loop.
fib(N) when N < 0 -> err_neg_val;
%% If fib/1 is passed precisely the integer 0, then return 0
fib(0) -> 0;
%% For all other values, call the private function fib_int/3 to perform
%% the calculation
fib(N) -> fib_int(N-1, 0, 1).
%% ---------------------------------------------------------------------
%% Private API
%% ---------------------------------------------------------------------
%% If fib_int/3 receives 0 as its first argument, then we're done, so
%% return the value in argument B. The second argument is denoted _ to
%% disregard its value.
fib_int(0, _, B) -> B;
%% For all other argument combinations, recursively call fib_int/3
%% where each call does the following:
%% - decrement counter N
%% - pass the third argument as the new second argument
%% - pass the sum of the second and third arguments as the new
%% third argument
fib_int(N, A, B) -> fib_int(N-1, B, A+B).
Omitting the comments gives a much shorter program.
-module(series).
-export([fib/1]).
fib(N) when N < 0 -> err_neg_val;
fib(0) -> 0;
fib(N) -> fib_int(N-1, 0, 1).
fib_int(0, _, B) -> B;
fib_int(N, A, B) -> fib_int(N-1, B, A+B).
Quicksort
Quicksort (Abre numa nova janela) in Erlang, using list comprehension (Abre numa nova janela):[25] (Abre numa nova janela)
%% qsort:qsort(List)
%% Sort a list of items
-module(qsort). % This is the file 'qsort.erl'
-export([qsort/1]). % A function 'qsort' with 1 parameter is exported (no type, no name)
qsort([]) -> []; % If the list [] is empty, return an empty list (nothing to sort)
qsort([Pivot|Rest]) ->
% Compose recursively a list with 'Front' for all elements that should be before 'Pivot'
% then 'Pivot' then 'Back' for all elements that should be after 'Pivot'
qsort([Front || Front <- Rest, Front < Pivot]) ++
[Pivot] ++
qsort([Back || Back <- Rest, Back >= Pivot]).
The above example recursively invokes the function qsort until nothing remains to be sorted. The expression [Front || Front <- Rest, Front < Pivot] is a list comprehension (Abre numa nova janela), meaning "Construct a list of elements Front such that Front is a member of Rest, and Front is less than Pivot." ++ is the list concatenation operator.
A comparison function can be used for more complicated structures for the sake of readability.
The following code would sort lists according to length:
% This is file 'listsort.erl' (the compiler is made this way)
-module(listsort).
% Export 'by_length' with 1 parameter (don't care about the type and name)
-export([by_length/1]).
by_length(Lists) -> % Use 'qsort/2' and provides an anonymous function as a parameter
qsort(Lists, fun(A,B) -> length(A) < length(B) end).
qsort([], _)-> []; % If list is empty, return an empty list (ignore the second parameter)
qsort([Pivot|Rest], Smaller) ->
% Partition list with 'Smaller' elements in front of 'Pivot' and not-'Smaller' elements
% after 'Pivot' and sort the sublists.
qsort([X || X <- Rest, Smaller(X,Pivot)], Smaller)
++ [Pivot] ++
qsort([Y || Y <- Rest, not(Smaller(Y, Pivot))], Smaller).
A Pivot is taken from the first parameter given to qsort() and the rest of Lists is named Rest. Note that the expression
[X || X <- Rest, Smaller(X,Pivot)]
is no different in form from
[Front || Front <- Rest, Front < Pivot]
(in the previous example) except for the use of a comparison function in the last part, saying "Construct a list of elements X such that X is a member of Rest, and Smaller is true", with Smaller being defined earlier as
fun(A,B) -> length(A) < length(B) end
The anonymous function (Abre numa nova janela) is named Smaller in the parameter list of the second definition of qsort so that it can be referenced by that name within that function. It is not named in the first definition of qsort, which deals with the base case of an empty list and thus has no need of this function, let alone a name for it.
Data types
Erlang has eight primitive data types (Abre numa nova janela):
Integers
Integers are written as sequences of decimal digits, for example, 12, 12375 and -23427 are integers. Integer arithmetic is exact and only limited by available memory on the machine. (This is called arbitrary-precision arithmetic (Abre numa nova janela).)
Atoms
Atoms are used within a program to denote distinguished values. They are written as strings of consecutive alphanumeric characters, the first character being lowercase. Atoms can contain any character if they are enclosed within single quotes and an escape convention exists which allows any character to be used within an atom. Atoms are never garbage collected and should be used with caution, especially if using dynamic atom generation.
Floats
Floating point numbers use the IEEE 754 64-bit representation (Abre numa nova janela).
References
References are globally unique symbols whose only property is that they can be compared for equality. They are created by evaluating the Erlang primitive make_ref().
Binaries
A binary is a sequence of bytes. Binaries provide a space-efficient way of storing binary data. Erlang primitives exist for composing and decomposing binaries and for efficient input/output of binaries.
Pids
Pid is short for process identifier – a Pid is created by the Erlang primitive spawn(...) Pids are references to Erlang processes.
Ports
Ports are used to communicate with the external world. Ports are created with the built-in function open_port. Messages can be sent to and received from ports, but these messages must obey the so-called "port protocol."
Funs
Funs are function closures (Abre numa nova janela). Funs are created by expressions of the form: fun(...) -> ... end.
And three compound data types:
Tuples
Tuples are containers for a fixed number of Erlang data types. The syntax {D1,D2,...,Dn} denotes a tuple whose arguments are D1, D2, ... Dn. The arguments can be primitive data types or compound data types. Any element of a tuple can be accessed in constant time.
Lists
Lists are containers for a variable number of Erlang data types. The syntax [Dh|Dt] denotes a list whose first element is Dh, and whose remaining elements are the list Dt. The syntax [] denotes an empty list. The syntax [D1,D2,..,Dn] is short for [D1|[D2|..|[Dn|[]]]]. The first element of a list can be accessed in constant time. The first element of a list is called the head of the list. The remainder of a list when its head has been removed is called the tail of the list.
Maps
Maps contain a variable number of key-value associations. The syntax is#{Key1=>Value1,...,KeyN=>ValueN}.
Two forms of syntactic sugar (Abre numa nova janela) are provided:
Strings
Strings are written as doubly quoted lists of characters. This is syntactic sugar for a list of the integer Unicode (Abre numa nova janela) code points for the characters in the string. Thus, for example, the string "cat" is shorthand for [99,97,116].[26] (Abre numa nova janela)
Records
Records provide a convenient way for associating a tag with each of the elements in a tuple. This allows one to refer to an element of a tuple by name and not by position. A pre-compiler takes the record definition and replaces it with the appropriate tuple reference.
Erlang has no method to define classes, although there are external libraries (Abre numa nova janela) available.[27] (Abre numa nova janela)
"Let it crash" coding style
Erlang is designed with a mechanism that makes it easy for external processes to monitor for crashes (or hardware failures), rather than an in-process mechanism like exception handling (Abre numa nova janela) used in many other programming languages. Crashes are reported like other messages, which is the only way processes can communicate with each other,[28] (Abre numa nova janela) and subprocesses can be spawned cheaply (see below (Abre numa nova janela)). The "let it crash" philosophy prefers that a process be completely restarted rather than trying to recover from a serious failure.[29] (Abre numa nova janela) Though it still requires handling of errors, this philosophy results in less code devoted to defensive programming (Abre numa nova janela) where error-handling code is highly contextual and specific.[28] (Abre numa nova janela)
Supervisor trees
A typical Erlang application is written in the form of a supervisor tree. This architecture is based on a hierarchy of processes in which the top level process is known as a "supervisor". The supervisor then spawns multiple child processes that act either as workers or more, lower level supervisors. Such hierarchies can exist to arbitrary depths and have proven to provide a highly scalable and fault-tolerant environment within which application functionality can be implemented.
Within a supervisor tree, all supervisor processes are responsible for managing the lifecycle of their child processes, and this includes handling situations in which those child processes crash. Any process can become a supervisor by first spawning a child process, then calling erlang:monitor/2 on that process. If the monitored process then crashes, the supervisor will receive a message containing a tuple whose first member is the atom 'DOWN'. The supervisor is responsible firstly for listening for such messages and for taking the appropriate action to correct the error condition.
Concurrency and distribution orientation
Erlang's main strength is support for concurrency (Abre numa nova janela). It has a small but powerful set of primitives to create processes and communicate among them. Erlang is conceptually similar to the language occam (Abre numa nova janela), though it recasts the ideas of communicating sequential processes (Abre numa nova janela) (CSP) in a functional framework and uses asynchronous message passing.[30] (Abre numa nova janela) Processes are the primary means to structure an Erlang application. They are neither operating system (Abre numa nova janela) processes (Abre numa nova janela) nor threads (Abre numa nova janela), but lightweight processes (Abre numa nova janela) that are scheduled by BEAM. Like operating system processes (but unlike operating system threads), they share no state with each other. The estimated minimal overhead for each is 300 words (Abre numa nova janela).[31] (Abre numa nova janela) Thus, many processes can be created without degrading performance. In 2005, a benchmark with 20 million processes was successfully performed with 64-bit Erlang on a machine with 16 GB random-access memory (Abre numa nova janela) (RAM; total 800 bytes/process).[32] (Abre numa nova janela) Erlang has supported symmetric multiprocessing (Abre numa nova janela) since release R11B of May 2006.
While threads (Abre numa nova janela) need external library support in most languages, Erlang provides language-level features to create and manage processes with the goal of simplifying concurrent programming. Though all concurrency is explicit in Erlang, processes communicate using message passing (Abre numa nova janela) instead of shared variables, which removes the need for explicit locks (Abre numa nova janela) (a locking scheme is still used internally by the VM).[33] (Abre numa nova janela)
Inter-process communication (Abre numa nova janela) works via a shared-nothing (Abre numa nova janela) asynchronous (Abre numa nova janela) message passing (Abre numa nova janela) system: every process has a "mailbox", a queue (Abre numa nova janela) of messages that have been sent by other processes and not yet consumed. A process uses the receive primitive to retrieve messages that match desired patterns. A message-handling routine tests messages in turn against each pattern, until one of them matches. When the message is consumed and removed from the mailbox the process resumes execution. A message may comprise any Erlang structure, including primitives (integers, floats, characters, atoms), tuples, lists, and functions.
The code example below shows the built-in support for distributed processes:
% Create a process and invoke the function web:start_server(Port, MaxConnections)
ServerProcess = spawn(web, start_server, [Port, MaxConnections]),
% Create a remote process and invoke the function
% web:start_server(Port, MaxConnections) on machine RemoteNode
RemoteProcess = spawn(RemoteNode, web, start_server, [Port, MaxConnections]),
% Send a message to ServerProcess (asynchronously). The message consists of a tuple
% with the atom "pause" and the number "10".
ServerProcess ! {pause, 10},
% Receive messages sent to this process
receive
a_message -> do_something;
{data, DataContent} -> handle(DataContent);
{hello, Text} -> io:format("Got hello message: ~s", [Text]);
{goodbye, Text} -> io:format("Got goodbye message: ~s", [Text])
end.
As the example shows, processes may be created on remote nodes, and communication with them is transparent in the sense that communication with remote processes works exactly as communication with local processes.
Concurrency supports the primary method of error-handling in Erlang. When a process crashes, it neatly exits and sends a message to the controlling process which can then take action, such as starting a new process that takes over the old process's task.[34] (Abre numa nova janela)[35] (Abre numa nova janela)
Implementation
The official reference implementation of Erlang uses BEAM (Abre numa nova janela).[36] (Abre numa nova janela) BEAM is included in the official distribution of Erlang, called Erlang/OTP. BEAM executes bytecode (Abre numa nova janela) which is converted to threaded code (Abre numa nova janela) at load time. It also includes a native code compiler on most platforms, developed by the High Performance Erlang Project (HiPE) at Uppsala University (Abre numa nova janela). Since October 2001 the HiPE system is fully integrated in Ericsson's Open Source Erlang/OTP system.[37] (Abre numa nova janela) It also supports interpreting, directly from source code via abstract syntax tree (Abre numa nova janela), via script as of R11B-5 release of Erlang.
Hot code loading and modules
Erlang supports language-level Dynamic Software Updating (Abre numa nova janela). To implement this, code is loaded and managed as "module" units; the module is a compilation unit (Abre numa nova janela). The system can keep two versions of a module in memory at the same time, and processes can concurrently run code from each. The versions are referred to as the "new" and the "old" version. A process will not move into the new version until it makes an external call to its module.
An example of the mechanism of hot code loading:
%% A process whose only job is to keep a counter.
%% First version
-module(counter).
-export([start/0, codeswitch/1]).
start() -> loop(0).
loop(Sum) ->
receive
{increment, Count} ->
loop(Sum+Count);
{counter, Pid} ->
Pid ! {counter, Sum},
loop(Sum);
code_switch ->
?MODULE:codeswitch(Sum)
% Force the use of 'codeswitch/1' from the latest MODULE version
end.
codeswitch(Sum) -> loop(Sum).
For the second version, we add the possibility to reset the count to zero.
%% Second version
-module(counter).
-export([start/0, codeswitch/1]).
start() -> loop(0).
loop(Sum) ->
receive
{increment, Count} ->
loop(Sum+Count);
reset ->
loop(0);
{counter, Pid} ->
Pid ! {counter, Sum},
loop(Sum);
code_switch ->
?MODULE:codeswitch(Sum)
end.
codeswitch(Sum) -> loop(Sum).
Only when receiving a message consisting of the atom code_switch will the loop execute an external call to codeswitch/1 (?MODULE is a preprocessor macro for the current module). If there is a new version of the counter module in memory, then its codeswitch/1 function will be called. The practice of having a specific entry-point into a new version allows the programmer to transform state to what is needed in the newer version. In the example, the state is kept as an integer.
In practice, systems are built up using design principles from the Open Telecom Platform, which leads to more code upgradable designs. Successful hot code loading is exacting. Code must be written with care to make use of Erlang's facilities.
Distribution
In 1998, Ericsson released Erlang as free and open-source software (Abre numa nova janela) to ensure its independence from a single vendor and to increase awareness of the language. Erlang, together with libraries and the real-time distributed database Mnesia (Abre numa nova janela), forms the OTP collection of libraries. Ericsson and a few other companies support Erlang commercially.
Since the open source release, Erlang has been used by several firms worldwide, including Nortel (Abre numa nova janela) and Deutsche Telekom (Abre numa nova janela).[38] (Abre numa nova janela) Although Erlang was designed to fill a niche and has remained an obscure language for most of its existence, its popularity is growing due to demand for concurrent services.[39] (Abre numa nova janela)[40] (Abre numa nova janela) Erlang has found some use in fielding massively multiplayer online role-playing game (Abre numa nova janela) (MMORPG) servers.[41] (Abre numa nova janela)
See also
Elixir (Abre numa nova janela) – a functional, concurrent, general-purpose programming language that runs on BEAM
Luerl (Abre numa nova janela) - Lua on the BEAM, designed and implemented by one of the creators of Erlang.
Lisp Flavored Erlang (Abre numa nova janela) (LFE) – a Lisp-based programming language that runs on BEAM
References
"Release 27.3.4" (Abre numa nova janela). 8 May 2025. Retrieved 17 May 2025.
Conferences, N. D. C. (4 June 2014). "Joe Armstrong - Functional Programming the Long Road to Enlightenment: a Historical and Personal Narrative" (Abre numa nova janela). Vimeo.
"Clojure: Lisp meets Java, with a side of Erlang - O'Reilly Radar" (Abre numa nova janela). radar.oreilly.com (Abre numa nova janela).
"Influences - The Rust Reference" (Abre numa nova janela). The Rust Reference. Retrieved 18 April 2023.
"Erlang – Introduction" (Abre numa nova janela). erlang.org (Abre numa nova janela). Archived from the original (Abre numa nova janela) on 8 September 2019. Retrieved 6 February 2017.
Armstrong, Joe; Däcker, Bjarne; Lindgren, Thomas; Millroth, Håkan. "Open-source Erlang – White Paper" (Abre numa nova janela). Archived from the original (Abre numa nova janela) on 25 October 2011. Retrieved 31 July 2011.
Hitchhiker’s Tour of the BEAM – Robert Virding http://www.erlang-factory.com/upload/presentations/708/HitchhikersTouroftheBEAM.pdf (Abre numa nova janela)
Armstrong, Joe (2007). History of Erlang. HOPL III: Proceedings of the third ACM SIGPLAN conference on History of programming languages. ISBN (Abre numa nova janela) 978-1-59593-766-7 (Abre numa nova janela).
"How tech giants spread open source programming love - (Abre numa nova janela)CIO.com (Abre numa nova janela)" (Abre numa nova janela). 8 January 2016. Archived from the original (Abre numa nova janela) on 22 February 2019. Retrieved 5 September 2016.
"Erlang/OTP Released as Open Source, 1998-12-08" (Abre numa nova janela). Archived from the original (Abre numa nova janela) on 9 October 1999.
"Erlang, the mathematician?" (Abre numa nova janela). February 1999.
"Free Online Dictionary of Computing: Erlang" (Abre numa nova janela).
"History of Erlang" (Abre numa nova janela). Erlang.org (Abre numa nova janela).
Armstrong, Joe (August 1997). "The development of Erlang". Proceedings of the second ACM SIGPLAN international conference on Functional programming. Vol. 32. pp. 196–203. doi (Abre numa nova janela):10.1145/258948.258967 (Abre numa nova janela). ISBN (Abre numa nova janela) 0897919181 (Abre numa nova janela). S2CID (Abre numa nova janela) 6821037 (Abre numa nova janela).
{{cite book}}:|journal=ignored (help (Abre numa nova janela))Däcker, Bjarne (October 2000). Concurrent Functional Programming for Telecommunications: A Case Study of Technology Introduction (Abre numa nova janela) (PDF) (Thesis). Royal Institute of Technology. p. 37.
"question about Erlang's future" (Abre numa nova janela). 6 July 2010.
"Concurrency Oriented Programming in Erlang" (Abre numa nova janela) (PDF). 9 November 2002.
Armstrong, Joe (20 November 2003). Making reliable distributed systems in the presence of software errors (DTech thesis). Stockholm, Sweden: The Royal Institute of Technology.
McGreggor, Duncan (26 March 2013). Rackspace takes a look at the Erlang programming language for distributed computing (Abre numa nova janela) (Video). Rackspace Studios, SFO. Archived (Abre numa nova janela) from the original on 11 December 2021. Retrieved 24 April 2019.
"Ericsson" (Abre numa nova janela). Ericsson.com (Abre numa nova janela). 4 December 2014. Retrieved 7 April 2018.
"Inside Erlang, The Rare Programming Language Behind WhatsApp's Success" (Abre numa nova janela). fastcompany.com (Abre numa nova janela). 21 February 2014. Retrieved 12 November 2019.
"Erlang/Elixir Syntax: A Crash Course" (Abre numa nova janela). elixir-lang.github.com (Abre numa nova janela). Retrieved 10 October 2022.
"Which companies are using Erlang, and why? #MyTopdogStatus" (Abre numa nova janela). erlang-solutions.com (Abre numa nova janela). 11 September 2019. Retrieved 15 March 2020.
"Which new companies are using Erlang and Elixir? #MyTopdogStatus" (Abre numa nova janela). erlang-solutions.com (Abre numa nova janela). 2 March 2020. Retrieved 24 June 2020.
"Erlang – List Comprehensions" (Abre numa nova janela). erlang.org (Abre numa nova janela).
"String and Character Literals" (Abre numa nova janela). Retrieved 2 May 2015.
"ect – Erlang Class Transformation – add object-oriented programming to Erlang – Google Project Hosting" (Abre numa nova janela). Retrieved 2 May 2015.
Verraes, Mathias (9 December 2014). "Let It Crash" (Abre numa nova janela). Mathias Verraes' Blog. Retrieved 10 February 2021.
"Reactive Design Patterns —" (Abre numa nova janela). www.reactivedesignpatterns.com (Abre numa nova janela). Retrieved 10 February 2021.
Armstrong, Joe (Abre numa nova janela) (September 2010). "Erlang" (Abre numa nova janela). Communications of the ACM (Abre numa nova janela). 53 (9): 68–75. doi (Abre numa nova janela):10.1145/1810891.1810910 (Abre numa nova janela). Erlang is conceptually similar to the occam programming language, though it recasts the ideas of CSP in a functional framework and uses asynchronous message passing.
"Erlang Efficiency Guide – Processes" (Abre numa nova janela). Archived from the original (Abre numa nova janela) on 27 February 2015.
Wiger, Ulf (14 November 2005). "Stress-testing erlang" (Abre numa nova janela). comp.lang.functional.misc. Retrieved 25 August 2006.
"Lock-free message queue" (Abre numa nova janela). Archived from the original (Abre numa nova janela) on 24 December 2013. Retrieved 23 December 2013.
Armstrong, Joe. "Erlang robustness" (Abre numa nova janela). Archived from the original (Abre numa nova janela) on 23 April 2015. Retrieved 15 July 2010.
"Erlang Supervision principles" (Abre numa nova janela). Archived from the original (Abre numa nova janela) on 6 February 2015. Retrieved 15 July 2010.
"Erlang – Compilation and Code Loading" (Abre numa nova janela). erlang.org (Abre numa nova janela). Retrieved 21 December 2017.
"High Performance Erlang" (Abre numa nova janela). Retrieved 26 March 2011.
"Who uses Erlang for product development?" (Abre numa nova janela). Frequently asked questions about Erlang. Retrieved 16 July 2007. The largest user of Erlang is (surprise!) Ericsson. Ericsson use it to write software used in telecommunications systems. Many dozens of projects have used it, a particularly large one is the extremely scalable AXD301 ATM switch. Other commercial users listed as part of the FAQ include: Nortel, Deutsche Flugsicherung (the German national air traffic control (Abre numa nova janela) organisation), and T-Mobile.
"Programming Erlang" (Abre numa nova janela). Retrieved 13 December 2008. Virtually all language use shared state concurrency. This is very difficult and leads to terrible problems when you handle failure and scale up the system...Some pretty fast-moving startups in the financial world have latched onto Erlang; for example, the Swedish www.kreditor.se (Abre numa nova janela).
"Erlang, the next Java" (Abre numa nova janela). Archived from the original (Abre numa nova janela) on 11 October 2007. Retrieved 8 October 2008. I do not believe that other languages can catch up with Erlang anytime soon. It will be easy for them to add language features to be like Erlang. It will take a long time for them to build such a high-quality VM and the mature libraries for concurrency and reliability. So, Erlang is poised for success. If you want to build a multicore application in the next few years, you should look at Erlang.
Clarke, Gavin (5 February 2011). "Battlestar Galactica vets needed for online roleplay" (Abre numa nova janela). Music and Media. The Reg (Abre numa nova janela). Retrieved 8 February 2011.
Further reading
Armstrong, Joe (2003). Making reliable distributed systems in the presence of software errors (Abre numa nova janela) (PDF) (PhD). The Royal Institute of Technology, Stockholm, Sweden. Archived from the original (Abre numa nova janela) (PDF) on 23 March 2015. Retrieved 13 February 2016.
Armstrong, Joe (2007). "A history of Erlang". Proceedings of the third ACM SIGPLAN conference on History of programming languages – HOPL III. pp. 6–1. doi (Abre numa nova janela):10.1145/1238844.1238850 (Abre numa nova janela). ISBN (Abre numa nova janela) 978-1-59593-766-7 (Abre numa nova janela). S2CID (Abre numa nova janela) 555765 (Abre numa nova janela).
Early history of Erlang (Abre numa nova janela) Archived (Abre numa nova janela) 29 August 2019 at the Wayback Machine (Abre numa nova janela) by Bjarne Däcker
Mattsson, H.; Nilsson, H.; Wikstrom, C. (1999). "Mnesia – A distributed robust DBMS for telecommunications applications". First International Workshop on Practical Aspects of Declarative Languages (PADL '99): 152–163.
Armstrong, Joe; Virding, Robert; Williams, Mike; Wikstrom, Claes (16 January 1996). Concurrent Programming in Erlang (Abre numa nova janela) (2nd ed.). Prentice Hall (Abre numa nova janela). p. 358. ISBN (Abre numa nova janela) 978-0-13-508301-7 (Abre numa nova janela). Archived from the original (Abre numa nova janela) on 6 March 2012.
Armstrong, Joe (11 July 2007). Programming Erlang: Software for a Concurrent World (Abre numa nova janela) (1st ed.). Pragmatic Bookshelf (Abre numa nova janela). p. 536 (Abre numa nova janela). ISBN (Abre numa nova janela) 978-1-934356-00-5 (Abre numa nova janela).
Thompson, Simon J.; Cesarini, Francesco (19 June 2009). Erlang Programming: A Concurrent Approach to Software Development (Abre numa nova janela) (1st ed.). Sebastopol, California: O'Reilly Media (Abre numa nova janela), Inc. p. 496. ISBN (Abre numa nova janela) 978-0-596-51818-9 (Abre numa nova janela).
Logan, Martin; Merritt, Eric; Carlsson, Richard (28 May 2010). Erlang and OTP in Action (1st ed.). Greenwich, CT: Manning Publications (Abre numa nova janela). p. 500. ISBN (Abre numa nova janela) 978-1-933988-78-8 (Abre numa nova janela).
Martin, Brown (10 May 2011). "Introduction to programming in Erlang, Part 1: The basics" (Abre numa nova janela). developerWorks. IBM. Retrieved 10 May 2011.
Martin, Brown (17 May 2011). "Introduction to programming in Erlang, Part 2: Use advanced features and functionality" (Abre numa nova janela). developerWorks. IBM. Retrieved 17 May 2011.
Wiger, Ulf (30 March 2001). "Four-fold Increase in Productivity and Quality: Industrial-Strength Functional Programming in Telecom-Class Products" (Abre numa nova janela) (PDF). FEmSYS 2001 Deployment on distributed architectures. Ericsson Telecom AB. Archived from the original (Abre numa nova janela) (PDF) on 19 August 2019. Retrieved 16 September 2014.
External links
Wikimedia Commons has media related to Erlang (programming language) (Abre numa nova janela).
Wikibooks has a book on the topic of: Erlang Programming (Abre numa nova janela)