SOE ex.12.4



class Area a where
  area :: a -> Float

class Perimeter p where
  perimeter :: p -> Float

class Draw d where
  draw :: d -> IO ()

data Rectangle = Rectangle Float Float

instance Area Rectangle where
  area (Rectangle w h) = w * h

instance Perimeter Rectangle where
  perimeter (Rectangle w h) = 2 * (w + h)

-- instance Draw Rectangle where ...

data Circle = Circle Float

instance Area Circle where
  area (Circle radius) = pi * radius * radius

instance Perimeter Circle where
  perimeter (Circle radius) = 2 * pi * radius

-- instance Draw Circle where ...


-- ... etc


Leave a Reply