Gleam, an actor-based highly-concurrent functional language running on the Erlang virtual machine (BEAM), has reached version 1.0, which means it is now ready to be used in production systems with a guarantee of backward compatibility based on semantic versioning.
Gleam aims to be a language with a small surface area, easy to read and understand, and expressive.
Gleam runs on the Erlang virtual machine, a mature and battle-tested platform that powers many of the world’s most reliable and scalable systems, such as WhatsApp. Gleam can also run on JavaScript runtimes, making it possible to run Gleam code in the browser, on mobile devices, or anywhere else.
Gleam follows in the line of strong statically-typed languages like Elm, OCaml, and Rust, providing robust static analysis and compile-time guarantees. It also adopts immutable data structures implemented with structural sharing as in Clojure to ensure efficient operation. Concurrent access to mutable state is achieved through actors or Erlang's in-memory key-value database ETS.
According to the language core team, Gleam's concurrency system can run millions of tasks concurrently and scale easily thanks to immutable data and a garbage collector that never stops the world.
Gleam programs can use packages created for BEAM independently from the language used to write them. Additionally, it is possible to mix Erlang and Elixir code in a Gleam program. This is possible thanks to Gleam build tool being able to compile Elixir dependencies as well as Elixir source files and supporting a specific syntax that enables importing external functions to call them from Gleam code. Gleam also supports seamless integration with JavaScript code when compiling for the JavaScript runtime:
pub fn register_event_handler() {
let el = document.query_selector("a")
element.add_event_listener(el, fn() {
io.println("Clicked!")
})
}
Gleam can also use Erlang hot code reloading but without any additional guarantees to those provided by Erlang itself. Specifically, upgraded code cannot be type checked since it is not possible to know which types are used in the running code.
The arena of languages for the Erlang virtual machine sports several Gleam competitors, including Alpaca, Caramel, and Elixir. Both Alpaca and Caramel are statically-typed languages that differ from Gleam in a number of ways. In particular, Caramel is based on OCaml and even forks the OCaml compiler to generate code, while Gleam and Alpaca are original languages. Gleam is the only one of the set that also targets JavaScript. On the other hand, Elixir is, without doubt, the most mature and popular alternative to Erlang on BEAM, providing a Ruby-like syntax and a dynamical type system.