HaskellWiki

Haskell | Wiki community | Recent changes
Random page | Special pages

 

Not logged in
Log in | Help

Request an account if you don't have one.

Polymorphism

Categories: Glossary

A value is polymorphic if, depending on the context where it's used, it can take on more than one type.

There are different kinds of polymorphism.

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

1 Examples

foldr :: forall a b. (a -> b -> b) -> b -> [a] -> b

foldr is a parametric 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 a parametric polymorphic data type:

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

2 References

Retrieved from "http://haskell.cs.yale.edu/haskellwiki/Polymorphism"

This page has been accessed 9,429 times. This page was last modified 07:02, 6 October 2009. Recent content is available under a simple permissive license.