Difference Argument Order
ajb at spamcop.net
ajb at spamcop.net
Mon May 23 20:15:24 EDT 2005
G'day all.
Quoting Henning Thielemann <lemming at henning-thielemann.de>:
> I assume that these function are for computations like
> subtract :: DegreeCentigrade -> Kelvin -> DegreeCentigrade
> diff :: DegreeCentigrade -> DegreeCentigrade -> Kelvin
> and the intentions are different enough to implement distinct functions.
> I assume that there will be an implementation for 'diff' whenever there is
> one for 'subtract' and vice versa, thus considering them as different
> instances of the same class does not seem to be a good design.
That's interesting, because I was thinking about homogeneous spaces:
subtract :: Point -> Vector -> Point
diff :: Point -> Point -> Vector
Or:
subtract :: Time -> Duration -> Time
diff :: Time -> Time -> Duration
Or more generally:
class Group g where
id :: g
(+) :: g -> g -> g
negate :: g -> g
class (Group g) => LeftGroupAction g x where
add :: g -> x -> x
subtract :: x -> g -> x
subtract x g = add g (negate x)
class (LeftGroupAction g x) => RegularLeftGroupAction g x where
diff :: x -> x -> g
Cheers,
Andrew Bromage
More information about the Libraries
mailing list