Personal tools


From HaskellWiki

Revision as of 03:13, 17 February 2007 by BrettGiles (Talk | contribs)

Jump to: navigation, search

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.

  1. Parametric polymorphism; mostly found in functional languages
  2. Inclusion polymorphism; mostly found in object oriented languages
  3. Ad-hoc polymorphism; typically C++ overloading

1 Haskell Examples

foldr :: forall a b. (a -> b -> b) -> b -> [a] -> b
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

An "integer literal" is polymorphic:

1 :: forall t. (Num t) => t

2 References