Difference between revisions of "Polymorphism"
Jump to navigation
Jump to search
BrettGiles (talk | contribs) (Hawiki conversion) |
BrettGiles (talk | contribs) m (Fix list) |
||
Line 4: | Line 4: | ||
Various kinds of polymorphism are identified. |
Various kinds of polymorphism are identified. |
||
− | + | #Parametric polymorphism; mostly found in functional languages |
|
− | + | #Inclusion polymorphism; mostly found in object oriented languages |
|
− | + | #Ad hoc polymorphism; typically C++ overloading |
|
== Haskell Examples == |
== Haskell Examples == |
Revision as of 16:40, 19 October 2006
A value is called polymorphic if, depending on the context where it's used, it can take on more than one type.
Various kinds of polymorphism are identified.
- Parametric polymorphism; mostly found in functional languages
- Inclusion polymorphism; mostly found in object oriented languages
- Ad hoc polymorphism; typically C++ overloading
Haskell Examples
foldr :: forall a b. (a -> b -> b) -> b -> [a] -> b
foldr
is a typical example of a polymorphic function. When actually used, it may take on any of a variety of types, for example:
::(Char ->Int->Int)->Int->String->Int
::(String->String->String)->String->[String]->String
An "integer literal" is polymorphic:
1 :: forall t. (Num t) => t
References
- On Understanding Types, Data Abstraction, and Polymorphism (1985), by Luca Cardelli, Peter Wegner in ACM Computing Surveys.