Next | Atypical Types | 59 |
map :: (a -> b, [a]) -> [b]
Normally map is defined as a curried function
Instead of this:
map(f, []) = [] map(f, h:t) = f(h) : map(f, t)
We write this:
map f [] = [] map f (h:t) = f(h) : map f t
And the type is:
map :: (a -> b) -> [a] -> [b]
Then for example:
length :: [a] -> Integer map length ["I", "like", "pie"] [1, 4, 3]
length_all = map length length_all :: [[a]] -> [Integer] length_all ["I", "like", "pie"] [1, 4, 3]
Next | Copyright © 1999,2008 Mark Dominus |