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"
Your email address will not be published. Required fields are marked *