This paper, published in the Journal of Functional Programming in 2012, represents a seminal advancement in type theory. It bridges the gap between simple polymorphism and the complex world of dependent types by extending Reynolds’ famous "theorems for free" (parametricity) to Pure Type Systems (PTSs).
The Problem: Parametricity in Expressive Systems
In functional programming, parametricity is the principle that a polymorphic function must behave uniformly across all types. For example, a function with the type forall A. List A -> List A can only rearrange or drop elements; it cannot inspect the elements because it lacks knowledge of the type A. In 1983, John Reynolds formalized this into the "Abstraction Theorem," allowing developers to derive "free theorems" about a program solely from its type signature.
However, Reynolds' work was primarily focused on System F (standard polymorphism). Modern dependently typed languages—such as Agda, Coq, or Idris—allow types to depend on values (e.g., a "Vector of length $n$"). Extending parametricity to these systems is notoriously difficult because the boundary between "types" and "values" blurs. This paper addresses the lack of a unified, formal framework for parametricity in these advanced type systems.
Methodology: Pure Type Systems
The authors utilize Pure Type Systems (PTSs) as their mathematical framework. PTSs provide a generalized way of describing a wide range of lambda calculi, from simple systems to the highly complex "Lambda Cube."
Key technical contributions include:
- Relational Interpretation: The authors define a translation $\llbracket \cdot \rrbracket$ that transforms a type into a relation and a term (program) into a proof that the program satisfies that relation.
- Reflecting Systems: They introduce the concept of a "target" PTS that "reflects" a "source" PTS. The source serves as the programming language, while the target acts as the logic used for reasoning.
- Coloured PTS: To manage complexity, they introduce "colours" to distinguish between different flavors of quantification (e.g., implicit vs. explicit arguments), making the generated proofs more readable.
- Inductive Families: The theory is extended to handle complex datatypes like
List,Bool, andVec(vectors), demonstrating how to derive parametricity for data structures with internal dependencies.
Key Insights and Ideas
Unified Translation
A major breakthrough in the paper is the realization that in dependently typed systems, the translation of types to relations and terms to proofs is the same operation. Because types are first-class values, the Abstraction Theorem becomes elegantly self-referential.
Internalization and Proof Irrelevance
The authors show that a param axiom can be added to the language itself. This allows a program to "know" it is parametric, enabling internal optimizations or proofs without breaking logical consistency. Furthermore, the framework naturally handles "proof irrelevance"—the idea that for certain propositions, only the existence of a proof matters, not its specific form. They demonstrate that any two proofs of the same proposition are "related" under parametricity.
Key Results and Impact
- The Abstraction Theorem for PTS: The authors successfully prove that for any well-typed term $t : A$ in a source system, there is a corresponding term in the target system proving that $t$ satisfies the relational interpretation of $A$.
- Consistency: They demonstrate that adding an internal parametricity axiom is logically consistent and does not lead to contradictions (such as proving $0=1$).
- Practical Utility: The paper illustrates how to derive well-known properties, such as the fact that a function on a
Vec A n(a vector of length $n$) must return a result whose length is still determined by $n$, regardless of the contents of typeA.
Limitations and Future Work
While groundbreaking, the framework assumes a "pure" environment and does not yet account for side effects like state, exceptions, or non-termination. In languages with features like seq (which forces evaluation), some "free theorems" can break. Additionally, while "colours" assist readability, a more formal "phase distinction" between compile-time types and run-time values in the translation remains a subject for future refinement.
Summary updated