Course

Erlang from the ground up

Small modules, matching instead of assignment, and no loops in sight

  • Beginner
  • 12 chapters
  • 207 min read

Learn Erlang by writing it: modules and main/1, atoms and numbers and text, the equals sign that matches, function heads and guards, case and if, lists walked by head and tail, tuples, maps with maps:get, the lists module, funs and higher-order functions, try and catch and throw, ending with a small sales report that folds, sorts and prints.

What You'll Learn

  • Write a module that exports main/1 and prints with io:format
  • Tell atoms, whole numbers, decimals and strings apart, and print each one
  • Match a value against a pattern, unpack its shape, and test a bound name
  • Write several clauses for one function and narrow them with guards
  • Choose between case and if, and know that if needs a final true clause
  • Walk a list with the empty case and the head and tail case
  • Group fixed values in a tuple and read them by position or by pattern
  • Store records in maps, read them with maps:get, and change one key safely
  • Ask a list questions with map, filter, foldl, sum, sort and seq
  • Hold a function in a value, pass it to another function and return one
  • Handle a failing division and a thrown signal without stopping the program
  • Assemble a report from maps, a fold, a sort and formatted money columns

Prerequisites

  • No programming experience needed — this course starts at the first line
  • Any other language you know will make the early chapters quick

Course Content

  1. 01
    Your first Erlang

    What an Erlang file actually is: a module, an exported entry point called main/1, and io:format writing the answers out.

    Beginner · 14 min read

    Not started
  2. 02
    Values: atoms, numbers and text

    The handful of values Erlang has — atoms, whole numbers, decimals, strings and booleans — and the two different divisions and two different ways of printing text.

    Beginner · 15 min read

    Not started
  3. 03
    Pattern matching: the equals sign that matches

    The equals sign does not assign, it matches. How to bind a name, unpack a shape you already know, and pin a name to the value it holds.

    Beginner · 16 min read

    Not started
  4. 04
    Function heads and guards

    One function name can have several heads. Erlang picks the first one whose pattern matches and whose guards are true, which is how most decisions are really made.

    Beginner · 16 min read

    Not started
  5. 05
    Decisions: case and if

    The two decisions inside a function body: case, which matches a value against several patterns, and if, which is a ladder of guards with a required final true.

    Intermediate · 17 min read

    Not started
  6. 06
    Lists and recursion

    A list is a head and a tail. Two clauses — one for the empty list, one that takes the head and asks again about the tail — are how Erlang walks a list without a loop.

    Intermediate · 18 min read

    Not started
  7. 07
    Tuples: fixed groups of values

    A tuple groups a fixed number of values under one term, and is matched by position. Tagged tuples like {ok, Value} are how Erlang functions hand back an answer and its reason together.

    Intermediate · 15 min read

    Not started
  8. 08
    Maps: records with names

    A map is a set of keys and values, read by name with maps:get. Updating one key writes a new map and leaves the old one as it was.

    Intermediate · 19 min read

    Not started
  9. 09
    The lists module

    map, filter, foldl, sum, sort and seq: the toolbox that does the walking for you, once you can read the two clauses it is built from.

    Intermediate · 18 min read

    Not started
  10. 10
    Funs and higher-order functions

    A fun is a function you can hold in a variable, pass to another function and get back. Funs remember the values they were made with, which is what makes map and foldl expressive.

    Advanced · 19 min read

    Not started
  11. 11
    Errors: try, catch and throw

    Errors in Erlang are values with a class. try runs code that might fail, catch says what to do about each class, and throw is a signal you can raise and catch yourself.

    Advanced · 18 min read

    Not started
  12. 12
    Putting it together: a sales report

    A capstone that uses most of the course: orders as maps, one foldl that aggregates them by item, a sorted list of rows, money rounded to two places, and a report with a footer.

    Pro · 22 min read

    Not started