{"id":28,"date":"2007-07-28T21:56:05","date_gmt":"2007-07-29T04:56:05","guid":{"rendered":"http:\/\/www.elbeno.com\/haskell_soe_blog\/?p=28"},"modified":"2008-01-07T22:08:20","modified_gmt":"2008-01-08T06:08:20","slug":"exercise-74","status":"publish","type":"post","link":"https:\/\/www.elbeno.com\/haskell_soe_blog\/?p=28","title":{"rendered":"Exercise 7.4"},"content":{"rendered":"<p>It&#8217;s not clear what the action of <tt>zip<\/tt> should be on trees with data only at the leaves: if the two trees are mismatched, what should the zipped tree look like? So it is easier to define <tt>zipWith<\/tt> on an <tt>InternalTree<\/tt>, and of course to define <tt>zip<\/tt> in terms of <tt>zipWith<\/tt>.<\/p>\n<pre lang=\"haskell\">zipWithInternalTree :: (a -> b -> c) -> InternalTree a\r\n                    -> InternalTree b -> InternalTree c\r\nzipWithInternalTree f ILeaf _ = ILeaf\r\nzipWithInternalTree f _ ILeaf = ILeaf\r\nzipWithInternalTree f (IBranch a x y) (IBranch b i j)\r\n    = IBranch (f a b) x' y'\r\n      where x' = (zipWithInternalTree f x i)\r\n            y' = (zipWithInternalTree f y j)\r\n\r\nzipInternalTree :: InternalTree a -> InternalTree b -> InternalTree (a,b)\r\nzipInternalTree x y = zipWithInternalTree (,) x y<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s not clear what the action of zip should be on trees with data only at the leaves: if the two trees are mismatched, what should the zipped tree look like? So it is easier to define zipWith on an InternalTree, and of course to define zip in terms of zipWith. zipWithInternalTree :: (a -> [&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\/28"}],"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=28"}],"version-history":[{"count":0,"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=\/wp\/v2\/posts\/28\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=28"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=28"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=28"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}