Introduction

Why Gleam?

Every programmer eventually runs into a project where threads behave strangely, a server falls over at three in the morning, or refactoring breaks something in a module nobody touched. Gleam addresses all three problems with two design decisions: make illegal states impossible to represent, and run everything on a runtime built for failure.

Who This Tutorial Is For

This tutorial assumes you are comfortable with Python: you can write functions, work with lists and dictionaries, and read a stack trace. It does not assume any experience with:

If you have written some JavaScript or another scripting language and can follow Python examples, you will be fine. The explanations throughout these lessons compare Gleam's approach to Python equivalents, so you have a concrete anchor for each new idea.

The BEAM in Thirty Seconds

Setting Up

gleam new hello_gleam
cd hello_gleam
gleam run
i
hello_gleam/                    # project root directory
├── README.md                   # project description
├── gleam.toml                  # project name, version, and dependencies
├── src                         # all project source code is under 'src'
│   └── hello_gleam.gleam       # entry point
└── test                        # all project test code is under 'test'
    └── hello_gleam_test.gleam  # tests using 'gleeunit'

Lesson Structure

A Few Differences Between Gleam and Python Syntax

Check Understanding

What does "statically typed" mean in practice?

In a statically typed language, the type of every expression is known at compile time before the program runs. The compiler rejects programs where you add an integer to a string, pass the wrong number of arguments to a function, or forget to handle an error. Python determines types at runtime, so these mistakes surface as exceptions during execution. Gleam determines types at compile time, so many mistakes never make it into a running program. The trade-off is that you must think about types explicitly as you are writing code.

What are the key features of the BEAM runtime?

The BEAM runs many lightweight processes concurrently on all available CPU cores, with no shared memory between them. A crash in one BEAM process cannot corrupt any other process's state. This isolation is why BEAM-based systems can use supervisors that restart failed components automatically, without restarting the entire application.