Parametric polymorphism
In programming languages and type theory, parametric polymorphism allows a single piece of code to be given a "generic" type, using variables in place of actual types, and then instantiated with particular types as needed. Parametrically polymorphic functions and data types are sometimes called generic functions and generic datatypes, respectively, and they form the basis of generic programming. Parametric polymorphism may be contrasted with ad hoc polymorphism. Parametrically polymorphic definitions are uniform: they behave identically regardless of the type they are instantiated at. In contrast, ad hoc polymorphic definitions are given a distinct definition for each type. Thus, ad hoc polymorphism can generally only support a limited number of such distinct types, since a separate implementation has to be provided for each type. The usual theoretical device for studying parametric polymorphism is system F, which extends simply typed lambda calculus with quantification over types.
In programming languages and type theory, parametric polymorphism allows a single piece of code to be given a "generic" type, using variables in place of actual types, and then instantiated with particular types as needed. Parametrically polymorphic functions and data types are sometimes called generic functions and generic datatypes, respectively, and they form the basis of generic programming. Parametric polymorphism may be contrasted with ad hoc polymorphism. Parametrically polymorphic definitions are uniform: they behave identically regardless of the type they are instantiated at. In contrast, ad hoc polymorphic definitions are given a distinct definition for each type. Thus, ad hoc polymorphism can generally only support a limited number of such distinct types, since a separate implementation has to be provided for each type. The usual theoretical device for studying parametric polymorphism is system F, which extends simply typed lambda calculus with quantification over types. It is possible to write functions that do not depend on the types of their arguments. For example, the identity function \mathsf{id}(x) = x simply returns its argument unmodified. This naturally gives rise to a family of potential types, such as \mathsf{Int} \to \mathsf{Int} , \mathsf{Bool} \to \mathsf{Bool} , \mathsf{String} \to \mathsf{String} , and so on. Parametric polymorphism allows \mathsf{id} to be given a single, most general type by introducing a universally quantified type variable: \mathsf{id} : \forall \alpha. \alpha \to \alpha The polymorphic definition can then be instantiated by substituting any concrete type for \alpha , yielding the full family of potential types. The identity function is a particularly extreme example, but many other functions also benefit from parametric polymorphism. For example, an \mathsf{append} function that concatenates two lists does not inspect the elements of the list, only the list structure itself. Therefore, \mathsf{append} can be given a similar family of types, such as [ \mathsf{Int}] \times [\mathsf{Int}] \to [\mathsf{Int}] , [ \mathsf{Bool}] \times [\mathsf{Bool}] \to [\mathsf{Bool}] , and so on, where [T] denotes a list of elements of type T . The most general type is therefore \mathsf{append} : \forall \alpha. [\alpha] \times [\alpha] \to [\alpha] which can be instantiated to any type in the family. Parametrically polymorphic functions like \mathsf{id} and \mathsf{append} are said to be parameterized over an arbitrary type \alpha . Both \mathsf{id} and \mathsf{append} are parameterized over a single type, but functions may be parameterized over arbitrarily many types. For example, the \mathsf{fst} and \mathsf{snd} functions that return the first and second elements of a pair, respectively, can be given the following types: \begin{aligned} \mathsf{fst} & : \forall \alpha. \forall \beta. \alpha \times \beta \to \alpha \\ \mathsf{snd} & : \forall \alpha. \forall \beta. \alpha \times \beta \to \beta \end{aligned} In the expression \mathsf{fst}((3, \mathsf{true})) , \alpha is instantiated to \mathsf{Int} and \beta is instantiated to \mathsf{Bool} in the call to \mathsf{fst} , so the type of the overall expression is \mathsf{Int} . The syntax used to introduce parametric polymorphism varies significantly between programming languages. For example, in some programming languages, such as Haskell, the \forall \alpha quantifier is implicit and may be omitted. Other languages require types to be instantiated explicitly at a parametrically polymorphic function's call sites, either at all sites or alternatively at least sufficient to allow type inference to determine the rest. In 1985, Luca Cardelli and Peter Wegner recognized the advantages of allowing bounds on the type parameters. Many operations require some knowledge of the data types, but can otherwise work parametrically. For example, to check whether an item is included in a list, we need to compare the items for equality. In Standard ML, type parameters of the form a are restricted so that the equality operation is available, thus the function would have the type a × a list → bool and a can only be a type with defined equality. In Haskell, bounding is achieved by requiring types to belong to a type class; thus the same function has the type \mathrm{Eq} \, \alpha \, \Rightarrow \alpha \, \rightarrow \left[\alpha \right] \rightarrow \mathrm{Bool} in Haskell. In most object-oriented programming languages that support parametric polymorphism, parameters can be constrained to be subtypes of a given type (see the articles Subtype polymorphism and Generic programming).
References
- The essence of ML · retrieved 2026-11-19 · rev 1378822151
Cite this reference
MLA "The essence of ML." Mitchell, J. 2026-11-19. https://dl.acm.org/doi/abs/10.1145/73560.73563. Accessed 24 November 2026.
Chicago "The essence of ML." Mitchell, J. 2026-11-19. https://dl.acm.org/doi/abs/10.1145/73560.73563.
APA Mitchell, J. (2026). The essence of ML. Retrieved November 24, 2026, from https://dl.acm.org/doi/abs/10.1145/73560.73563
- Kwang's Haskell Blog - Higher rank polymorphism · retrieved 2026-11-19 · rev 1378822151
Cite this reference
MLA "Kwang's Haskell Blog - Higher rank polymorphism." Kwang Yul Seo. 2026-11-19. https://kseo.github.io/posts/2016-12-27-higher-rank-polymorphism.html. Accessed 24 November 2026.
Chicago "Kwang's Haskell Blog - Higher rank polymorphism." Kwang Yul Seo. 2026-11-19. https://kseo.github.io/posts/2016-12-27-higher-rank-polymorphism.html.
APA Kwang Yul Seo. (2026). Kwang's Haskell Blog - Higher rank polymorphism. Retrieved November 24, 2026, from https://kseo.github.io/posts/2016-12-27-higher-rank-polymorphism.html
- Principality and decidable type inference for finite-rank intersection types · retrieved 2026-11-19 · rev 1378822151
Cite this reference
MLA "Principality and decidable type inference for finite-rank intersection types." Kfoury, A. 2026-11-19. https://en.wikipedia.org/wiki/Symposium_on_Principles_of_Programming_Languages. Accessed 24 November 2026.
Chicago "Principality and decidable type inference for finite-rank intersection types." Kfoury, A. 2026-11-19. https://en.wikipedia.org/wiki/Symposium_on_Principles_of_Programming_Languages.
APA Kfoury, A. (2026). Principality and decidable type inference for finite-rank intersection types. Retrieved November 24, 2026, from https://en.wikipedia.org/wiki/Symposium_on_Principles_of_Programming_Languages
- Principality and type inference for intersection types using expansion variables · retrieved 2026-11-19 · rev 1378822151
Cite this reference
MLA "Principality and type inference for intersection types using expansion variables." Kfoury, A. 2026-11-19. https://en.wikipedia.org/w/index.php?oldid=1378822151. Accessed 24 November 2026.
Chicago "Principality and type inference for intersection types using expansion variables." Kfoury, A. 2026-11-19. https://en.wikipedia.org/w/index.php?oldid=1378822151.
APA Kfoury, A. (2026). Principality and type inference for intersection types using expansion variables. Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1378822151
- More polymorphism and type classes · retrieved 2026-11-19 · rev 1378822151
Cite this reference
MLA "More polymorphism and type classes." Yorgey, Brent. 2026-11-19. https://www.seas.upenn.edu/~cis1940/spring13/lectures/05-type-classes.html. Accessed 24 November 2026.
Chicago "More polymorphism and type classes." Yorgey, Brent. 2026-11-19. https://www.seas.upenn.edu/~cis1940/spring13/lectures/05-type-classes.html.
APA Yorgey, Brent. (2026). More polymorphism and type classes. Retrieved November 24, 2026, from https://www.seas.upenn.edu/~cis1940/spring13/lectures/05-type-classes.html
- Parametric Polymorphism - SML Help · retrieved 2026-11-19 · rev 1378822151
Cite this reference
MLA "Parametric Polymorphism - SML Help." Wu, Brandon. 2026-11-19. https://web.archive.org/web/20221001000858/https://smlhelp.github.io/book/concepts/poly.html. Accessed 24 November 2026.
Chicago "Parametric Polymorphism - SML Help." Wu, Brandon. 2026-11-19. https://web.archive.org/web/20221001000858/https://smlhelp.github.io/book/concepts/poly.html.
APA Wu, Brandon. (2026). Parametric Polymorphism - SML Help. Retrieved November 24, 2026, from https://web.archive.org/web/20221001000858/https://smlhelp.github.io/book/concepts/poly.html
- Haskell 2010 Language Report § 4.1.2 Syntax of Types · retrieved 2026-11-19 · rev 1378822151
Cite this reference
MLA "Haskell 2010 Language Report § 4.1.2 Syntax of Types." "Haskell 2010 Language Report § 4. 2026-11-19. https://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-650004.1.2. Accessed 24 November 2026.
Chicago "Haskell 2010 Language Report § 4.1.2 Syntax of Types." "Haskell 2010 Language Report § 4. 2026-11-19. https://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-650004.1.2.
APA "Haskell 2010 Language Report § 4. (2026). Haskell 2010 Language Report § 4.1.2 Syntax of Types. Retrieved November 24, 2026, from https://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-650004.1.2
- A Logic for Computable Functions with reflexive and polymorphic types · retrieved 2026-11-19 · rev 1378822151
Cite this reference
MLA "A Logic for Computable Functions with reflexive and polymorphic types." Milner, R. 2026-11-19. https://en.wikipedia.org/wiki/Robin_Milner. Accessed 24 November 2026.
Chicago "A Logic for Computable Functions with reflexive and polymorphic types." Milner, R. 2026-11-19. https://en.wikipedia.org/wiki/Robin_Milner.
APA Milner, R. (2026). A Logic for Computable Functions with reflexive and polymorphic types. Retrieved November 24, 2026, from https://en.wikipedia.org/wiki/Robin_Milner
- D. Leivant, Polymorphic type inference, in: Conf. Rec. 10th Ann. ACM Symp. Princ. of Prog. Langs., 1983, pp. 88–98. Wikipedia revision 1378822151, retrieved 2026-11-20 · retrieved 2026-11-19 · rev 1378822151
Cite this reference
MLA "D. Leivant, Polymorphic type inference, in: Conf. Rec. 10th Ann. ACM Symp. Princ. of Prog. Langs., 1983, pp. 88–98. Wikipedia revision 1378822151, retrieved 2026-11-20." D. 2026-11-19. https://en.wikipedia.org/w/index.php?oldid=1378822151. Accessed 24 November 2026.
Chicago "D. Leivant, Polymorphic type inference, in: Conf. Rec. 10th Ann. ACM Symp. Princ. of Prog. Langs., 1983, pp. 88–98. Wikipedia revision 1378822151, retrieved 2026-11-20." D. 2026-11-19. https://en.wikipedia.org/w/index.php?oldid=1378822151.
APA D. (2026). D. Leivant, Polymorphic type inference, in: Conf. Rec. 10th Ann. ACM Symp. Princ. of Prog. Langs., 1983, pp. 88–98. Wikipedia revision 1378822151, retrieved 2026-11-20. Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1378822151
- E. Moggi and Amr Sabry. 2001. Monadic Encapsulation of Effects: A Revised Approach (Extended Version). J. Funct. Program. 11, 6 (Nov. 2001), 591-627 Wikipedia revision 1378822151, retrieved 2026-11-20 · retrieved 2026-11-19 · rev 1378822151
Cite this reference
MLA "E. Moggi and Amr Sabry. 2001. Monadic Encapsulation of Effects: A Revised Approach (Extended Version). J. Funct. Program. 11, 6 (Nov. 2001), 591-627 Wikipedia revision 1378822151, retrieved 2026-11-20." E. 2026-11-19. https://en.wikipedia.org/w/index.php?oldid=1378822151. Accessed 24 November 2026.
Chicago "E. Moggi and Amr Sabry. 2001. Monadic Encapsulation of Effects: A Revised Approach (Extended Version). J. Funct. Program. 11, 6 (Nov. 2001), 591-627 Wikipedia revision 1378822151, retrieved 2026-11-20." E. 2026-11-19. https://en.wikipedia.org/w/index.php?oldid=1378822151.
APA E. (2026). E. Moggi and Amr Sabry. 2001. Monadic Encapsulation of Effects: A Revised Approach (Extended Version). J. Funct. Program. 11, 6 (Nov. 2001), 591-627 Wikipedia revision 1378822151, retrieved 2026-11-20. Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1378822151
- A logical relation for monadic encapsulation of state: proving contextual equivalences in the presence of runST · retrieved 2026-11-19 · rev 1378822151
Cite this reference
MLA "A logical relation for monadic encapsulation of state: proving contextual equivalences in the presence of runST." Amin Timany, Léo Stefanesco, Morten Krogh-Jespersen, Lars Birkedal, "A logical relation for monadic encapsulation of sta. 2026-11-19. https://en.wikipedia.org/w/index.php?oldid=1378822151. Accessed 24 November 2026.
Chicago "A logical relation for monadic encapsulation of state: proving contextual equivalences in the presence of runST." Amin Timany, Léo Stefanesco, Morten Krogh-Jespersen, Lars Birkedal, "A logical relation for monadic encapsulation of sta. 2026-11-19. https://en.wikipedia.org/w/index.php?oldid=1378822151.
APA Amin Timany, Léo Stefanesco, Morten Krogh-Jespersen, Lars Birkedal, "A logical relation for monadic encapsulation of sta. (2026). A logical relation for monadic encapsulation of state: proving contextual equivalences in the presence of runST. Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1378822151
- Cardelli & Wegner 1985 . Wikipedia revision 1378822151, retrieved 2026-11-20 · retrieved 2026-11-19 · rev 1378822151
Cite this reference
MLA "Cardelli & Wegner 1985 . Wikipedia revision 1378822151, retrieved 2026-11-20." Cardelli & Wegner 1985. 2026-11-19. https://en.wikipedia.org/w/index.php?oldid=1378822151. Accessed 24 November 2026.
Chicago "Cardelli & Wegner 1985 . Wikipedia revision 1378822151, retrieved 2026-11-20." Cardelli & Wegner 1985. 2026-11-19. https://en.wikipedia.org/w/index.php?oldid=1378822151.
APA Cardelli & Wegner 1985. (2026). Cardelli & Wegner 1985 . Wikipedia revision 1378822151, retrieved 2026-11-20. Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1378822151
- Fundamental Concepts in Programming Languages · retrieved 2026-11-19 · rev 1378822151
Cite this reference
MLA "Fundamental Concepts in Programming Languages." Strachey, Christopher (1967), Fundamental Concepts in Programming Languages (Lecture notes), Copenhagen: International S. 2026-11-19. https://en.wikipedia.org/wiki/Christopher_Strachey. Accessed 24 November 2026.
Chicago "Fundamental Concepts in Programming Languages." Strachey, Christopher (1967), Fundamental Concepts in Programming Languages (Lecture notes), Copenhagen: International S. 2026-11-19. https://en.wikipedia.org/wiki/Christopher_Strachey.
APA Strachey, Christopher (1967), Fundamental Concepts in Programming Languages (Lecture notes), Copenhagen: International S. (2026). Fundamental Concepts in Programming Languages. Retrieved November 24, 2026, from https://en.wikipedia.org/wiki/Christopher_Strachey
- a b c d e f Benjamin C. Pierce (2002). Types and Programming Languages . MIT Press. ISBN 978-0-262-16209-8 . Wikipedia revision 1378822151, retrieved 2026-11-20 · retrieved 2026-11-19 · rev 1378822151
Cite this reference
MLA "a b c d e f Benjamin C. Pierce (2002). Types and Programming Languages . MIT Press. ISBN 978-0-262-16209-8 . Wikipedia revision 1378822151, retrieved 2026-11-20." a b c d e f Benjamin C. 2026-11-19. https://en.wikipedia.org/wiki/Benjamin_C._Pierce. Accessed 24 November 2026.
Chicago "a b c d e f Benjamin C. Pierce (2002). Types and Programming Languages . MIT Press. ISBN 978-0-262-16209-8 . Wikipedia revision 1378822151, retrieved 2026-11-20." a b c d e f Benjamin C. 2026-11-19. https://en.wikipedia.org/wiki/Benjamin_C._Pierce.
APA a b c d e f Benjamin C. (2026). a b c d e f Benjamin C. Pierce (2002). Types and Programming Languages . MIT Press. ISBN 978-0-262-16209-8 . Wikipedia revision 1378822151, retrieved 2026-11-20. Retrieved November 24, 2026, from https://en.wikipedia.org/wiki/Benjamin_C._Pierce
Cite this article
MLA
"Parametric polymorphism." encyclopegia.org, 2026, https://encyclopegia.org/wiki/parametric-polymorphism. Accessed 24 November 2026.
Chicago
"Parametric polymorphism." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/parametric-polymorphism.
APA
encyclopegia.org. (2026). Parametric polymorphism. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/parametric-polymorphism
Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON