Dear Haskell Fans, I'm afraid that I'm a bit dumb but I'm somewhat
stuck. 

Can someone give me a hand on this problem

I wrote this code to solve SOE, exc 5.1. 

import Shape

triangleArea :: [Vertex] -> Float
triangleArea (v1:v2:v3:_) = let a = distBetween v1 v2
                                b = distBetween v2 v3
                                c = distBetween v3 v1
                                s = 0.5 * (a + b + c)
                                in sqrt (s * (s-a) *(s-b) * (s-c))
triangleArea _             = 0


o_array :: Shape -> Float
o_array (Polygon (v1:vs)) =  
   let ph = phelp vs
   in
     foldr (+) 0.0 (map triangleArea ph)
     where phelp :: [Vertex] -> [[Vertex]]
           phelp (v2:v3:vs) = (v1:v2:v3:[]):phelp (v3:vs)
           phelp _          = []


what I want is to replace the recursive phelp function with a function
using higher order functions. 

My base idea is splitting up List of Vertices into a list of exactly
three vertices calculating that area and adding them all. 

BTW, I do not like the above solution anyway. It's too bulky. So if one has
another idea on how to tackle it, I would be very thankful to some
hint. 

Best regards
Friedrich

-- 
for e-mail reply remove all after .com 

Reply via email to