O'Reilly logo

Programming Elixir by Dave Thomas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix 2Type Specifications and Type Checking

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?

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required