Type Inference and Success Typing

Some of the errors the dialyzer produces are pretty strange. To understand these errors, we have to understand the process by which the dialyzer derives the types of Erlang functions. Understanding this will help us interpret these cryptic error messages.

Type inference is the process of deriving the types of a function by analyzing the code. To do this, we analyze the program looking for constraints; from the constraints, we build a set of constraint equations, and then we solve the equations. The result is a set of types that we call the success typing of the program. Let’s look at a simple module and see what it tells us.

dialyzer/types1.erl
 
-module​(types1).
 
-export​([f1/1, f2/1, f3/1]).
 
 
f1({H,M,S}) ...

Get Programming Erlang, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.