geometry.hs 382 B

123456789101112131415
  1. -- Slide 23
  2. data Point = Point Float Float
  3. data Shape = Singularity Point | Circle Float Point | Square Point Point
  4. distance p1 p2 =
  5. let (Point a b) = p1 in
  6. let (Point c d) = p2 in
  7. sqrt ((a - c) * (a - c) + (b - d) * (b - d))
  8. perimeter sh = case sh of
  9. Singularity _ -> 0.0
  10. Circle r _ -> 3.14 * 2 * r
  11. Square (Point a b) (Point c d) -> 2 * abs (a - c) + 2 * abs (b - d)