Modern Erlang tour
| Types and specs | |
| Dialyzer | |
| Modern habits |
Types and specs
Type specifications attach types to function heads. The -type directive defines a new type, and -spec attaches it to a function. Dialyzer uses these to find common bugs without running the code.
-type maybe(Normal | Error).
-spec add(Normal) -> maybe.
add(X) when is_number(X) -> X + 1.
add(_) -> error.
Next: Hero roadmap: the whole course on one page
Article author: Arthur Isaev