geometry.hs 369 B

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