data Point = Point { x :: Double, y :: Double } data Circle = Circle { center :: Point, radius :: Double } data Rectangle = Rectangle { edge1 :: Point, edge2 :: Point } class Shape a where area :: a -> Double instance Shape Circle where area :: Circle -> Double area (Circle {radius = r}) = pi * r^2 instance Shape Rectangle where area :: Rectangle -> Double area (Rectangle {edge1 = Point {x = x1, y = y1} , edge2 = Point {x = x2, y = y2}}) = length * width where length = abs (x1 - x2) width = abs (y1 - y2) main = print $ area $ Rectangle (Point 0 0) (Point 3 4)