Hello,
I have just begun reading Hudak's The Haskell School of Expression
and i am wondering something about the manner he calculates
the area of a polygon (made of vertices) on page 27.
He wrote:
area(Polygon (v1:vs)) = polyArea vs
where polyArea :: [Vertex] -> Float
polyArea (v2:v3:vs') = triArea v1 v2 v3 + polyArea(v3:vs')
polyArea _ = 0
i do not understand why variable v1 is pattern-matched in
the definition of area and made "global" to polyArea instead
of doing it with polyArea like this:
area(Polygon vs) = polyArea vs
where polyArea :: [Vertex] -> Float
polyArea (v1:v2:v3:vs') = triArea v1 v2 v3 + polyArea(v3:vs')
polyArea _ = 0
Is it an idiom or some sort of optimization ?
Or just the way he likes it ?
TIA
Ludovic Kuty
_______________________________________________
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe