Functional Programming (H) - 3.06 - What Have We Learned About Lists?

1. A recursive function must have at least two cases. What are these called?

2. What is wrong with the following definition of filter?

filter :: (a -> Bool) -> [a] -> [a] filter pred [] = [] filter pred (x:xs) | pred x = x : filter pred xs | otherwise = filter pred (x:xs)

3. What is the effect of the following fold?

foldl (\acc elt -> acc++[elt]) "" "A string"

4. What is the wrong with the following map/fold-based computation?

foldl (+) (map (*2) [1..8])

5. What is the result of the following computation?

foldr (/) 1 [2,4,8]

6. What is the result of the following computation?

foldl (/) 16 [8,4,2,1]