Parametricity and Free Theorems
Use uniform behavior at a type variable to reason about a polymorphic function without reading its implementation.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
A relation transports a uniform computation
For a total, pure parametric calculus, a term of type \(\forall A.\,A\to A\) must preserve every relation chosen between interpretations of \(A\). Pick a relation relating a value \(a\) only to the unique value of a one-element type. The result at the one-element type has to be that value. Relation preservation forces the result at the original type to be \(a\). This proves the identity behavior under the model’s assumptions.
The type controls which observations are allowed
A polymorphic list function can inspect list structure and rearrange elements. Without type-specific operations, it cannot branch on arbitrary unknown element values. Language features such as effects, runtime type inspection and nontermination change the statement or the relation used in its proof. Let-polymorphism explains how a language assigns reusable type schemes. Contextual equivalence instead reasons through what an enclosing program can observe.[1][2]