Exercise 5.1


Recall the definitions from Exercise 2.3.

area' :: Shape -> Float
area' (Polygon (v1:vs)) = let arealist = map (\(v2, v3) -> triArea v1 v2 v3)
                                         (zip vs (tail vs))
                          in foldl (+) 0 arealist

(zip vs (tail vs)) turns out to be a handy idiom.


One response to “Exercise 5.1”

Leave a Reply

Your email address will not be published. Required fields are marked *