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' [] = [] |

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' [] = []

This entry was posted on Thursday, July 26th, 2007 at 10:58 pm and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.

[…] Instances where we can curry and convert anonymous functions to sections are easy to find, for example from Exercise 5.5: […]