Type inference

In these exercises you should assume the following types:

(+)    :: Int -> Int -> Int
even   :: Int -> Bool

head   :: [a] -> a
(++)   :: [a] -> [a] -> [a]
foldr  :: (a -> b -> b) -> b -> [a] -> b
map    :: (a -> b) -> [a] -> [b]
concat :: [[a]] -> [a]
(.)    :: (b -> c) -> (a -> b) -> a -> c

1 atHome

What is the type of head ([3, 2] ++ [2])? Give the type derivation.

2 atHome

What is the type of (+) 3? Give the type derivation.

3 atHome

What is the type of map even? Give the type derivation.

4 atHome

What is the type of map concat? Give the type derivation.

5 inClass

What is the type of map head? Give the type derivation.

6 atHome

What is the type of reverse . reverse? Give the type derivation.

7 atHome

What is the type of foldr (+)? Give the type derivation.

8 inClass

What is the type of foldr map? Give the type derivation.

  1. [a] -> [a -> a] -> [a]
  2. [a] -> [[a -> a]] -> [a]
  3. [a] -> [[a -> a] -> [a]]
  4. [[a]] -> [a -> a] -> [a]

9 atHome

What is the type of map . foldr? Give the type derivation.

  1. (a -> a -> a) -> [a] -> [[a] -> a]
  2. (a -> a -> a) -> [b] -> [b -> a]
  3. (b -> a -> a) -> [a] -> [[b] -> a]
  4. (b -> a -> a) -> [b] -> [[a] -> a]

10 atHome

Which of the following is the type of concat . concat? Give the type derivation.

  1. [[a]] -> [[a]] -> [[a]]
  2. [[a]] -> [[a]] -> [a]
  3. [[[a]]] -> [a]
  4. [a] -> [[a]] -> [a]

11 atHome

What is the type of map map? Give the type derivation.

12 inClass

What is the type of map (map map)? Give the type derivation.

  1. [[a -> b]] -> [[[a] -> [b]]]
  2. [a -> b] -> [[[a] -> [b]]]
  3. [[a -> b]] -> [[[a -> b]]]
  4. [[a -> b] -> [[a] -> [b]]]

Give the type derivation.

13 atHome

Which observation is correct when comparing the types of (map map) map and map (map map)?

  1. The type of the first is less polymorphic than the type of the second.
  2. The type of the first is more polymorphic than the type of the second.
  3. The types are the same, since function composition is associative.
  4. One of the expressions does not have any type at all.

14 atHome

The function maximum has type Ord a => [a] -> a. What is the type of map maximum? Can you give a derivation?