07.26.07

Exercise 5.5

Posted in Uncategorized at 10:58 pm by admin

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

1 Comment »

  1. The Haskell School of Expression: Exercises » Exercise 9.12 said,

    August 9, 2007 at 9:13 pm

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

Leave a Comment