Math 2.0

Computer science Definition

Hindley–Milner type system

Builds on Simply typed lambda calculusType inferenceSubstitutionUnification

Definition

Fix a set of type variables α,β,…\alpha, \beta, \dots and a set of type constructors containing the arrow →\to. The monotypes are τ::=α∣C τ1⋯τn\tau ::= \alpha \mid C\, \tau_1 \cdots \tau_n, where CC is a type constructor of arity nn; in particular τ1→τ2\tau_1 \to \tau_2 is a monotype. The type schemes are σ::=τ∣∀α. σ\sigma ::= \tau \mid \forall \alpha.\, \sigma. The terms are e::=x∣e e∣λx. e∣𝗅𝖾𝗍 x=e 𝗂𝗇 ee ::= x \mid e\, e \mid \lambda x.\, e \mid \mathsf{let}\ x = e\ \mathsf{in}\ e. A context Γ\Gamma assigns type schemes to finitely many variables. A monotype τ\tau is an instance of ∀α1…αn. τ0\forall \alpha_1 \dots \alpha_n.\, \tau_0 if τ=τ0[τ1/α1,…,τn/αn]\tau = \tau_0[\tau_1/\alpha_1, \dots, \tau_n/\alpha_n] for some monotypes τi\tau_i. The typing relation Γ⊢e:τ\Gamma \vdash e : \tau of the Hindley–Milner type system is the least relation closed under these rules.

  1. Variable: if x:σx : \sigma is in Γ\Gamma and τ\tau is an instance of σ\sigma, then Γ⊢x:τ\Gamma \vdash x : \tau.
  2. Application: if Γ⊢e1:τ1→τ2\Gamma \vdash e_1 : \tau_1 \to \tau_2 and Γ⊢e2:τ1\Gamma \vdash e_2 : \tau_1, then Γ⊢e1 e2:τ2\Gamma \vdash e_1\, e_2 : \tau_2.
  3. Abstraction: if Γ,x:τ1⊢e:τ2\Gamma, x : \tau_1 \vdash e : \tau_2 with τ1\tau_1 a monotype, then Γ⊢λx. e:τ1→τ2\Gamma \vdash \lambda x.\, e : \tau_1 \to \tau_2.
  4. Let: if Γ⊢e1:τ1\Gamma \vdash e_1 : \tau_1 and Γ,x:genΓ(τ1)⊢e2:τ2\Gamma, x : \mathrm{gen}_\Gamma(\tau_1) \vdash e_2 : \tau_2, then Γ⊢𝗅𝖾𝗍 x=e1 𝗂𝗇 e2:τ2\Gamma \vdash \mathsf{let}\ x = e_1\ \mathsf{in}\ e_2 : \tau_2.

Here genΓ(τ1)=∀α1…αn. τ1\mathrm{gen}_\Gamma(\tau_1) = \forall \alpha_1 \dots \alpha_n.\, \tau_1, where α1,…,αn\alpha_1, \dots, \alpha_n are the type variables free in τ1\tau_1 but not free in Γ\Gamma.

Remarks

Example: ⊢𝗅𝖾𝗍 i=λx. x 𝗂𝗇 i i:β→β\vdash \mathsf{let}\ i = \lambda x.\, x\ \mathsf{in}\ i\, i : \beta \to \beta. The check: rule 3 gives λx. x:α→α\lambda x.\, x : \alpha \to \alpha, and rule 4 gives ii the scheme ∀α. α→α\forall \alpha.\, \alpha \to \alpha. By rule 1 the first ii gets the instance (β→β)→β→β(\beta \to \beta) \to \beta \to \beta and the second gets β→β\beta \to \beta, so rule 2 gives i i:β→βi\, i : \beta \to \beta.

Non-example: λi. i i\lambda i.\, i\, i has no type. Rule 3 gives the bound variable ii a single monotype τ1\tau_1, and i ii\, i would need τ1=τ1→τ2\tau_1 = \tau_1 \to \tau_2, which no monotype satisfies. So polymorphism is available for 𝗅𝖾𝗍\mathsf{let}-bound names but not for λ\lambda-bound ones.

Algorithm W of Damas and Milner computes a principal type of every typable term by unification of monotypes. This makes type inference decidable for the system.

Reading path

To understand this page from the ground up, read these 28 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 levelNegationdefinitionType inference, concept, no evidence levelType inferenceconceptBiconditional, 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…conceptHindley–Milner type system, definition, no evidence levelHindley–Milner type s…definition
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. Type inference concept
  15. Biconditional definition
  16. Truth table concept
  17. Modus ponens concept
  18. Mathematical proof concept
  19. Propositional logic concept
  20. Tautology definition
  21. Logical equivalence definition
  22. Double negation law statement
  23. Proof by contradiction concept
  24. Russell's paradox statement
  25. Type theory concept
  26. Curry–Howard correspondence concept
  27. Simply typed lambda calculus concept
  28. Hindley–Milner type system definition

Further reading

  1. Web https://en.wikipedia.org/wiki/Hindley–Milner_type_system
About this page
TagAPWK8VAXGD
URIm2://APWK8VAXGD
Kinddefinition
WritingW0 stub
MSC68N18, 68N15, 03B40
DefinesHindley–Milner type system
UsesSimply typed lambda calculus, Type inference, 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.