Skip to content

Erlang Data Types — Numbers, Atoms, Tuples, Lists, Maps, and Binaries

DodaTech Updated 2026-06-29 2 min read

In this tutorial, you will learn about Erlang Data Types. We cover key concepts, practical examples, and best practices to help you master this topic.

Erlang was designed for concurrent, fault-tolerant systems. Its data types reflect this — immutability by default, pattern matching everywhere, and efficient binary handling for network protocols.

In this tutorial, you'll explore Erlang's type system. Erlang powers telecom switches, messaging systems, and databases. DodaTech evaluates Erlang for high-reliability security infrastructure.

What You'll Learn

  • Integers (arbitrary precision)
  • Floats
  • Atoms (named constants)
  • Tuples for fixed collections
  • Lists (linked lists)
  • Maps (key-value)
  • Binaries and bitstrings

Numbers

%% Integers (unbounded precision)
42.
-17.
1073741824.

%% Floats
3.14.
-0.5.
1.0e-10.

%% Operations
10 + 3.      %% => 13
10 - 3.      %% => 7
10 * 3.      %% => 30
10 / 3.      %% => 3.3333333333333335 (float division)
10 div 3.    %% => 3 (integer division)
10 rem 3.    %% => 1 (remainder)

%% Math functions (from math module)
math:sqrt(16).   %% => 4.0
math:pi().       %% => 3.14159...

Atoms

%% Atoms are named constants (similar to symbols)
hello.
'Hello World'.  %% Atom with special chars needs quotes
true.           %% Boolean atoms
false.
ok.             %% Convention: success
error.          %% Convention: failure
undefined.

%% Atoms ARE booleans
true =:= true.  %% => true

Tuples

%% Fixed-size, ordered collection
Person = {alice, 30, engineer}.
{Age, Name} = {30, alice}.  %% Error: different arity

%% Pattern matching
{Name, Age, Role} = Person.
Name.   %% => alice
Age.    %% => 30
Role.   %% => engineer

%% Common patterns
{ok, Content} = file:read_file("test.txt").
{error, Reason} = file:read_file("missing.txt").

Lists

%% Lists (linked lists)
[1, 2, 3, 4].
[alice, bob, charlie].

%% Head and tail
[Head | Tail] = [1, 2, 3, 4].
Head.  %% => 1
Tail.  %% => [2, 3, 4]

%% Building lists
[0 | [1, 2, 3]].   %% => [0, 1, 2, 3] (cons)
[1, 2] ++ [3, 4].  %% => [1, 2, 3, 4] (append)

%% List operations
length([1, 2, 3]).          %% => 3
lists:map(fun(X) -> X*2 end, [1, 2, 3]).  %% => [2, 4, 6]
lists:filter(fun(X) -> X > 1 end, [1, 2, 3]).  %% => [2, 3]

%% Strings are lists of integers
"hello".  %% Equivalent to [$h, $e, $l, $l, $o]

Maps

%% Key-value maps (since Erlang 17)
User = #{name => alice, age => 30, role => engineer}.

%% Access
maps:get(name, User).       %% => alice
maps:get(city, User, unknown).  %% => unknown (default)

%% Update (returns new map)
Updated = User#{age => 31}.

%% Pattern matching
#{name := Name} = User.
Name.  %% => alice

Practice Questions

  1. Create a tuple representing a book (title, author, year) and extract each field.

  2. Write a pattern that extracts the first 3 elements from a list.

  3. Use a map to represent a user and update their age.

  4. Write a function using pattern matching on {:ok, Value} and {:error, Reason}.

  5. Use lists:map to convert a list of integers to their string representations.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro