Type systems and inference
Problems
- Type checking problem
Given a typing context, a term and a type, decide whether the term has that type under the rules of a type system.
intro - Type inference problem
Given a term without type annotations, find types for its variables and the term that make it well typed, or report that none exist; ideally return a principal type.
core
Algorithms
- Algorithm W
Infers the principal type of an ML term bottom-up by unification, generalizing free type variables at each let binding.
1 languagescore - Algorithm J
An imperative form of Hindley-Milner inference that keeps one global substitution, updated in place by union-find unification.
1 languagesadvanced
Techniques
- Bidirectional type checking
Splits the typing judgment into a checking mode and a synthesis mode, so annotations are needed only where the two modes meet.
core - Monomorphization
Compiles a polymorphic function by making one specialized copy for each set of type arguments it is used at.
core - Constraint-based type inference
Splits inference into a pass that emits type constraints and a solver for them, so one inference engine serves many constraint domains.
advanced - Dictionary-passing translation
Compiles type class constraints into extra arguments that are records of the instance methods, chosen at each call site.
advanced - Borrow checking
Checks that each reference to owned memory lives no longer than its owner and that no mutable reference is aliased, without a garbage collector.
research - Liquid types
Infers refinement types by abstract interpretation over conjunctions of given qualifiers, with SMT queries to check each subtyping step.
research
Concepts
- Type system
A set of rules that assigns a type to each phrase of a program and rejects the programs whose phrases cannot be typed.
intro - Let-polymorphism
Polymorphism where only let-bound names get type schemes, and lambda-bound names stay monomorphic, which keeps inference decidable.
core - Subtyping
A relation S <: T saying a value of type S can be used wherever a T is expected; functions are contravariant in the argument, and records allow width and depth subtyping.
core - Type classes
Named sets of overloaded operations with instances per type, resolved during inference by constraints on type variables.
core - Dependent types
Types that depend on values, such as vectors of length n, so that types can state and check full program specifications.
advanced - Effect system
Extends types with effects, such as the regions a function reads or writes, to reason about side effects and to enable optimizations.
advanced - Gradual typing
Mixes static and dynamic typing in one language with an unknown type, consistency in place of equality, and run-time casts at the borders.
advanced - Linear types
Types whose values must be used exactly once, or at most once in the affine case, which supports safe in-place update and resources.
advanced - Recursive types
Types of the form mu a. T that refer to themselves, for lists, trees and objects; equi-recursive types equal their unfolding, while iso-recursive types need explicit fold and unfold.
advanced - Refinement types
Types that carry a logical predicate on their values, such as the integers greater than zero, checked with a decision procedure.
advanced - Row polymorphism
Types records and variants with a row variable for the unknown fields, so a function can accept any record that has some fields.
advanced
Definitions
- Hindley-Milner type system
The type system of ML, with type schemes that quantify type variables at let bindings, so that each typable term has a principal type.
core - Value restriction
Generalize the type of a let binding only when its right side is a syntactic value, which keeps polymorphism sound with mutable references.
advanced
Theorems
- Curry-Howard correspondence
Simple types are the formulas of intuitionistic implicational logic, typed lambda terms are its natural deduction proofs, and beta reduction is the removal of detours from proofs.
core - Principal type theorem
Every typable ML term has a principal type scheme of which all its other types are instances, and algorithm W computes it.
core - Type soundness
A well-typed closed term never reaches a stuck state. For the simply typed lambda calculus it follows from progress (a value or a step) and preservation (a step keeps the type).
core - DEXPTIME-completeness of ML typability
Deciding whether an ML program is typable is complete for deterministic exponential time, since nested lets can double type sizes.
advanced - Undecidability of type inference for System F
Without type annotations, no algorithm decides whether a pure lambda term has a System F type, or whether it has a given type. Wells proved it in 1994 by a reduction from semi-unification.
advanced - Undecidability of polymorphic recursion
Type inference for ML with polymorphic recursion is undecidable, as it is equivalent to semi-unification.
research
Models
- Simply typed lambda calculus
The lambda calculus with base types and function types; each well-typed term has a unique type, evaluation never gets stuck, and every reduction sequence terminates.
core - System F
The simply typed lambda calculus with abstraction over types, so one term works at every type. It is strongly normalizing, and Church-style checking is decidable but Curry-style typing is not.
core