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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.