Erlang Type Notation

So far, we have introduced types through informal descriptions. To make full use of the type system, we need to understand the type grammar so we can read and write more precise type descriptions.

The Grammar of Types

Types are defined informally using the following syntax:

 
T1 :: A | B | C ...

This means that T1 is defined to be one of A, B, or C.

Using this notation, we can define a subset of Erlang types as follows:

 
Type :: any() | none() | pid() | port() | reference() | []
 
| Atom | binary() | float() | Fun | Integer | [Type] |
 
| Tuple | Union | UserDefined
 
 
Union :: Type1 | Type2 | ...
 
 
Atom :: atom() | Erlang_Atom
 
 
Integer :: integer() | Min .. Max
 
 
Fun :: fun() | fun((...) -> Type)
 
 
Tuple :: tuple() ...

Get Programming Erlang, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.