What if you could have Rust's type safety with Elixir's concurrency and JavaScript's friendliness? That's Gleam.
What Is Gleam?
Gleam is a type-safe functional language that runs on the BEAM (Erlang VM) and compiles to JavaScript. It combines:
- Erlang/Elixir's legendary concurrency and fault tolerance
- ML-family type system (like Rust, but friendlier)
- Clean, Python-like syntax
- Zero runtime errors from type mismatches
import gleam/io
pub fn main() {
io.println("Hello from Gleam!")
}
Type Safety Without the Pain
// Types are inferred — you rarely need annotations
pub fn add(a: Int, b: Int) -> Int {
a + b
}
// Custom types (like Rust enums)
pub type Shape {
Circle(radius: Float)
Rectangle(width: Float, height: Float)
Triangle(base: Float, height: Float)
}
pub fn area(shape: Shape) -> Float {
case shape {
Circle(r) -> 3.14159 *. r *. r
Rectangle(w, h) -> w *. h
Triangle(b, h) -> 0.5 *. b *. h
}
}
// Compiler ensures ALL cases are handled. Miss one → compile error.
Web Server (Wisp Framework)
import wisp
import gleam/http
pub fn handle_request(req: wisp.Request) -> wisp.Response {
case wisp.path_segments(req) {
["api", "users"] -> list_users(req)
["api", "users", id] -> get_user(req, id)
_ -> wisp.not_found()
}
}
fn list_users(_req: wisp.Request) -> wisp.Response {
let users = "[{"name": "Alice"}, {"name": "Bob"}]"
wisp.json_response(string_tree.from_string(users), 200)
}
Why Gleam
- BEAM runtime — millions of concurrent connections, hot code reloading, fault tolerance
- No null, no exceptions — Result types for errors, Option for absence
- JavaScript target — share code between server and browser
- Interop — call Erlang/Elixir libraries directly
- Fast compilation — compiles in milliseconds
Gleam vs Elixir
| Feature | Elixir | Gleam |
|---|---|---|
| Type system | Dynamic | Static |
| Runtime errors | Common | Rare |
| IDE support | Basic | Excellent (types!) |
| BEAM ecosystem | Full access | Full access |
| Learning curve | Medium | Low |
gleam new my_project && cd my_project && gleam run
Building type-safe systems? Check out my developer tools or email spinov001@gmail.com.
Top comments (0)