Parametricity
Type theory concept
title: "Parametricity" type: doc version: 1 created: 2026-02-28 author: "Wikipedia contributors" status: active scope: public tags: ["programming-language-topics", "type-theory", "polymorphism-(computer-science)"] description: "Type theory concept" topic_path: "technology/programming-languages" source: "https://en.wikipedia.org/wiki/Parametricity" license: "CC BY-SA 4.0" wikipedia_page_id: 0 wikipedia_revision_id: 0
::summary Type theory concept ::
In programming language theory, parametricity is an abstract uniformity property enjoyed by parametrically polymorphic functions, which captures the intuition that all instances of a polymorphic function act the same way.
Idea
Consider this example, based on a set X and the type T(X) = [X → X] of functions from X to itself. The higher-order function twice**X : T(X) → T(X) given by twice**X(f) = f ∘ f, is intuitively independent of the set X. The family of all such functions twice**X, parametrized by sets X, is called a "parametrically polymorphic function". We simply write twice for the entire family of these functions and write its type as \forallX. T(X) → T(X). The individual functions twice**X are called the components or instances of the polymorphic function. Notice that all the component functions twice**X act "the same way" because they are given by the same rule. Other families of functions obtained by picking one arbitrary function from each T(X) → T(X) would not have such uniformity. They are called "ad hoc polymorphic functions". Parametricity is the abstract property enjoyed by the uniformly acting families such as twice, which distinguishes them from ad hoc families. With an adequate formalization of parametricity, it is possible to prove that the parametrically polymorphic functions of type \forallX. T(X) → T(X) are one-to-one with natural numbers. The function corresponding to the natural number n is given by the rule f \mapsto f**n, i.e., the polymorphic Church numeral for n. In contrast, the collection of all ad hoc families would be too large to be a set.
History
The parametricity theorem was originally stated by John C. Reynolds, who called it the abstraction theorem.{{cite conference |last1=Reynolds |first1=J.C. |year=1983 |title=Types, abstraction, and parametric polymorphism |book-title=Information Processing |pages=513–523 |url=https://people.mpi-sws.org/~dreyer/tor/papers/reynolds.pdf |location=North Holland, Amsterdam}} In his paper "Theorems for free!",{{cite conference |last1=Wadler |first1=Philip |author1-link=Philip Wadler |date=September 1989 |url=http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.38.9875 |title=Theorems for free! |book-title=4th International Conference on Functional Programming and Computer Architecture |location=London}} Philip Wadler described an application of parametricity to derive theorems about parametrically polymorphic functions based on their types.
Programming language implementation
Parametricity is the basis for many program transformations implemented in compilers for the programming language Haskell. These transformations were traditionally thought to be correct in Haskell because of Haskell's non-strict semantics. Despite being a lazy evaluation programming language, Haskell does support certain primitive operations, such as the operator seq—that enable so-called selective strictness, allowing evaluation to be forced for certain expressions. In their paper "Free theorems in the presence of seq",{{cite conference
|last1=Johann
|first1=Patricia
|last2=Voigtlaender |first2=Janis
|date=January 2004
|title=Free theorems in the presence of seq
|url=https://doi.org/10.1145/964001.964010
|book-title=Proceedings, Principles of Programming Languages
|pages=99–110 |doi=10.1145/964001.964010
|url-access=subscription
Dependent types
References
::callout[type=info title="Wikipedia Source"] This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page. ::