Gleam Introduction
Gleam is a modern programming language built for safety and speed. It runs on the Erlang virtual machine (BEAM) and also compiles to JavaScript. This makes Gleam useful for building web servers, APIs, and even frontend applications — all from one language.
What Makes Gleam Different
Most programming languages either focus on safety or speed. Gleam delivers both. It uses a strong static type system, which means the compiler catches your mistakes before the program even runs. You never spend hours debugging a bug that the compiler already knew about.
Think of the Gleam compiler as a strict but helpful editor. Before your book goes to print, the editor reads every sentence and flags every grammar mistake. Gleam's compiler does the same for your code.
The BEAM Virtual Machine
Gleam runs on the BEAM — the same engine that powers Erlang and Elixir. The BEAM handles millions of tiny tasks at the same time without crashing. Large companies like WhatsApp and Discord use BEAM-based systems to serve billions of messages.
BEAM Virtual Machine
┌────────────────────────────────────┐
│ Erlang │ Elixir │ Gleam │
│ (old) │ (modern)│ (typed+modern) │
└────────────────────────────────────┘
↓ all run on BEAM ↓
┌────────────────────────────────────┐
│ Handles millions of processes │
│ Fault-tolerant & self-healing │
│ Used in telecom & messaging apps │
└────────────────────────────────────┘
JavaScript Target
Gleam also compiles to JavaScript. You can write one Gleam program and run it in the browser or on Node.js. This dual-target capability makes Gleam a full-stack language.
Why Learn Gleam
Gleam brings three major advantages to developers:
1. No Null Errors
Languages like Java and Python allow a variable to hold "nothing" (null or None). Accessing a null value crashes the program at runtime. Gleam eliminates null entirely. Instead, it uses the Option type, which forces you to handle both "value present" and "value absent" cases in your code.
2. No Runtime Type Errors
Gleam checks every type at compile time. A function that expects a number will never receive a text string at runtime. You know what you get — always.
3. Friendly Error Messages
Gleam's compiler writes error messages in plain English. It tells you what went wrong, where it went wrong, and often suggests how to fix it. Many languages produce cryptic errors — Gleam does not.
Example: Friendly Gleam Error
─────────────────────────────
error: Type mismatch
→ src/main.gleam:5
Expected: Int
Found: String
Hint: You passed "hello" where a number was needed.
Gleam vs Other Languages
Feature Comparison
──────────────────────────────────────────────
Feature │ Gleam │ Python │ JavaScript
─────────────────┼───────┼────────┼───────────
Static Types │ Yes │ No │ No
Null Safety │ Yes │ No │ No
Runs on BEAM │ Yes │ No │ No
Runs in Browser │ Yes │ No │ Yes
Friendly Errors │ Yes │ Some │ Some
Gleam is not a replacement for Python or JavaScript. It fills a different role — reliable, concurrent server-side software where crashes cost money and users expect zero downtime.
What You Can Build with Gleam
Gleam suits several types of projects:
Web APIs and Servers
Gleam handles thousands of web requests at the same time. The BEAM makes this possible without extra effort from the developer. Frameworks like Wisp and Mist provide routing and HTTP handling.
Real-Time Applications
Chat apps, live scoreboards, and notifications need instant data updates. Gleam's process model — inherited from Erlang — makes real-time features straightforward to build.
Microservices
Gleam compiles to small, fast binaries. Teams building microservices use Gleam to write individual services that communicate with each other reliably.
Frontend and Full-Stack Apps
Because Gleam compiles to JavaScript, you can use libraries like Lustre to build browser-based user interfaces in Gleam.
Gleam's Design Philosophy
The creators of Gleam followed one guiding principle: make the wrong thing hard and the right thing easy. Bad patterns — like ignoring errors or mixing types — become compile errors, not silent bugs.
Gleam also prioritizes readability. Code written six months ago should still make sense when you read it today. The language avoids clever tricks that look impressive but confuse readers later.
A Snapshot of Gleam Code
Here is a simple Gleam function to give you a taste of the syntax. Do not worry about understanding every detail — later topics cover each part in full.
import gleam/io
pub fn greet(name: String) -> String {
"Hello, " <> name <> "!"
}
pub fn main() {
io.println(greet("World"))
}
This program defines a function called greet that takes a name and returns a greeting. The main function calls greet and prints the result. The output is: Hello, World!
The Gleam Ecosystem
Gleam uses a package manager called Hex, shared with the Erlang and Elixir communities. Thousands of packages are available, covering databases, HTTP clients, JSON parsing, and more.
The build tool, also called gleam, handles project creation, dependency management, compilation, testing, and formatting from one command-line interface. You do not need separate tools for each task.
Community and Maturity
Gleam reached its stable 1.0 release in 2024. The community is active on the Gleam Discord server and the official forum. The language maintainers publish a detailed changelog and roadmap, so you always know what comes next.
Gleam is a young language compared to Python or Java, but it runs on the battle-tested BEAM — a platform with over 35 years of production use.
