doubleEach :: [Int] -> [Int]
doubleEach xs = map (\x -> x * 2) xs
doubleEach' (x:xs) = (x * 2) : doubleEach' xs
doubleEach' [] = []
pairAndOne :: [Int] -> [(Int, Int)]
pairAndOne xs = zip xs (map (\x -> x + 1) xs)
pairAndOne' (x:xs) = (x, x+1) : pairAndOne' xs
pairAndOne' [] = []
addEachPair :: [(Int, Int)] -> [Int]
addEachPair xs = map (\(a,b) -> a + b) xs
addEachPair' ((a,b):xs) = (a + b) : addEachPair' xs
addEachPair' [] = []
One response to “Exercise 5.5”
[…] Instances where we can curry and convert anonymous functions to sections are easy to find, for example from Exercise 5.5: […]