The Gleam type safety shift on the BEAM
Gleam provides strong static typing and JavaScript targets for the Erlang virtual machine, offering a type-safe alternative to Elixir. The language recently reached version 1.0 and was named the second most admired programming language by developers.
Gleam reached version 1.0, which provides backward compatibility through semantic versioning. This statically typed language runs on the Erlang virtual machine and also targets JavaScript runtimes, which makes it possible to run Gleam code on mobile devices or in a browser. While Elixir provides a dynamic type system that is moving toward gradual typing, Gleam provides strong static analysis and compile-time guarantees. The language has a small surface area and a syntax that feels like a hybrid of Elixir and OCaml. Developers coming from modern typed languages like TypeScript or Rust feel at home quickly. This language allows millions of tasks to run concurrently because it uses the Erlang virtual machine. You can also use Erlang and Elixir code in a Gleam program because the Gleam build tool compiles Elixir dependencies and source files. The language core team provides a system that scales easily thanks to immutable data and a garbage collector that never stops the world. Concurrent access to mutable state is achieved through actors or the Erlang in-memory key-value database, ETS. Gleam is an original language, which differs from Caramel, a language based on OCaml that forks the OCaml compiler to generate code. Gleam is the only language in its set of BEAM competitors, like Alpaca and Caramel, that targets JavaScript. Gleam recently entered the list of "Most Admired Programming Languages" at number two, with 70% of developers expressing interest in continuing to use it.
Frameworks and interoperability
Elixir uses a powerful macro system that libraries like Phoenix and Ecto use to manage tasks like JSON decoding. Gleam does not have macros, which makes it more predictable but also more verbose. If you want to build web applications, you choose between the mature Phoenix framework and the lower-level Wisp. Wisp behaves like Plug, which requires building your own abstractions for various tasks. Elixir, created in 2012, has superior deployment tooling, including support for OTP releases and umbrella applications. Gleam’s editor tooling is superior because it has a mature official language server. Elixir’s type system does not include generics, whereas Gleam’s type system does. Gleam’s standard library is distributed as Hex packages, which makes interoperability with other BEAM languages easier. If you are moving from a language like C or Rust, you might find Gleam’s C-family syntax more familiar than the Ruby-like syntax that Elixir uses to provide its functional programming experience on the BEAM.
| Feature | Gleam | Elixir |
|---|---|---|
| Type System | Static | Dynamic/Gradual |
| Syntax Style | C-family/Rust-like | Ruby-like |
| Compiler Target | Erlang source / JS | Erlang abstract format |
| Macros | None | Powerful |
The decision to use Gleam often rests on the desire for strong static typing and a minimal syntax, even if the language lacks the mature libraries and macro-heavy frameworks that define the Elixir ecosystem. Because Gleam compiles to Erlang source rather than the abstract format Elixir uses, debugging tools such as code coverage and profiling provide less accurate line numbers than the native experience available to Elixir developers. Elixir remains the more mature and popular alternative for the BEAM because its ecosystem includes more libraries.
Full-stack and development reality
You already know that the BEAM is reliable for distributed systems and real-time messaging. Gleam adds a way to use those strengths with the addition of type safety. One advantage is the ability to compile Gleam to JavaScript, which allows teams to use the same language for backend domain logic and frontend code. This allows developers to share types between the backend and the frontend, which reduces runtime bugs. Using Gleam for both parts of the stack can reduce the duplication of effort in validation and data models. One can use the Lustre framework to build frontend components with ideas from Elm and Phoenix LiveView. This allows you to build a web app with no runtime exceptions if the project compiles. For those needing a web server, Mist is available in Gleam. You can also use Chip for a process registry similar to Syn and Bravo for ETS bindings. To use a database, you can make a library that targets both JavaScript and Erlang, such as a library for using SQLite that wraps an Erlang library for BEAM and a library for Deno when compiling to JavaScript. Gleam uses regular OTP, though it does not have a distinct OTP framework separate from other BEAM languages. You can use the untyped Erlang APIs if you wish, much like how Elixir users do. To run Gleam in a Phoenix project, you can use an Elixir GenServer to watch for file changes and trigger the Gleam compiler automatically. This setup allows for automatic recompilation when you edit files in the assets directory. You can also use FFI to wrap JavaScript, Erlang, or Elixir functions and call them in Gleam. Will Gleam’s ecosystem eventually match the massive reach of Phoenix? Developers interested in type safety on the BEAM can start by using the Gleam build tool to compile their first project.