Exercise 5.2


map map [x] = [map x]

Therefore:

x :: a -> b

because x is the first argument to map. Consider the type of map:

map :: (a -> b) -> [a] -> [b]

This implies:

map x :: [a] -> [b]
[map x] :: [[a] -> [b]]

And hence:

map map :: [a -> b] -> [[a] -> [b]]

–

foldl foldl x [y] = ?

This is a type error. See technical error 10.

–

map foldl [x] = [foldl x]

And as before:

foldl :: (a -> b -> a) -> a -> [b] -> a
x :: a -> b -> a
foldl x :: a -> [b] -> a
[foldl x] :: [a -> [b] -> a]
map foldl :: [a -> b -> a] -> [a -> [b] -> a]

2 responses to “Exercise 5.2”

  1. I do not understand the first one, map map. The first argument to map is a function (a->b). I don’t see how “map” can serve as the first argument. Hope you can help. I don’t follow the leap from the second last line to the conclusion.

  2. Using different type variables to make it clearer, the type (a -> b) can be unified with the type (c -> d) -> [c] -> [d] by considering a = (c -> d) and b = [c] -> [d]. So it is perfectly OK for map to be the first argument to map.

Leave a Reply

Your email address will not be published. Required fields are marked *