fork download
  1. type Height = Float
  2. type Width = Float
  3. type Radius = Float
  4. data Rectangle = Rectangle Height Width
  5. data Circle = Circle Radius
  6.  
  7. class (Eq a, Show a) => Shape a where
  8. area :: a -> Float
  9. perimeter :: a -> Float
  10.  
  11. instance Eq Rectangle where
  12. (Rectangle h w) == (Rectangle c d) = (h == c) && (w == d)
  13.  
  14. instance Show Rectangle where
  15. show (Rectangle h w) = "rectangle " ++ (show h) ++ " " ++ (show w)
  16.  
  17. instance Shape Rectangle where
  18. area (Rectangle h w) = h * w
  19. perimeter (Rectangle h w) = h*2 + w*2
  20.  
  21. instance Eq Circle where
  22. (Circle r) == (Circle x) = r == x
  23.  
  24. instance Show Circle where
  25. show (Circle r) = "circle " ++ (show r)
  26.  
  27. instance Shape Circle where
  28. area (Circle r) = pi * r**2
  29. perimeter (Circle r) = 2 * pi * r
  30.  
  31. main = print "foo"
Success #stdin #stdout 0s 4696KB
stdin
Standard input is empty
stdout
"foo"