October 2014
Intermediate to advanced
280 pages
7h 20m
English
When we looked at defcallback,, we saw that we defined callbacks in terms of their parameter types and return value. For example, we might write
| | defcallback parse(uri_info :: URI.Info.t) :: URI.Info.t |
| | defcallback default_port() :: integer |
The terms URI.Info.t and integer are examples of type specifications. And, as José Valim pointed out to me, the cool thing is that they are implemented (by Yurii Rashkovskii) directly in the Elixir language itself—no special parsing is involved. This is a fantastic illustration of the power of Elixir metaprogramming.
In this appendix we’ll discuss how to specify types in Elixir. But before we do, there’s another question to address: Why bother?
Read now
Unlock full access