15-312 Foundations of Programming Languages
Lecture 19: Type Inference
After analyzing the process of bottom-up type synthesis in Lecture 17,
we generalize this rather rigid scheme in two ways. The first, more
robust scheme, is bidirectional type-checking where we
combine synthesis of types from expression with the checking of
an expression against a given type. This allows more concise
program than pure synthesis without being excessively burdensome
to the programmer.
The second method is full inference. Here the expressions contain
no types at all and we compute a most general type. This proceeds
by collection a set of constraints and then solving them to obtain
the type schema that captures all types the expression can have.
Type inference puts the least burden on the programmer, but scales
only with difficulty or not at all to type systems with advanced
constructs (subtyping, universal, existential, and recursive types).