Skip to content

Types as Propositions

There’s a deeper theoretical basis for treating types as evidence. Under the Curry-Howard correspondence, types correspond to propositions and programs correspond to proofs. For example, function types, product types, and sum types correspond to logical implication, conjunction, and disjunction. Wadler gives a good overview in “Propositions as Types” (PDF). (Edinburgh Research)

Wadler describes the correspondence at three levels: propositions as types, proofs as programs, and simplification of proofs as evaluation of programs. Pierce (PDF, section 9.4 “The Curry-Howard Correspondence”) gives the working version: a proposition is provable exactly when its type has a value (is inhabited).

So:

A -> B

can be read informally as:

given evidence of A,
I can produce evidence of B

and

Result<A, B>

roughly corresponds to:

A OR B

The “roughly” matters. In the constructive logic behind the correspondence, a proof of A OR B has to say which of the two it proves, and Result does: it’s a tagged sum, and the tag (Ok or Err) is that indication. An untagged union such as TypeScript’s string | number records less; Pierce (section 15.7 “Intersection and Union Types”) notes that Nat ∨ Nat is just Nat, so the union can’t tell you which side you have.

The rest of logic has counterparts too (Wadler, sections 3 and 5):

LogicTypes
trueunit type ()
falseempty type (Void, Nothing, never)
A AND Bpair, record
A OR Btagged sum
A implies Bfunction
for all xpolymorphism over types; over values, dependent function types
there exists xexistential types; over values, dependent pairs
use exactly once (linear logic)linear types, session types

Two rows explain things elsewhere in this section. Existential types correspond to data abstraction (Mitchell and Plotkin; Pierce, section 24.2 “Data Abstraction with Existentials”): a module that hides its representation says “there exists a type T with these operations”, which is what an opaque type with a smart constructor does (Newtypes And Simple Values). And quantifying over values is where dependent types begin (Dependent Types).

This explains why algebraic data types can feel like designing a little logic for your application. Keep that logic correspondence distinct from the arithmetic of type sizes (|Either a b| = |a| + |b|, |(a, b)| = |a| * |b|, |a -> b| = |b|^|a|, covered in Algebraic Data Types). Some presentations (such as Maguire, PDF, section 1.4) fold both into one table under the Curry-Howard name, but as Hackett points out in her review (PDF), Curry-Howard links only logic and types: the numerical equations are cardinal arithmetic, and the two diverge (A OR A is logically equivalent to A, while Either A A has twice as many values as A).

A caveat: in most languages the logic is inconsistent, because every type has a cheating inhabitant. null, a thrown exception, an infinite loop or Haskell’s undefined can stand in for a value of any type, so a function of type A -> B proves A implies B only if it doesn’t cheat. Wadler puts the trade-off in terms of the halting problem: a typed lambda calculus without general recursion is a consistent logic in which every program halts, and adding a fixpoint operator gives you all computable functions but loses the logic. Only total languages (Agda, Idris with totality checking, Rocq) make the correspondence exact. In Haskell, Scala or TypeScript, read a type as strong evidence, not a proof. The explicit escape hatches belong on the same list: a cast or asInstanceOf is a proof by assertion, and Ramalho (PDF, chapter 15) notes that checkers believe typing.cast without question.

Library sources

  • Wadler 2015, Propositions as Types – the Curry-Howard correspondence told through its history and natural deduction, including quantifiers, data abstraction and linear logic, and the trade-off between general recursion and a consistent logic
  • Pierce 2002, Types and Programming Languages – section 9.4, “The Curry-Howard Correspondence”; section 15.7 on untagged unions; section 24.2, “Data Abstraction with Existentials”
  • Harper 2016, Practical Foundations for Programming Languages, 2nd Edition – Part V, “Types and Propositions”, and Part III on total functions
  • Milewski 2019, Category Theory for Programmers, Scala Edition – chapter 2, “Types and Functions” (section 2.3 on bottom ⊥ and undefined, section 2.6 on Void, absurd and ()), chapters 5 and 6 on products, coproducts and simple algebraic data types, and chapter 9, section 9.6, “Curry-Howard Isomorphism”
  • Ramalho 2022, Fluent Python, 2nd Edition – chapter 15, “More About Type Hints”: typing.cast as an assertion the checker believes
  • Maguire 2018, Thinking with Types: Type-Level Programming in Haskell – section 1.4, “The Curry-Howard Isomorphism”: a table matching Either, pairs, functions, Void and () with disjunction, conjunction, implication, false and true (alongside an algebra column; see Hackett 2020 below); section 15.5, “Dependent Pairs”: Σ types as the existential quantifier; on the table of logic and types
  • Hackett 2020, Review of “Thinking with Types” – points out that Maguire’s section 1.4 conflates the Curry-Howard correspondence (between logic and types) with cardinal arithmetic on type sizes; on keeping logic and cardinality distinct

Further reading:

  • Bird 1998, Introduction to Functional Programming using Haskell (2nd edition) – section 1.3, “Values”: every type has an undefined value ⊥ (“bottom”), the value of a non-terminating definition such as infinity = infinity + 1; on the caveat that undefined or an infinite loop inhabits any type
  • Bird 2015, Thinking Functionally with Haskell – sections 2.1, 2.3 and 2.4: in Bird’s replacement for the 1998 text, 1 `div` 0 and infinity = 1 + infinity evaluate to ⊥ (undefined :: a), giving Bool three values and () two; on the caveat that undefined or an infinite loop inhabits any type