In Haskell, one can define a data type like so:
data Point1 = Point1 {
x :: Integer
, y :: Integer
}
Can one use type classes for variables inside a data type? If so how? I realize it is possible to do this as an algebraic data type, with a different definition for each kind of point, but I'm wondering if there's a way to accomplish this in a more compact and flexible manner.
e.g. Something along the lines of this pseudocode which uses function declaration syntax:
data Point2 = Point2 {
x :: (Num a, Ord a) => a
, y :: (Num a, Ord a) => a
}
The goal would be to allow one to store Int, Integer, Float or Double values in the data type. Ideally, I'd like to restrict it so that x and y must be of the same type.