Polymorphism (computer science): Difference between revisions

Content deleted Content added
changed "we call it" to "it is called"
No edit summary
Tags: Mobile edit Mobile web edit
 
Line 1:
{{Short description|Using one interface or symbol with regards to multiple different types}}
In [[computer science]], '''polymorphism''' is the idea of allowing the same code to be used with different types, resulting in more general and abstract implementations.
{{Distinguish|Polymorphic code}}
{{Polymorphism}}
In [[programming language theory]] and [[type theory]], '''polymorphism''' is the approach that allows a value type to assume different types.<ref name="Luca">{{Cite journal |last1=Cardelli |first1=Luca |author1-link=Luca Cardelli |last2=Wegner |first2=Peter |author2-link=Peter Wegner (computer scientist)|doi=10.1145/6041.6042 |title=On understanding types, data abstraction, and polymorphism |journal=[[ACM Computing Surveys]] |volume=17 |issue=4 |pages=471–523 |date=December 1985 |url=http://lucacardelli.name/Papers/OnUnderstanding.A4.pdf |citeseerx=10.1.1.117.695 |s2cid=2921816}}: "Polymorphic types are types whose operations are applicable to values of more than one type."</ref>
 
In [[object-oriented programming]], polymorphism is the provision of one [[Interface (object-oriented programming)|interface]] to entities of different [[data type]]s.<ref>{{cite web |url=http://www.stroustrup.com/glossary.html#Gpolymorphism |last1=Stroustrup |first1=Bjarne |author1-link=Bjarne Stroustrup |title=Bjarne Stroustrup's C++ Glossary |date=February 19, 2007 |quote=polymorphism – providing a single interface to entities of different types.}}</ref> The concept is borrowed from a principle in [[biology]] where an organism or species can have many different forms or stages.<ref name="Moved">{{cite web |title=Polymorphism |work=The Java Tutorials: Learning the Java Language: Interfaces and Inheritance |publisher=Oracle |url=https://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html |access-date=2021-09-08}}</ref>
The concept of polymorphism applies to functions as well as types:
* A [[function (programming)|function]] that can evaluate to and be applied to values of different types is known as a ''polymorphic function''.
* A [[datatype]] that contains elements of an unspecified type is known as a ''polymorphic datatype''.
 
ThereThe aremost twocommonly fundamentallyrecognized differentmajor kindsforms of polymorphism are:
* ''[[Ad hoc polymorphism]]'': defines a common interface for an arbitrary set of individually specified types.
* If the range of actual types that can be used is finite and the combinations must be specified individually prior to use, it is called ''ad-hoc polymorphism''.
* ''[[Parametric polymorphism]]'': not specifying concrete types and instead use abstract symbols that can substitute for any type.
* If all code is written without mention of any specific type and thus can be used transparently with any number of new types, it is called ''parametric polymorphism''.
* ''[[Subtyping]]'' (also called ''subtype polymorphism'' or ''inclusion polymorphism''): when a name denotes instances of many different classes related by some common superclass.<ref name="gbooch">{{cite book |last1=Conallen |first1=J. |last2=Engle |first2=M. |last3=Houston |first3=K. |last4=Maksimchuk |first4=R. |last5=Young |first5=B. |last6=Booch |first6=G. |author6-link=Grady Booch |date=2007 |title=Object-Oriented Analysis and Design with Applications |publisher=Pearson Education |edition=3rd |isbn=9780132797443 |pages=}}</ref>
 
==History==
Programming using the latter kind is called ''[[generic programming]]''.
Interest in polymorphic [[type system]]s developed significantly in the 1990s, with practical implementations beginning to appear by the end of the decade. ''Ad hoc polymorphism'' and ''parametric polymorphism'' were originally described in [[Christopher Strachey]]'s ''[[Fundamental Concepts in Programming Languages]]'',<ref name=Strachey00>{{cite journal |last1=Strachey |first1=Christopher |author1-link=Christopher Strachey |date=2000 |title=Fundamental Concepts in Programming Languages |journal=[[Higher-Order and Symbolic Computation]] |volume=13 |issue=1/2 |pages=11–49 |doi=10.1023/A:1010000313106 |issn=1573-0557 |citeseerx=10.1.1.332.3161 |s2cid=14124601}}</ref> where they are listed as "the two main classes" of polymorphism. Ad hoc polymorphism was a feature of [[ALGOL 68]], while parametric polymorphism was the core feature of [[ML (programming language)|ML]]'s [[type system]].
 
In a 1985 paper, [[Peter Wegner (computer scientist)|Peter Wegner]] and [[Luca Cardelli]] introduced the term ''inclusion polymorphism'' to model subtypes and [[Inheritance (object-oriented programming)|inheritance]],<ref name="Luca"/> citing [[Simula]] as the first programming language to implement it.
Polymorphism gained most of its momentum when [[object-oriented programming]] became [[buzz word|popular]].
 
==Forms==
== Parametric polymorphism ==
===Ad hoc polymorphism===
Using '''parametric polymorphism''', a function can been written generically so that it can deal equally well with objects of various types. For example, a function <code>append</code> that joins two lists can be constructed so that it does not depend on one particular type of list: it can append lists of integers, lists of real numbers, lists of strings, and so on. Let <var>a</var> denote the type of elements in the lists. Then <code>append</code> can be typed [<var>a</var>] &times; [<var>a</var>] &rarr; [<var>a</var>], where [<var>a</var>] denotes a list of elements of type <var>a</var>. We say that <code>append</code> is ''parameterized by <var>a</var>''. (Note that since there is only one type parameter, the function cannot be applied to just any pair of lists: they must consist of the same type of elements.)
{{Further|Ad hoc polymorphism}}
[[Christopher Strachey]] chose the term ''ad hoc polymorphism'' to refer to polymorphic functions that can be applied to arguments of different types, but that behave differently depending on the type of the argument to which they are applied (also known as [[function overloading]] or [[operator overloading]]).<ref name=Strachey00/> The term "[[ad hoc]]" in this context is not pejorative: instead, it means that this form of polymorphism is not a fundamental feature of the type system. In the [[Java (programming language)|Java]] example below, the <code>add</code> functions seem to work generically over two types ([[Integer (computer science)|integer]] and [[String (computer science)|string]]) when looking at the invocations, but are considered to be two entirely distinct functions by the [[compiler]] for all intents and purposes:
 
<syntaxhighlight lang="java">
Parametric polymorphism was the first type of polymorphism developed, first identified by [[Christopher Strachey]] in [[1967]]. It was also the first type of polymorphism to appear in an actual programming language, [[ML programming language|ML]] in [[1976]]. It exists today in [[Standard ML]], [[OCaml]], [[Haskell programming language|Haskell]], and others. Some argue that [[template (programming)|templates]] should be considered an example of parametric polymorphism, though they rely on macros to generate specific code rather than actually reusing generic code (resulting in ''[[code bloat]]'').
class AdHocPolymorphic {
public String add(int x, int y) {
return String.format("Sum: %d", x + y);
}
 
public String add(String name) {
Parametric polymorphism is a way to make a language more expressible, while still maintaining full static [[type-safety]]. It is thus irrelevant in [[dynamically typed]] languages, since they ''by definition'' lack static type-safety. However, any dynamically typed function ''f'' that takes ''n'' arguments can be given a static typed using parametric polymorphism: ''f'' : ''p<sub>1</sub>'' &times; ... &times; ''p<sub>n</sub>'' &rarr; ''r'', where ''p<sub>1</sub>'' ... ''p<sub>n</sub>'' and ''r'' are type parameters. Of course, this type is completely insubstantial and thus essentially useless.
return String.format("Added ", name);
}
}
 
public class Adhoc {
=== Subtyping polymorphism ===
public static void main(String[] args) {
Some languages employ the idea of a ''[[subtype]]'' to restrict the range types that can be used in a particular case of parametric polymorphism. Hence, '''subtyping polymorphism''' allows a function to be written so that it takes a certain type of object <var>T</var>, but will also work correctly if passed an object that belongs to a type <var>S</var> that is a subtype of <var>T</var>. This is sometimes written <var>S</var>&nbsp;&lt;:&nbsp;<var>T</var>. Conversely, we say that <var>T</var> is a ''supertype'' of <var>S</var>&mdash;written <var>T</var>&nbsp;:&gt;&nbsp;<var>S</var>.
AdHocPolymorphic poly = new AdHocPolymorphic();
 
System.out.println(poly.add(1, 2)); // prints "Sum: 3"
For example, given the types <code>Number</code>, <code>Integer</code>, and <code>Fractional</code>, such that <code>Number</code>&nbsp;:&gt;&nbsp;<code>Integer</code> and <code>Number</code>&nbsp;:&gt;&nbsp;<code>Fractional</code>, a function could be written that takes any kind of <code>Number</code>, and works equally well whether an <code>Integer</code> or <code>Fractional</code> is passed. (This particular kind of type hierarchy is known&mdash;especially in the context of [[Scheme]]&mdash;as a ''[[numerical tower]]'', and usually contains a lot more types.)
System.out.println(poly.add("Jay")); // prints "Added Jay"
}
}
</syntaxhighlight>
 
In [[dynamically typed]] languages the situation can be more complex as the correct function that needs to be invoked might only be determinable at run time.
In [[object-oriented programming]] this is implemented with ''[[subclass]]ing'' ([[inheritance in object-oriented programming|inheritance]]), and is also known as '''late binding'''. See also:
* [[Polymorphism in object-oriented programming]],
* [[Liskov substitution principle]].
 
[[Implicit type conversion]] has also been defined as a form of polymorphism, referred to as "coercion polymorphism".<ref name="Luca"/><ref name="Tucker2004">{{cite book |last1=Tucker |first1=Allen B.|date=2004 |title=Computer Science Handbook |edition=2nd |url=https://books.google.com/books?id=9IFMCsQJyscC&pg=SA91-PA5 |publisher=Taylor & Francis |pages=91– |isbn=978-1-58488-360-9}}</ref>
== Ad-hoc polymorphism ==
'''Ad-hoc polymorphism''' usually refers to simple '''overloading''' (see [[function overloading]]), but sometimes automatic type conversion, known as '''coercion''', is also considered to be a kind of ad-hoc polymorphism (see the example section below). Common to these two types is the fact that the programmer has to specify exactly what types are to be usable with the polymorphic function.
 
===Parametric polymorphism===
The name refers to the manner in which this kind of polymorphism is typically introduced: &ldquo;Oh, hey, let&rsquo;s make the <code>+</code> operator work on strings, too!&rdquo; Some argue that ad-hoc polymorphism is not polymorphism in a meaningful computer science sense at all&mdash;that it is just [[syntactic sugar]] for calling <code>append_integer</code>, <code>append_string</code>, etc., manually. One way to see it is that
{{Further|Parametric polymorphism}}
* to the user, there appears to be only one function, but one that takes different types of input and is thus type polymorphic; on the other hand,
''Parametric polymorphism'' allows a function or a data type to be written generically, so that it can handle values ''uniformly'' without depending on their type.<ref name="bjpierce">{{cite book |last1=Pierce |first1=B.C. |date=2002 |chapter=23.2 Varieties of Polymorphism |chapter-url=https://books.google.com/books?id=ti6zoAC9Ph8C&pg=PA340 |title=Types and Programming Languages |publisher=MIT Press |isbn= 9780262162098 |pages=340–1 |url=}}</ref> Parametric polymorphism is a way to make a language more expressive while still maintaining full static [[type safety]].
* to the author, there are several functions that need to be written&mdash;one for each type of input&mdash;so there&rsquo;s essentially no polymorphism.
 
The concept of parametric polymorphism applies to both [[data type]]s and [[Function (computer programming)|functions]]. A function that can evaluate to or be applied to values of different types is known as a ''polymorphic function.'' A data type that can appear to be of a generalized type (e.g., a [[List (abstract data type)|list]] with elements of arbitrary type) is designated ''polymorphic data type'' like the generalized type from which such specializations are made.
=== Overloading ===
Overloading allows multiple functions taking different types to be defined with the same name; the [[compiler]] or [[Interpreter (computing)|interpreter]] automatically calls the right one. This way, functions appending lists of integers, lists of strings, lists of real numbers, and so on could be written, and all be called ''append''&mdash;and the right ''append'' function would be called based on the type of lists being appended. This differs from parametric polymorphism, in which the function would need to be written ''generically'', to work with any kind of list. Using overloading, it is possible to have a function perform two completely different things based on the type of input passed to it; this is not possible with parametric polymorphism.
 
Parametric polymorphism is ubiquitous in functional programming, where it is often simply referred to as "polymorphism". The next example in [[Haskell]] shows a parameterized list data type and two parametrically polymorphic functions on them:
This type of polymorphism is common in [[object-oriented programming]] languages, many of which allow [[operator]]s to be overloaded in a manner similar to functions (see [[operator overloading]]). It is also used extensively in the purely functional programming language [[Haskell]]. Many languages lacking ad-hoc polymorphism suffer from long-winded names such as <code>print_int</code>, <code>print_string</code>, etc. (see [[Objective Caml]]).
 
<syntaxhighlight lang="Haskell">
=== Coercion ===
data List a = Nil | Cons a (List a)
Due to a concept known as '''coercion''', a function can become polymorphic without being initially designed for it. Let <var>f</var> be a function that takes an argument of type <var>T</var>, and <var>S</var> be a type that can be ''automatically converted'' to <var>T</var>. Then <var>f</var> can be said to be polymorphic with respect to <var>S</var> and <var>T</var>.
 
length :: List a -> Integer
Some languages (e.g., [[C (programming language)|C]], [[Java (programming language)|Java]]), provide a fixed set of conversion rules, while others (e.g., [[C Plus Plus]]) allow new conversion rules to be defined by the programmer. While calling C &ldquo;polymorphic&rdquo; is perhaps stretching it, the facility for automatic conversion (i.e., ''casting operators'') found in C++ adds a whole new class of polymorphism to the language.
length Nil = 0
length (Cons x xs) = 1 + length xs
 
map :: (a -> b) -> List a -> List b
== Example ==
map f Nil = Nil
This example aims to illustrates the three different kinds of polymorphism described in this article. Though overloading an originally arithmetic operator to do a wide variety of things in this way may not be the most clear-cut example, it allows some subtle points to be made. In practice, the different types of polymorphism are not generally mixed up as much as they are here.
map f (Cons x xs) = Cons (f x) (map f xs)
</syntaxhighlight>
 
Parametric polymorphism is also available in several object-oriented languages. For instance, [[Template (C++)|templates]] in [[C++]] and [[D (programming language)|D]], or under the name [[Generics in Java|generics]] in [[C Sharp (programming language)|C#]], [[Delphi (software)|Delphi]], Java, and [[Go (programming language)|Go]]:
Imagine, if you will, an operator <code>+</code> that may be used in the following ways:
# <code>1 + 2 &rArr; 3</code>
# <code>3.14 + 0.0015 &rArr; 3.1415</code>
# <code>1 + 3.7 &rArr; 4.7</code>
# <code>[1, 2, 3] + [4, 5, 6] &rArr; [1, 2, 3, 4, 5, 6]</code>
# <code>[true, false] + [false, true] &rArr; [true, false, false, true]</code>
# <code>"foo" + "bar" &rArr; "foobar"</code>
 
<syntaxhighlight lang="CSharp">
=== Overloading ===
class List<T> {
To handle these six function calls, four different pieces of code are needed&mdash;or ''three'', if strings are considered to be lists of characters:
class Node<T> {
* In the first case, [[integer (computer science)|integer]] addition is invoked.
T elem;
* In the second and third cases, [[floating point|floating-point]] addition is invoked.
Node<T> next;
* In the fourth and fifth cases, [[list]] concatenation is invoked.
}
* In last case, [[literal string|string]] concatenation is invoked, unless this too is handled as list concatenation.
Node<T> head;
Thus, the name <code>+</code> actually refers to three or four completely different functions. This is an example of ''overloading''.
int length() { ... }
}
 
List<B> map(Func<A, B> f, List<A> xs) {
=== Coercion ===
...
As we&rsquo;ve seen, there&rsquo;s one function for adding two integers and one for adding two floating-point numbers in this hypothetical programming environment, but note that there is no function for adding an integer to a floating-point number. The reason why we can still do this is that when the [[compiler]]/[[Interpreter (computing)|interpreter]] finds a function call <code>f(a1,&nbsp;a2,&nbsp;...)</code> that no existing function named <code>f</code> can handle, it starts to look for ways to convert the arguments into different types in order to make the call conform to the signature of one of the functions named <code>f</code>. This is called ''coercion''. Both coercion and overloading are kinds of ''ad-hoc polymorphism''.
}
</syntaxhighlight>
 
[[John C. Reynolds]] (and later [[Jean-Yves Girard]]) formally developed this notion of polymorphism as an extension to lambda calculus (called the polymorphic lambda calculus or [[System F]]). Any parametrically polymorphic function is necessarily restricted in what it can do, working on the shape of the data instead of its value, leading to the concept of [[parametricity]].
In our case, since any integer can be converted into a floating-point number without loss of precision, <code>1</code> is converted into <code>1.0</code> and floating-point addition is invoked. There was really only one reasonable outcome in this case, because a floating-point number cannot generally be converted into an integer, so integer addition could not have been used; but significantly more complex, subtle, and ambiguous situations can occur in, e.g., [[C Plus Plus|C++]].
 
===Subtyping===
=== Parametric polymorphism ===
{{Further|Subtyping}}
Finally, the reason why we can concatenate both lists of integers, lists of booleans, and lists of characters, is that the function for list concatenation was written without any regard to the type of elements stored in the lists. This is an example of ''parametric polymorphism''. If you wanted to, you could make up a thousand different new types of lists, and the generic list concatenation function would happily and without requiring any augmentation accept instances of them all.
Some languages employ the idea of ''subtyping'' (also called ''subtype polymorphism'' or ''inclusion polymorphism'') to restrict the range of types that can be used in a particular case of polymorphism. In these languages, subtyping allows a function to be written to take an object of a certain type ''T'', but also work correctly, if passed an object that belongs to a type ''S'' that is a subtype of ''T'' (according to the [[Liskov substitution principle]]). This type relation is sometimes written {{nowrap|''S'' <: ''T''}}. Conversely, ''T'' is said to be a ''supertype'' of ''S'', written {{nowrap|''T'' :> ''S''}}. Subtype polymorphism is usually resolved dynamically (see below).
 
In the following Java example cats and dogs are made subtypes of pets. The procedure <code>letsHear()</code> accepts a pet, but will also work correctly if a subtype is passed to it:
It can be argued, however, that this polymorphism is not really a property of the function ''per se''; that if the function is polymorphic, it is due to the fact that the ''list datatype'' is polymorphic. This is true&mdash;to an extent, at least&mdash;but it is important to note that the function could just as well have been defined to take as a second argument an ''element'' to append to the list, instead of another list to concatenate to the first. If this were the case, the function would indisputably be parametrically polymorphic, because it could then not know ''anything'' about its second argument
 
<syntaxhighlight lang="java">
abstract class Pet {
abstract String speak();
}
 
class Cat extends Pet {
------------------------------------------------------------
String speak() {
return "Meow!";
}
}
 
class Dog extends Pet {
'''Polymorphism''', in computer underground terms, also refers to '''[[polymorphic code]]''', computer code that [[mutation|mutates]] for each new time it is executed. This is sometimes used by [[computer virus]]es, [[computer worm]]s and [[shellcode]]s to hide the presence of their decryption engines.
String speak() {
return "Woof!";
}
}
 
static void letsHear(final Pet pet) {
System.out.println(pet.speak());
}
 
static void main(String[] args) {
letsHear(new Cat());
letsHear(new Dog());
}
</syntaxhighlight>
 
[[File:UML class pet.svg]]
 
In another example, if ''Number'', ''Rational'', and ''Integer'' are types such that {{nowrap|''Number'' :> ''Rational''}} and {{nowrap|''Number'' :> ''Integer''}} (''Rational'' and ''Integer'' as subtypes of a type ''Number'' that is a supertype of them), a function written to take a ''Number'' will work equally well when passed an ''Integer'' or ''Rational'' as when passed a ''Number''. The actual type of the object can be hidden from clients into a [[black box]], and accessed via object [[identity (object-oriented programming)|identity]]. If the ''Number'' type is ''abstract'', it may not even be possible to get your hands on an object whose ''most-derived'' type is ''Number'' (see [[abstract data type]], [[abstract class]]). This particular kind of type hierarchy is known, especially in the context of the [[Scheme (programming language)|Scheme language]], as a ''[[numerical tower]]'', and usually contains many more types.
 
[[Object-oriented programming language]]s offer subtype polymorphism using ''[[Subclass (computer science)|subclass]]ing'' (also known as ''[[inheritance in object-oriented programming|inheritance]]''). In typical implementations, each class contains what is called a ''[[virtual table]]'' (shortly called ''vtable'') — a table of functions that implement the polymorphic part of the class interface—and each object contains a pointer to the vtable of its class, which is then consulted whenever a polymorphic method is called. This mechanism is an example of:
* ''[[late binding]]'', because virtual function calls are not bound until the time of invocation;
* ''[[single dispatch]]'' (i.e., single-argument polymorphism), because virtual function calls are bound simply by looking through the vtable provided by the first argument (the <code>this</code> object), so the runtime types of the other arguments are completely irrelevant.
The same goes for most other popular object systems. Some, however, such as [[Common Lisp Object System]], provide ''[[multiple dispatch]]'', under which method calls are polymorphic in ''all'' arguments.
 
The interaction between parametric polymorphism and subtyping leads to the concepts of [[covariance and contravariance (computer science)|variance]] and [[bounded quantification]].
 
===Row polymorphism===
{{Further|Row polymorphism}}
{{see also|Duck typing}}
 
Row polymorphism<ref>
{{cite conference
|first=Mitchell
|last=Wand
|title=Type inference for record concatenation and multiple inheritance
|book-title=Proceedings. Fourth Annual Symposium on Logic in Computer Science
|pages=92–97
|date=June 1989
|doi=10.1109/LICS.1989.39162
}}
</ref> is a similar, but distinct concept from subtyping. It deals with [[Structural type system|structural types]]. It allows the usage of all values whose types have certain properties, without losing the remaining type information.
 
===Polytypism===
{{Further|Generic programming#Functional languages}}
A related concept is ''polytypism'' (or ''data type genericity''). A polytypic function is more general than polymorphic, and in such a function, "though one can provide fixed ad hoc cases for specific data types, an ad hoc combinator is absent".<ref>{{cite book |first1=Ralf |last1=Lämmel |first2=Joost |last2=Visser |chapter=Typed Combinators for Generic Traversal |title=Practical Aspects of Declarative Languages: 4th International Symposium |publisher=Springer |date=2002 |isbn=354043092X |pages=137–154, See p. 153 |citeseerx=10.1.1.18.5727 |url=}}</ref>
 
===Rank polymorphism===
Rank polymorphism is one of the defining features of the [[array programming]] languages, like [[APL (programming language)|APL]]. The essence of the rank-polymorphic programming model is implicitly treating all operations as aggregate operations, usable on arrays with arbitrarily many dimensions,<ref>{{cite arXiv |last1=Slepak |first1=Justin |last2=Shivers |first2=Olin |last3=Manolios |first3=Panagiotis |date=2019 |title=The semantics of rank polymorphism |class=cs.PL |eprint=1907.00509}}</ref> which is to say that rank polymorphism allows functions to be defined to operate on arrays of any shape and size.
 
==Implementation aspects==
===Static and dynamic polymorphism===
{{Further|Static polymorphism|Late binding|Dynamic dispatch}}
 
Polymorphism can be distinguished by when the implementation is selected: statically (at compile time) or dynamically (at run time, typically via a [[virtual function]]). This is known respectively as ''[[static dispatch]]'' and ''[[dynamic dispatch]],'' and the corresponding forms of polymorphism are accordingly called ''static polymorphism'' and ''dynamic polymorphism''.
 
Static polymorphism executes faster, because there is no dynamic dispatch overhead, but requires additional compiler support. Further, static polymorphism allows greater static analysis by compilers (notably for optimization), source code analysis tools, and human readers (programmers). Dynamic polymorphism is more flexible but slower—for example, dynamic polymorphism allows [[Duck typing|duck typing]], and a dynamically linked library may operate on objects without knowing their full type.
 
Static polymorphism typically occurs in ad hoc polymorphism and parametric polymorphism, whereas dynamic polymorphism is usual for subtype polymorphism. However, it is possible to achieve static polymorphism with subtyping through more sophisticated use of [[template metaprogramming]], namely the [[curiously recurring template pattern]].
 
When polymorphism is exposed via a [[Library (computing)|library]], static polymorphism becomes impossible for [[dynamic libraries]] as there is no way of knowing what types the parameters are when the [[shared object]] is built. While languages like C++ and Rust use [[monomorphization|monomorphized]] templates, the [[Swift programming language]] makes extensive use of dynamic dispatch to build the [[application binary interface]] for these libraries by default. As a result, more code can be shared for a reduced system size at the cost of runtime overhead.<ref>{{cite web |last1=Beingessner |first1=Alexis |title=How Swift Achieved Dynamic Linking Where Rust Couldn't |url=https://gankra.github.io/blah/swift-abi/}}</ref>
 
==See also==
* [[Type class]]
* [[Virtual inheritance]]
 
==References==
{{Reflist}}
 
==External links==
* [http://www.cplusplus.com/doc/tutorial/polymorphism/ C++ examples of polymorphism]
* [http://wiki.visual-prolog.com/index.php?title=Objects_and_Polymorphism Objects and Polymorphism (Visual Prolog)]
* [https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/object-oriented/polymorphism Polymorphism on MSDN]
* [https://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html Polymorphism Java Documentation on Oracle]
 
{{Data types}}
 
{{DEFAULTSORT:Polymorphism}}
[[Category:Polymorphism (computer science)| ]]
[[Category:Data types]]
[[Category:Functional programming]]
[[Category:Object-oriented programming]]
[[Category:Programming language concepts]]
[[Category:Type theory]]
[[Category:Generic programming]]
[[Category:Programming language comparisons]]
<!-- Hidden categories below -->
[[Category:Articles with example C Sharp code]]
[[Category:Articles with example Haskell code]]
[[Category:Articles with example Java code]]
[[Category:Articles with example Pascal code]]