Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AddGroup a where
- (+), (-) :: a -> a -> a
- negate :: a -> a
- x - y = x + (negate y)
- data Vector = Vector { dx :: Double
- , dy :: Double
- } deriving (Show, Eq)
- instance AddGroup Vector where
- (Vector dx1 dy1) + (Vector dx2 dy2) = Vector (dx1 + dx2) (dy1 + dy2)
- negate (Vector dx dy) = Vector (-dx) (-dy)
- main = do
- putStrLn $ show $ (Vector 1 2) + (Vector 3 4)
- -- I get the following errors:
- -- So I should write Prelude.+ for every Double addition??
- {-
- Geom.hs:4:14:
- Ambiguous occurrence `+'
- It could refer to either `Main.+', defined at Geom.hs:2:4
- or `Prelude.+', imported from Prelude
- Geom.hs:4:17:
- Ambiguous occurrence `negate'
- It could refer to either `Main.negate', defined at Geom.hs:3:4
- or `Prelude.negate', imported from Prelude
- Geom.hs:11:54:
- Ambiguous occurrence `+'
- It could refer to either `Main.+', defined at Geom.hs:2:4
- or `Prelude.+', imported from Prelude
- Geom.hs:11:66:
- Ambiguous occurrence `+'
- It could refer to either `Main.+', defined at Geom.hs:2:4
- or `Prelude.+', imported from Prelude
- Geom.hs:15:35:
- Ambiguous occurrence `+'
- It could refer to either `Main.+', defined at Geom.hs:2:4
- or `Prelude.+', imported from Prelude
- -}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement