Math 2.0

Computer science Type theory Theorem

Type safety

Builds on Simply typed lambda calculusOperational semanticsType systemStrong normalization of simply typed lambda calculus

Statement

Consider the simply typed lambda calculus with a base type π–‘π—ˆπ—ˆπ—…\mathsf{Bool}, constants π—π—‹π—Žπ–Ύ,π–Ώπ–Ίπ—…π—Œπ–Ύ:π–‘π—ˆπ—ˆπ—…\mathsf{true}, \mathsf{false} : \mathsf{Bool}, and conditionals 𝗂𝖿 t1 𝗍𝗁𝖾𝗇 t2Β π–Ύπ—…π—Œπ–ΎΒ t3\mathsf{if}\ t_1\ \mathsf{then}\ t_2\ \mathsf{else}\ t_3 typed by the usual rule. The values are π—π—‹π—Žπ–Ύ\mathsf{true}, π–Ώπ–Ίπ—…π—Œπ–Ύ\mathsf{false} and the abstractions Ξ»x:Ο„. t\lambda x{:}\tau.\, t. Let β†’\to be the call-by-value small-step operational semantics on terms.

  1. Progress: if ⊒t:Ο„\vdash t : \tau with the empty context, then tt is a value or there is a term tβ€²t' with tβ†’tβ€²t \to t'.
  2. Preservation: if Ξ“βŠ’t:Ο„\Gamma \vdash t : \tau and tβ†’tβ€²t \to t', then Ξ“βŠ’tβ€²:Ο„\Gamma \vdash t' : \tau.

Hence, if ⊒t:Ο„\vdash t : \tau and tβ†’βˆ—tβ€²t \to^* t', then tβ€²t' is a value or can take a further step; a well-typed closed term never reaches a stuck state.

Remarks

Progress is proved by induction on the typing derivation, using a canonical forms lemma. The lemma says that a closed value of type π–‘π—ˆπ—ˆπ—…\mathsf{Bool} is π—π—‹π—Žπ–Ύ\mathsf{true} or π–Ώπ–Ίπ—…π—Œπ–Ύ\mathsf{false}, and a closed value of type Οƒβ†’Ο„\sigma \to \tau is an abstraction. Preservation is proved by induction on the derivation of tβ†’tβ€²t \to t', and its key case is a substitution lemma: if Ξ“,x:ΟƒβŠ’t:Ο„\Gamma, x : \sigma \vdash t : \tau and Ξ“βŠ’u:Οƒ\Gamma \vdash u : \sigma, then Ξ“βŠ’t[u/x]:Ο„\Gamma \vdash t[u/x] : \tau. The term 𝗂𝖿 (Ξ»x:π–‘π—ˆπ—ˆπ—…. x)Β π—π—π–Ύπ—‡Β π—π—‹π—Žπ–ΎΒ π–Ύπ—…π—Œπ–ΎΒ π–Ώπ–Ίπ—…π—Œπ–Ύ\mathsf{if}\ (\lambda x{:}\mathsf{Bool}.\, x)\ \mathsf{then}\ \mathsf{true}\ \mathsf{else}\ \mathsf{false} is stuck: it is not a value and no rule applies. The theorem predicts this, since the term has no type: the condition is a function, not a π–‘π—ˆπ—ˆπ—…\mathsf{Bool}. Progress needs the empty context: the open term xx with x:π–‘π—ˆπ—ˆπ—…x : \mathsf{Bool} is well typed, not a value and cannot step.

Going deeper

For a student

This syntactic form of type safety, split into progress and preservation, is due to Wright and Felleisen. The same two lemmas are the standard way to prove safety of any type system given by an operational semantics. Safety does not say that programs terminate: it also holds for languages with general recursion, where a safe program may run forever. For the simply typed calculus, strong normalization adds termination on top of safety.

Reading path

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

Show the path as a graph
Beta normal form, concept, no evidence levelBeta normal formconceptBeta reduction, concept, no evidence levelBeta reductionconceptBinary relation, concept, no evidence levelBinary relationconceptElement, definition, no evidence levelElementdefinitionIntuitionistic logic, concept, no evidence levelIntuitionistic logicconceptLambda calculus, concept, no evidence levelLambda calculusconceptNormalization property, concept, no evidence levelNormalization propertyconceptProposition, concept, no evidence levelPropositionconceptSet, concept, no evidence levelSetconceptType system, concept, no evidence levelType systemconceptChurch–Rosser theorem, statement, no evidence levelChurch–Rosser theoremstatementOperational semantics, concept, no evidence levelOperational semanticsconceptSet, 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…conceptStrong normalization of simply typed lambda calculus, statement, no evidence levelStrong normalization …statementType safety, statement, no evidence levelType safetystatement
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. Beta normal form concept
  2. Beta reduction concept
  3. Binary relation concept
  4. Element definition
  5. Intuitionistic logic concept
  6. Lambda calculus concept
  7. Normalization property concept
  8. Proposition concept
  9. Set concept
  10. Type system concept
  11. Church–Rosser theorem statement
  12. Operational semantics concept
  13. Set definition
  14. Conjunction definition
  15. Disjunction definition
  16. Implication definition
  17. Negation definition
  18. Biconditional definition
  19. Truth table concept
  20. Modus ponens concept
  21. Mathematical proof concept
  22. Propositional logic concept
  23. Tautology definition
  24. Logical equivalence definition
  25. Double negation law statement
  26. Proof by contradiction concept
  27. Russell's paradox statement
  28. Type theory concept
  29. Curry–Howard correspondence concept
  30. Simply typed lambda calculus concept
  31. Strong normalization of simply typed lambda calculus statement
  32. Type safety statement

Further reading

  1. Web https://en.wikipedia.org/wiki/Type_safety
About this page
TagCY0V19041Y
URIm2://CY0V19041Y
Kindstatement, theorem
WritingW0 stub
MSC68N15, 68Q55, 03B40
StatusThis copy of the site has no build data. Run m2 status CY0V19041Y.
AboutType system, Simply typed lambda calculus
UsesSimply typed lambda calculus, Operational semantics, Type system, Strong normalization of simply typed lambda calculus
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.