{"id":10,"date":"2007-07-25T22:40:13","date_gmt":"2007-07-26T05:40:13","guid":{"rendered":"http:\/\/www.elbeno.com\/haskell_soe_blog\/?p=10"},"modified":"2008-01-07T21:43:33","modified_gmt":"2008-01-08T05:43:33","slug":"exercise-25","status":"publish","type":"post","link":"https:\/\/www.elbeno.com\/haskell_soe_blog\/?p=10","title":{"rendered":"Exercise 2.5"},"content":{"rendered":"<pre lang=\"haskell\">{-\r\nArea of a shape: compute by adding up the trapezoidal areas\r\nformed by pair of vertices with the x-axis.\r\nThis can (correctly) be negative when x2 > x1.\r\n-}\r\n\r\naxisTrapezoidArea :: Vertex -> Vertex -> Float\r\naxisTrapezoidArea (x1, y1) (x2, y2) = (x1 - x2) * (y1 + y2) * 0.5\r\n\r\narea :: Shape -> Float\r\narea (Polygon (v1:vs)) = polyArea v1 vs\r\n    where polyArea v (vnext:vs') = axisTrapezoidArea v vnext\r\n                                   + polyArea vnext vs'\r\n          polyArea vlast [] = axisTrapezoidArea vlast v1<\/pre>\n<p>Wrapping the head of a list in this way is more idiomatically done with<\/p>\n<pre lang=\"haskell\">list ++ [head list]<\/pre>\n<p>rather than pattern matching the end of the list. However, at this stage in the book, we&#8217;re Haskell newbies.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>{- Area of a shape: compute by adding up the trapezoidal areas formed by pair of vertices with the x-axis. This can (correctly) be negative when x2 > x1. -} axisTrapezoidArea :: Vertex -> Vertex -> Float axisTrapezoidArea (x1, y1) (x2, y2) = (x1 &#8211; x2) * (y1 + y2) * 0.5 area :: Shape [&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\/10"}],"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=10"}],"version-history":[{"count":0,"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=\/wp\/v2\/posts\/10\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}