Skip to content

Set-theoretic types cheatsheet ​

Source: Elixir cheatsheet, Set-theoretic types.

A type is a set of values. The type language has set operators that combine those sets.

Set operators ​

Types combine as sets do: or, and, and not.
OperatorSyntaxMeaning
Uniontype1 or type2values in either type
Intersectiontype1 and type2values in both types
Differencetype1 and not type2values in the first type but not in the second type
Negationnot typeevery value that is not in the type

Data types ​

The broad types and how they nest.

Broad types ​

bitstring(), binary(), empty_list(), integer(), float(), pid(), port(), reference().

binary() is a subtype of bitstring().

Atoms ​

TypeMatches
atom()all AtomA constant with a value that is its own name, such as :ok. Two atoms are equal if their names are equal.Read the page · Glossary
:ok, :error, SomeModuleone atom each

Functions ​

TypeMeaning
function()all functions
(-> :ok)a function with no arguments that returns :ok
(integer() -> boolean())a function with one argument
(binary(), binary() -> binary())a function with two arguments
(integer() -> binary()) and (binary() -> atom())a function with multiple clauses

An intersection of function types describes one function with several clauses:

Each clause applies to its own argument type.

Maps ​

TypeMeaning
map()all maps
empty_map()the empty map

Maps with atom keys

elixir
# Only has the keys name and age
%{name: binary(), age: integer()}

# Has the name key and age is optional
%{name: binary(), age: if_set(integer())}

# Has the keys name and age and may have other keys (open map)
%{..., name: binary(), age: integer()}

# Has the key name, may have other keys, but age is not set
%{..., name: binary(), age: not_set()}
The values that each map type accepts.

Maps with domain keys (always optional)

elixir
# Has atom and binary keys
%{atom() => binary(), binary() => binary()}

# ...and may have other keys (open map)
%{..., atom() => binary(), binary() => binary()}

Maps with mixed keys

elixir
# atom keys with binary values, but a :root key of type integer
%{atom() => binary(), root: integer()}

# ...and may have other keys
%{..., atom() => binary(), root: integer()}

The domain key types are atom(), binary(), integer(), float(), fun(), list(), map(), pid(), port(), reference(), and tuple().

Non-empty lists ​

TypeMeaning
non_empty_list(elem_type)a proper list
non_empty_list(elem_type, tail_type)an improper list, as long as tail_type does not include lists
A proper list ends in []. An improper list ends in another value.

Tuples ​

TypeMeaning
tuple()all TupleA fixed collection with curly brackets that can hold any value. Its elements are stored one after the other in memory, so it is fast to read one element by index or to get the size.Read the page · Glossary
{:ok, binary()}, {:error, binary(), term()}, {pid(), reference()}tuples of exactly n elements
{binary(), binary(), ...}tuples of at least n elements

Extra types for convenience ​

AliasDefinition
boolean()true or false
number()integer() or float()
list()empty_list() or non_empty_list(term())
list(a)empty_list() or non_empty_list(a)
list(a, b)empty_list() or non_empty_list(a, b)

Site code: MIT. Pages and diagrams come from the Elixir documentation (Apache-2.0, snapshot of 2026-10-08, Elixir 1.20). This project is not affiliated with the Elixir Team.