fork download
  1. import Control.Arrow
  2.  
  3. cross ((ax, ay), (bx, by), (cx, cy)) =
  4. (bx - ax) * (cy - ay) - (cx - ax) * (by - ay)
  5.  
  6. groupInPairs (a:b:xs) = scanl (curry $ first snd) (a, b) xs
  7. triangulate = uncurry (map . (uncurry . (,,))) . (head &&& groupInPairs . tail)
  8. task = (/ 2) . sum . map (abs . cross) . triangulate
  9.  
  10. main = print $ task [(0, 0), (0, 1), (1, 1), (2, 0)]
  11.  
Success #stdin #stdout 0.01s 3680KB
stdin
Standard input is empty
stdout
1.5