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}) = 3.14 * r^2 instance Shape Rectangle where area :: Rectangle -> Double area (Rectangle {edge1 = edge1, edge2 = edge2}) = length * width where length = abs (x1 - x2) where Point {x = x1} = edge1 -- HERE!! Point {x = x2} = edge2 width = abs (y1 - y2) where Point {y = y1} = edge1 Point {y = y2} = edge2 main = print $ area $ Rectangle (Point 0 0) (Point 3 4)