I found the following resources helpful for understanding type inference, in order of increasing difficulty:
- Chapter 30 (Type Inference) of the freely available book PLAI, Programming Languages: Application and Interpretation, sketches unification-based type inference.
- The summer course Interpreting types as abstract values presents elegant evaluators, type checkers, type reconstructors and inferencers using Haskell as a metalanguage.
- Chapter 7 (Types) of the book EOPL, Essentials of Programming Languages.
- Chapter 22 (Type Reconstruction) of the book TAPL, Types and Programming Languages, and the corresponding OCaml implementations recon and fullrecon.
- Chapter 13 (Type Reconstruction) of the new book DCPL, Design Concepts in Programming Languages.
- Selection of academic papers.
- Closure compiler’s TypeInference is an example of the data-flow analysis approach to type inference, which is better suited to dynamic languages that the Hindler Milner approach.
However, since the best way to learn is to do, I strongly suggest implementing type inference for a toy functional language by working through a homework assignment of a programming languages course.
I recommend these two accessible homeworks in ML, which you can both complete in less than a day:
- PCF Interpreter (a solution) to warm up.
- PCF Type Inference (a solution) to implement algorithm W for Hindley-Milner type inference.
These assignments are from a more advanced course:
-
Implementing MiniML
-
Polymorphic, Existential, Recursive Types (PDF)
-
Bi-Directional Typechecking (PDF)
-
Subtyping and Objects (PDF)