data Point = Point Float Float deriving (Show, Ord, Eq)
(+) :: Point -> Point -> Point
(Point x1 y1) + (Point x2 y2) = Point (x1 + x2) (y1 + y2)
Gives me an error on loading into ghci.
It seems to me that x1, x2, y1, y2 should be easily inferred as Float - because they are when I declared them as arguments to the Point constructor.
src/Shapes.hs:4:53: error:
Ambiguous occurrence ‘+’
It could refer to
either ‘Prelude.+’,
imported from ‘Prelude’ at src/Shapes.hs:1:1
(and originally defined in ‘GHC.Num’)
or ‘Main.+’, defined at src/Shapes.hs:4:15
|
4 | (Point x1 y1) + (Point x2 y2) = Point (x1 + x2) (y1 + y2)
Yet (Point 0 0) < (Point 1 1)
works without throwing an error.
- What is my mistake?
- How should I perform this overloading idiomatically?