07.26.07

Exercise 5.2

Posted in Uncategorized at 10:12 pm by admin

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 Comments »

  1. Mike said,

    March 29, 2009 at 10:29 pm

    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. admin said,

    March 29, 2009 at 10:55 pm

    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 Comment