Type Inference
Type inference automatically deduces expression types without explicit annotations; the Hindley-Milner algorithm is the foundation of functional languages.
Purpose
Reduce annotation burden while keeping static type safety.
Mechanism
Hindley-Milner: derives the most general type (principal type) via unification. Algorithm W generates type constraints from expressions and unifies them. Rust uses an HM variant plus lifetimes. TypeScript uses structural type inference.
Use cases
- Functional languages
- Rust type deduction
- TypeScript inference