Advertisement
karlicoss

what's wrong?

Jul 30th, 2011
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class AddGroup a where
  2.     (+), (-) :: a -> a -> a
  3.     negate   :: a -> a
  4.     x - y = x + (negate y)
  5.  
  6. data Vector = Vector { dx :: Double
  7.                      , dy :: Double
  8.                      } deriving (Show, Eq)
  9.  
  10. instance AddGroup Vector where
  11.     (Vector dx1 dy1) + (Vector dx2 dy2) = Vector (dx1 + dx2) (dy1 + dy2)
  12.     negate (Vector dx dy) = Vector (-dx) (-dy)
  13.  
  14. main = do
  15.     putStrLn $ show $ (Vector 1 2) + (Vector 3 4)
  16.  
  17. -- I get the following errors:
  18. -- So I should write Prelude.+ for every Double addition??
  19.  
  20. {-
  21.  
  22. Geom.hs:4:14:
  23.     Ambiguous occurrence `+'
  24.     It could refer to either `Main.+', defined at Geom.hs:2:4
  25.                           or `Prelude.+', imported from Prelude
  26.  
  27. Geom.hs:4:17:
  28.     Ambiguous occurrence `negate'
  29.     It could refer to either `Main.negate', defined at Geom.hs:3:4
  30.                           or `Prelude.negate', imported from Prelude
  31.  
  32. Geom.hs:11:54:
  33.     Ambiguous occurrence `+'
  34.     It could refer to either `Main.+', defined at Geom.hs:2:4
  35.                           or `Prelude.+', imported from Prelude
  36.  
  37. Geom.hs:11:66:
  38.     Ambiguous occurrence `+'
  39.     It could refer to either `Main.+', defined at Geom.hs:2:4
  40.                           or `Prelude.+', imported from Prelude
  41.  
  42. Geom.hs:15:35:
  43.     Ambiguous occurrence `+'
  44.     It could refer to either `Main.+', defined at Geom.hs:2:4
  45.                           or `Prelude.+', imported from Prelude
  46. -}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement