[Haskell-cafe] Type question re: map
skynare at gmail.com
Fri Mar 6 23:43:39 EST 2009
map :: (a -> b) -> [a] -> [b]
map takes a function and transforms a list of a's to b's.
map succ [1,2,3]
==> [succ 1, succ 2, succ 3]
==> [2, 3, 4]
map f :: [a] -> [b]
where a is domain-type of f and b is image-type of f (f :: a -> b).
map map [x, y, z]
==> [map x, map y, map z]
so, x,y,z should functions of type (a -> b).
and the result list, [map x, map y, map z], should have type [([a] -> [b])]
map x :: [a] -> [b] where x :: a -> b
On 3/6/09, R J <rj248842 at hotmail.com> wrote:
> Given the following (usual) definition of "map":
> map :: (a -> b) -> [a] -> [b]
> map f  = 
> map f (x : xs) = f x : map f xs
> What's the type of "map map"?
> GHCi's :t command reveals:
> *Main> :t map map
> map map :: [a -> b] -> [[a] -> [b]]
> I'd be grateful if anyone could provide a systematic type calculation so
> that I can reason through more complicated examples myself.
> Windows Live™: Life without walls.
More information about the Haskell-Cafe