[Haskell-cafe] Area from [(x,y)] using foldl

Chaddaï Fouché chaddai.fouche at gmail.com
Sun Nov 8 15:52:12 EST 2009


On Sun, Nov 8, 2009 at 9:04 PM, michael rice <nowgate at yahoo.com> wrote:

> Of course! Back to the drawing board.
>
>
If I understand the problem correctly, I'm not convinced that foldl is the
right approach (nevermind that foldl is almost never what you want, foldl'
and foldr being the correct choice almost always). My proposition would be
the following :

> area ps = abs . (/2) . sum $ zipWith (\(x,y) (x',y') -> (x - x') * (y +
y')) ps (tail $ cycle ps)

I think it express the algorithm more clearly.

-- 
Jedaï
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091108/3c9a81c8/attachment.html


More information about the Haskell-Cafe mailing list