Parametric polymorphism
From HaskellWiki
(Difference between revisions)
(...have I got this right?) |
m (typo) |
||
| Line 1: | Line 1: | ||
| - | Parametric polymorphism is when a function's type signature allows various arguments to take on arbitrary types, but the types | + | Parametric polymorphism is when a function's type signature allows various arguments to take on arbitrary types, but the types must be ''related'' to each other in some way. |
For example, in Java one can write a function that accepts two arguments of any possible type. However, Haskell goes further by allowing a function to accept two arguments of any type so long as they are both ''the same'' type. For example | For example, in Java one can write a function that accepts two arguments of any possible type. However, Haskell goes further by allowing a function to accept two arguments of any type so long as they are both ''the same'' type. For example | ||
Revision as of 22:15, 20 May 2007
Parametric polymorphism is when a function's type signature allows various arguments to take on arbitrary types, but the types must be related to each other in some way.
For example, in Java one can write a function that accepts two arguments of any possible type. However, Haskell goes further by allowing a function to accept two arguments of any type so long as they are both the same type. For example
As a specific (and slightly more complicated) example, the well-knownmap
map :: (a -> b) -> [a] -> [b]
map
