Parametric polymorphism

parametrically polymorphicimpredicative polymorphismparametricPolymorphicpolymorphismArbitrary-rankbounded polymorphismfirst-class polymorphismgenericgenerics
In programming languages and type theory, parametric polymorphism is a way to make a language more expressive, while still maintaining full static type-safety.wikipedia
82 Related Articles

Polymorphism (computer science)

polymorphismpolymorphictype polymorphism
Using parametric polymorphism, a function or a data type can be written generically so that it can handle values identically without depending on their type.

Ad hoc polymorphism

ad hoc'' polymorphic functionsad hoc'' polymorphismad-hoc overloading
Following Christopher Strachey, parametric polymorphism may be contrasted with ad hoc polymorphism, in which a single polymorphic function can have a number of distinct and potentially heterogeneous implementations depending on the type of argument(s) to which it is applied.
This is in contrast to parametric polymorphism, in which polymorphic functions are written without mention of any specific type, and can thus apply a single abstract implementation to any number of types in a transparent way.

OCaml

MetaOCamlOCaml Package ManagerOPAM
Today it exists in Standard ML, OCaml, F#, Ada, Haskell, Mercury, Visual Prolog, Scala, Julia, and others.
OCaml features: a static type system, type inference, parametric polymorphism, tail recursion, pattern matching, first class lexical closures, functors (parametric modules), exception handling, and incremental generational automatic garbage collection.

Julia (programming language)

JuliaJeff BezansonJulia programming language
Today it exists in Standard ML, OCaml, F#, Ada, Haskell, Mercury, Visual Prolog, Scala, Julia, and others.
Distinctive aspects of Julia's design include a type system with parametric polymorphism in a dynamic programming language; with multiple dispatch as its core programming paradigm.

Scala (programming language)

ScalaScala programming languageScala.js
Today it exists in Standard ML, OCaml, F#, Ada, Haskell, Mercury, Visual Prolog, Scala, Julia, and others.
It also has an advanced type system supporting algebraic data types, covariance and contravariance, higher-order types (but not higher-rank types), and anonymous types.

Generic programming

genericgenericstemplates
Such functions and data types are called generic functions and generic datatypes respectively and form the basis of generic programming. One example is C++ template specialization. In most object-oriented programming languages that support parametric polymorphism, parameters can be constrained to be subtypes of a given type (see Subtype polymorphism and the article on Generic programming).
They are known as parametric polymorphism in ML, Scala, Julia, and Haskell (the Haskell community also uses the term "generic" for a related but somewhat different concept); templates in C++ and D; and parameterized types in the influential 1994 book Design Patterns.

ML (programming language)

MLML programming languageML family
Parametric polymorphism was first introduced to programming languages in ML in 1975.
Features of ML include a call-by-value evaluation strategy, first-class functions, automatic memory management through garbage collection, parametric polymorphism, static typing, type inference, algebraic data types, pattern matching, and exception handling.

System F

polymorphic lambda calculuspolymorphicsecond order lambda calculus
An example of this is the System F with the type variable X in the type, where X could even refer to T itself. In type theory, the most frequently studied impredicative typed λ-calculi are based on those of the lambda cube, especially System F.
System F thus formalizes the notion of parametric polymorphism in programming languages, and forms a theoretical basis for languages such as Haskell and ML.

C++

C++ programming languageC++98C with Classes
One example is C++ template specialization.
Templates in C++ provide a sophisticated mechanism for writing generic, polymorphic code (i.e. parametric polymorphism).

Type class

classtype classesBounded type
In Haskell, bounding is achieved by requiring types to belong to a type class; thus the same function has the type in Haskell.
This is achieved by adding constraints to type variables in parametrically polymorphic types.

Lambda cube

λ-cube
In type theory, the most frequently studied impredicative typed λ-calculi are based on those of the lambda cube, especially System F.
The terms beginning with a \Lambda are called polymorphic, as they can be applied to different types to get different functions, similarly to polymorphic functions in ML-like languages.

Subtyping

subtypesubtype polymorphismsupertype
In most object-oriented programming languages that support parametric polymorphism, parameters can be constrained to be subtypes of a given type (see Subtype polymorphism and the article on Generic programming).
In object-oriented programming the term 'polymorphism' is commonly used to refer solely to this subtype polymorphism, while the techniques of parametric polymorphism would be considered generic programming.

Parametricity

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.

Polymorphic recursion

In computer science, polymorphic recursion (also referred to as Milner–Mycroft typability or the Milner–Mycroft calculus) refers to a recursive parametrically polymorphic function where the type parameter changes with each recursive invocation made, instead of staying constant.

Type system

dynamicstatictype checking
This is because predicativity, together with other restrictions, makes the type system simple enough that full type inference is always possible.

Type inference

inferredpartially inferredinfer
This is because predicativity, together with other restrictions, makes the type system simple enough that full type inference is always possible.
As the inferred type of is parametrically polymorphic, the type of the arguments and results of are not inferred, but left as type variables, and so can be applied to functions and lists of various types, as long as the actual types match in each invocation.

Impredicativity

impredicativepredicativepredicativism
The most general form of polymorphism is "higher-rank impredicative polymorphism".

Programming language

programming languageslanguagedialect
In programming languages and type theory, parametric polymorphism is a way to make a language more expressive, while still maintaining full static type-safety.

Type theory

theory of typestypestype
In type theory, the most frequently studied impredicative typed λ-calculi are based on those of the lambda cube, especially System F. In programming languages and type theory, parametric polymorphism is a way to make a language more expressive, while still maintaining full static type-safety.

Type safety

type-safetype safesafe
In programming languages and type theory, parametric polymorphism is a way to make a language more expressive, while still maintaining full static type-safety.

Christopher Strachey

ChristopherChristopher Stratchey
Following Christopher Strachey, parametric polymorphism may be contrasted with ad hoc polymorphism, in which a single polymorphic function can have a number of distinct and potentially heterogeneous implementations depending on the type of argument(s) to which it is applied.

Standard ML

SMLMoscow MLML
Today it exists in Standard ML, OCaml, F#, Ada, Haskell, Mercury, Visual Prolog, Scala, Julia, and others.

F Sharp (programming language)

F#F# programming language F# (programming language)
Today it exists in Standard ML, OCaml, F#, Ada, Haskell, Mercury, Visual Prolog, Scala, Julia, and others.

Ada (programming language)

AdaAda programming languageAda 83
Today it exists in Standard ML, OCaml, F#, Ada, Haskell, Mercury, Visual Prolog, Scala, Julia, and others.

Haskell (programming language)

HaskellHaskell programming languageHackage
Today it exists in Standard ML, OCaml, F#, Ada, Haskell, Mercury, Visual Prolog, Scala, Julia, and others. In Haskell, bounding is achieved by requiring types to belong to a type class; thus the same function has the type in Haskell.