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), (1, 0)]
  11.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
[1 of 1] Compiling Main             ( prog.hs, prog.o )

prog.hs:7:50:
    Couldn't match expected type `(a, c)'
           against inferred type `[a1] -> a1'
    In the first argument of `(&&&)', namely `head'
    In the second argument of `($)', namely
        `(head &&& groupInPairs . tail)'
    In the expression:
          uncurry (map . (uncurry . (,,))) $ (head &&& groupInPairs . tail)
stdout
Standard output is empty