Difference between revisions of "Polymorphism (computer science)"
From Wiki @ Karl Jones dot com
Karl Jones (Talk | contribs) (Created page with "In programming languages and type theory, '''polymorphism''' (from Greek πολύς, ''polys'', "many, much" and μορφή, ''morphē'', "form, s...") |
Karl Jones (Talk | contribs) |
||
Line 7: | Line 7: | ||
There are several fundamentally different kinds of polymorphism: | There are several fundamentally different kinds of polymorphism: | ||
− | * Ad hoc polymorphism: when a function denotes different and potentially heterogeneous implementations depending on a limited range of individually specified types and combinations. Ad hoc polymorphism is supported in many languages using function overloading. | + | * [[Ad hoc polymorphism]]: when a function denotes different and potentially heterogeneous implementations depending on a limited range of individually specified types and combinations. Ad hoc polymorphism is supported in many languages using [[function overloading]]. |
− | * Parametric polymorphism: when code is written without mention of any specific type and thus can be used transparently with any number of new types. In the object-oriented programming community, this is often known as generics or generic programming. In the functional programming community, this is often shortened to polymorphism. | + | * [[Parametric polymorphism]]: when code is written without mention of any specific type and thus can be used transparently with any number of new types. In the [[object-oriented programming]] community, this is often known as generics or [[generic programming]]. In the functional programming community, this is often shortened to polymorphism. |
− | * Subtyping (also called subtype polymorphism or inclusion polymorphism): when a name denotes instances of many different classes related by some common superclass. In the object-oriented programming community, this is often simply referred to as polymorphism. | + | * [[Subtyping]] (also called subtype polymorphism or inclusion polymorphism): when a name denotes instances of many different classes related by some common superclass. In the [[object-oriented programming]] community, this is often simply referred to as polymorphism. |
− | The interaction between parametric polymorphism and subtyping leads to the concepts of variance and bounded quantification. | + | The interaction between parametric polymorphism and subtyping leads to the concepts of [[Covariance and contravariance (computer science)|variance]] and [[bounded quantification]]. |
== See also == | == See also == | ||
+ | * [[Ad hoc polymorphism]] | ||
+ | * [[Bounded quantification]] | ||
+ | * [[Covariance and contravariance (computer science)]] | ||
* [[Data type]] | * [[Data type]] | ||
* [[Duck typing]] for polymorphism without (static) types | * [[Duck typing]] for polymorphism without (static) types | ||
+ | * [[Function overloading]] | ||
+ | * [[Object-oriented programming]] | ||
+ | * [[Parametric polymorphism]] | ||
* [[Polymorphic code]] (Computer virus terminology) | * [[Polymorphic code]] (Computer virus terminology) | ||
+ | * [[Subtyping]] | ||
* [[System F]] for a lambda calculus with parametric polymorphism. | * [[System F]] for a lambda calculus with parametric polymorphism. | ||
* [[Type class]] | * [[Type class]] |
Latest revision as of 07:29, 20 September 2016
In programming languages and type theory, polymorphism (from Greek πολύς, polys, "many, much" and μορφή, morphē, "form, shape") is the provision of a single interface to entities of different data types.
Description
A polymorphic type is one whose operations can also be applied to values of some other type, or types.
There are several fundamentally different kinds of polymorphism:
- Ad hoc polymorphism: when a function denotes different and potentially heterogeneous implementations depending on a limited range of individually specified types and combinations. Ad hoc polymorphism is supported in many languages using function overloading.
- Parametric polymorphism: when code is written without mention of any specific type and thus can be used transparently with any number of new types. In the object-oriented programming community, this is often known as generics or generic programming. In the functional programming community, this is often shortened to polymorphism.
- Subtyping (also called subtype polymorphism or inclusion polymorphism): when a name denotes instances of many different classes related by some common superclass. In the object-oriented programming community, this is often simply referred to as polymorphism.
The interaction between parametric polymorphism and subtyping leads to the concepts of variance and bounded quantification.
See also
- Ad hoc polymorphism
- Bounded quantification
- Covariance and contravariance (computer science)
- Data type
- Duck typing for polymorphism without (static) types
- Function overloading
- Object-oriented programming
- Parametric polymorphism
- Polymorphic code (Computer virus terminology)
- Subtyping
- System F for a lambda calculus with parametric polymorphism.
- Type class
- Type theory
- Virtual inheritance
External links
- Polymorphism (computer science) @ Wikipedia