Math 2.0

Computer science Definition

Type inference

Builds on Type systemSimply typed lambda calculusSubstitutionUnification

Definition

Let a type system be given by a typing relation Γ⊢t:τ\Gamma \vdash t : \tau between contexts, terms and types. Type inference, also called type reconstruction, is the following computational problem. The input is a context Γ\Gamma and a term tt, possibly without type annotations. The task is to decide whether some type τ\tau satisfies Γ⊢t:τ\Gamma \vdash t : \tau, and if so to output one such τ\tau.

Suppose that types may contain type variables. A type τ\tau of tt in Γ\Gamma is principal if every type of tt in Γ\Gamma is a substitution instance of τ\tau. That is, it arises from τ\tau by putting types in place of its type variables.

Remarks

Example: in the Curry-style simply typed lambda calculus with type variables, take t=λf. λx. f xt = \lambda f.\, \lambda x.\, f\, x and the empty context. Give ff the type α\alpha and xx the type β\beta; the application f xf\, x forces α=β→γ\alpha = \beta \to \gamma. So tt has the principal type (β→γ)→β→γ(\beta \to \gamma) \to \beta \to \gamma, and each other type, such as (𝖻→𝖻)→𝖻→𝖻(\mathsf{b} \to \mathsf{b}) \to \mathsf{b} \to \mathsf{b}, is a substitution instance of it. For this calculus the constraints are equations between types, and first-order unification solves them, so inference is decidable.

Non-example: the term λx. x x\lambda x.\, x\, x has no type in the simply typed calculus. Inference reaches the equation α=α→β\alpha = \alpha \to \beta, which fails the occurs check of unification, and the algorithm reports that there is no type.

Type inference differs from type checking, which is the problem of deciding Γ⊢t:τ\Gamma \vdash t : \tau for a given τ\tau. For the Curry-style System F, J. B. Wells proved that both problems are undecidable.

Reading path

To understand this page from the ground up, read these 27 pages in order. The foundations come first.

Show the path as a graph
Element, definition, no evidence levelElementdefinitionIntuitionistic logic, concept, no evidence levelIntuitionistic logicconceptLambda calculus, concept, no evidence levelLambda calculusconceptProposition, concept, no evidence levelPropositionconceptSet, concept, no evidence levelSetconceptSubstitution, concept, no evidence levelSubstitutionconceptType system, concept, no evidence levelType systemconceptUnification, concept, no evidence levelUnificationconceptSet, definition, no evidence levelSetdefinitionConjunction, definition, no evidence levelConjunctiondefinitionDisjunction, definition, no evidence levelDisjunctiondefinitionImplication, definition, no evidence levelImplicationdefinitionNegation, definition, no evidence levelNegationdefinitionBiconditional, definition, no evidence levelBiconditionaldefinitionTruth table, concept, no evidence levelTruth tableconceptModus ponens, concept, no evidence levelModus ponensconceptMathematical proof, concept, no evidence levelMathematical proofconceptPropositional logic, concept, no evidence levelPropositional logicconceptTautology, definition, no evidence levelTautologydefinitionLogical equivalence, definition, no evidence levelLogical equivalencedefinitionDouble negation law, statement, no evidence levelDouble negation lawstatementProof by contradiction, concept, no evidence levelProof by contradictionconceptRussell's paradox, statement, no evidence levelRussell's paradoxstatementType theory, concept, no evidence levelType theoryconceptCurry–Howard correspondence, concept, no evidence levelCurry–Howard correspo…conceptSimply typed lambda calculus, concept, no evidence levelSimply typed lambda c…conceptType inference, definition, no evidence levelType inferencedefinition
Each page uses the pages above it. The colour of the bar on a box shows how strong the evidence is, and the box also gives it as text. The list has the same pages.
  • no evidence level
  1. Element definition
  2. Intuitionistic logic concept
  3. Lambda calculus concept
  4. Proposition concept
  5. Set concept
  6. Substitution concept
  7. Type system concept
  8. Unification concept
  9. Set definition
  10. Conjunction definition
  11. Disjunction definition
  12. Implication definition
  13. Negation definition
  14. Biconditional definition
  15. Truth table concept
  16. Modus ponens concept
  17. Mathematical proof concept
  18. Propositional logic concept
  19. Tautology definition
  20. Logical equivalence definition
  21. Double negation law statement
  22. Proof by contradiction concept
  23. Russell's paradox statement
  24. Type theory concept
  25. Curry–Howard correspondence concept
  26. Simply typed lambda calculus concept
  27. Type inference definition

Further reading

  1. Web https://en.wikipedia.org/wiki/Type_inference
About this page
TagE7YW37TGAY
URIm2://E7YW37TGAY
Kinddefinition
WritingW0 stub
MSC68N15, 68N18, 03B40
DefinesType inference
UsesType system, Simply typed lambda calculus, Substitution, Unification
Changed3 November 2026

Markdown · JSON · Edit on GitHub

What this page needs for W1

  • an inventory row: the row of the inventory that the node accounts for (0 of 1)
  • a source with a locator (0 of 1)

The writing levels say how complete the text of a page is. They do not measure its truth.

What links here

No page links to this page yet.