Appendix 2
Type Specifications and Type Checking

When we looked at @callback,, we saw that we defined callbacks in terms of their parameter types and return values. For example, we might write

 @callback parse(uri_info :: URI.Info.t) :: URI.Info.t
 @callback 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 great 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?