# Type variable

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Type_variable
> Markdown URL: https://mediated.wiki/source/Type_variable.md
> Source: https://en.wikipedia.org/wiki/Type_variable
> Source revision: 1339551615
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

{{Unreferenced|date=January 2025}}
In [type theory](/source/type_theory) and [programming language](/source/programming_language)s, a '''type variable''' is a [mathematical variable](/source/Variable_(mathematics)) ranging over [types](/source/data_types). Even in programming languages that allow [mutable variable](/source/variable_(programming))s, a type variable remains an abstraction, in the sense that it does not correspond to some memory locations.

Programming languages that support [parametric polymorphism](/source/parametric_polymorphism) make use of [universally quantified](/source/universally_quantified) type variables. Languages that support [existential type](/source/existential_type)s make use of [existentially quantified](/source/existentially_quantified) type variables. For example, the following [OCaml](/source/OCaml) code defines a polymorphic [identity function](/source/identity_function) that has a universally quantified type, which is printed by the interpreter on the second line:

<syntaxhighlight lang="ocaml">
# let id x = x;;
val id : 'a -> 'a = <fun>
</syntaxhighlight>

In mathematical notation, the type of the function <code>id</code> is <math>\forall a.a \to a</math>, where <math>a</math> is a type variable.

== See also ==
* [System F](/source/System_F) 

{{type-theory-stub}}

Category:Type theory
Category:Functional programming
Category:Dependently typed programming

---
Adapted from the Wikipedia article [Type variable](https://en.wikipedia.org/wiki/Type_variable) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Type_variable?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
