Lumenary CS · Programming languages
Erlang
The concurrent, fault-tolerant functional language born in Ericsson's telephone switches, and the OTP framework built around it, from a first program to professional practice.
Erlang is a functional programming language designed at Ericsson from 1986 for telephone switches that had to handle many calls at once, survive hardware and software faults, and be upgraded without stopping. It was released as open source in 1998 together with OTP, its libraries and design patterns for reliable servers. Erlang runs on the BEAM virtual machine, which also runs Elixir and Gleam, and it powers message brokers such as RabbitMQ, messaging servers such as ejabberd, databases such as CouchDB, and the back ends of large chat and payment services.
This course is for anyone who already knows what a variable, a loop and a function are: the Start level of Lumenary CS or equivalent experience in any language. No functional programming background is needed. It starts with the shell and a first escript, works through terms, pattern matching, recursion, lists, maps and binaries, and then turns to what makes Erlang unique: processes, message passing, links, monitors and supervision trees, the OTP behaviours gen_server, supervisor and application, hot code loading and distribution, ending with a complete small project.
To run the code, install Erlang/OTP from erlang.org/downloads, which links to installers for Windows and to package managers and source builds for macOS and Linux; the official Docker images are another option. There is no official online playground. Every complete program in these lessons is an escript that was run with escript main.erl on Erlang/OTP 29 by Lumenary's test suite, and the output shown is the output it printed. The lessons were drafted with AI assistance and are awaiting review by a human computer scientist.
- Chloe · The Designer
“Why is the language built this way?” - Margaret · The Profiler
“What does it print, and what does it cost?” - Gideon · The Language Lawyer
“What exactly does the language guarantee?”
Foundations · 3 lessons
Foundations
Meet Erlang's history and the BEAM, use the shell and escripts, and learn terms, single-assignment variables, pattern matching, functions, guards and recursion.
- 1Getting started with ErlangWhy a telephone company invented a programming language, what the BEAM and OTP are, and your first programs in the shell, as escripts and as compiled modules. 45 min
- 2Terms, variables and pattern matchingErlang's data types, single-assignment variables, the match operator, case expressions, and how strings, binaries and atoms really work. 50 min
- 3Functions, guards and recursionFunction clauses and guards, if and case, recursion with accumulators instead of loops, and funs as values for higher-order programming. 55 min
Practice · 3 lessons
Practice
Work with lists, tuples, maps and binaries, then build concurrent programs from processes, mailboxes and selective receive, and make them robust with errors, links and monitors.
- 4Lists, tuples, maps and binariesThe lists module and comprehensions old and new, records and maps for structured data, the bit syntax for binary protocols, iolists, and JSON. 60 min
- 5Processes, mailboxes and selective receiveSpawning processes, sending messages, the mailbox and selective receive, keeping state in a receive loop, registered names, and parallel work. 55 min
- 6Errors, links, monitors and supervisionErlang's three kinds of exception, try and catch, the "let it crash" philosophy, links and trapped exits, monitors, and a supervisor built by hand. 60 min
Professional · 2 lessons
Professional
Structure systems with the OTP behaviours gen_server, supervisor and application, understand hot code loading and distribution, and build a complete supervised project with tests and the rebar3 toolchain.
- 7OTP behaviours: gen_server, supervisor and applicationThe generic parts of servers, supervisors and applications that OTP provides, the callbacks you write, and how they fit into a supervision tree. 65 min
- 8Hot code loading, distribution and a complete projectReplacing code in a running system, connecting nodes into a cluster, the rebar3 toolchain with EUnit, Common Test and Dialyzer, and a supervised rate-limiting service with tests. 70 min
Further reading and resources
- erlang.orgThe official home of Erlang/OTP: downloads, news, documentation and community.
- Erlang/OTP documentationThe system guides and the reference documentation of every OTP application, for the current release.
- Erlang Reference ManualThe precise description of the language; Erlang has no separate standard, so this is its specification.
- Getting Started with ErlangThe official tutorial for sequential and concurrent programming.
- OTP Design PrinciplesThe official guide to behaviours, supervision trees, applications and releases.
- DownloadsInstallers, source releases and pointers to package managers.
- Learn You Some Erlang for Great Good! · Fred HébertA well-loved free book that covers the language and OTP in depth.
- rebar3The standard build tool and package manager for Erlang projects.