07.26.07

Exercise 5.1

Posted in Uncategorized at 9:52 pm by admin

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.

1 Comment »

  1. Wiesław Poszewiecki said,

    November 2, 2010 at 9:05 am

    With foldr
    area” (Polygon (v1:vs)) = foldr (\(v2,v3) ->(+) ( triArea v1 v2 v3)) 0.0 (zip vs (tail vs))

Leave a Comment