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
This entry was posted
on Saturday, June 30th, 2007 at 2:58 pm and is filed under Haskell - SOE.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.