{"id":21,"date":"2007-07-26T23:08:51","date_gmt":"2007-07-27T06:08:51","guid":{"rendered":"http:\/\/www.elbeno.com\/haskell_soe_blog\/?p=21"},"modified":"2008-01-07T22:01:37","modified_gmt":"2008-01-08T06:01:37","slug":"exercise-57","status":"publish","type":"post","link":"https:\/\/www.elbeno.com\/haskell_soe_blog\/?p=21","title":{"rendered":"Exercise 5.7"},"content":{"rendered":"<p>We&#8217;ve seen <tt>zip<\/tt>, but I don&#8217;t think <tt>unzip<\/tt> has been mentioned. To me it&#8217;s the obvious way to solve this problem.<\/p>\n<pre lang=\"haskell\">addPairsPointwise :: [(Int, Int)] -> (Int, Int)\r\naddPairsPointwise xs = (foldl (+) 0 as, foldl (+) 0 bs)\r\n    where (as,bs) = unzip xs \r\n\r\naddPairsPointwise' xs = addPairsOp xs (0,0)\r\n    where addPairsOp ((x,y):xs) (a,b) = addPairsOp xs (a+x, b+y)\r\n          addPairsOp [] r = r<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>We&#8217;ve seen zip, but I don&#8217;t think unzip has been mentioned. To me it&#8217;s the obvious way to solve this problem. addPairsPointwise :: [(Int, Int)] -> (Int, Int) addPairsPointwise xs = (foldl (+) 0 as, foldl (+) 0 bs) where (as,bs) = unzip xs addPairsPointwise&#8217; xs = addPairsOp xs (0,0) where addPairsOp ((x,y):xs) (a,b) = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=\/wp\/v2\/posts\/21"}],"collection":[{"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=21"}],"version-history":[{"count":0,"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=\/wp\/v2\/posts\/21\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=21"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=21"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=21"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}