Exercise 8.11

See Exercises 2.4 and 5.1. Then:

area'' :: Shape -> Float
area'' (Polygon (v1:vs)) = if convex (Polygon (v1:vs))
                           then let areas = map ((v2, v3) -> triArea v1 v2 v3)
                                               (zip vs (tail vs))
                                in foldl (+) 0 areas
                           else error "Non-convex polygon"

Leave a Reply