
Which of these argument orders is more intuitive to you? 1. This one makes more sense when considering the function formed by applying one argument: add :: Diff -> Absolute -> Absolute add d a = a + d subtract :: Diff -> Absolute -> Absolute subtract d a = a - d diff :: Absolute -> Absolute -> Diff diff a b = b - a So "add x", "subtract y" and perhaps "diff z" are intuitively useful functions. And we also have "subtract = add . negate". 2. This one is more familiar for the English language and for the standard operators: add :: Absolute -> Diff -> Absolute add a d = a + d subtract :: Absolute -> Diff -> Absolute subtract a d = a - d diff :: Absolute -> Absolute -> Diff diff a b = a - b -- Ashley Yakeley, Seattle WA

G'day all.
Quoting Ashley Yakeley
Which of these argument orders is more intuitive to you?
This one:
2. This one is more familiar for the English language and for the standard operators:
add :: Absolute -> Diff -> Absolute add a d = a + d subtract :: Absolute -> Diff -> Absolute subtract a d = a - d diff :: Absolute -> Absolute -> Diff diff a b = a - b
But even better would be if you could do both, and not distinguish between subtract and diff: class Add a b c | a b -> c where add :: a -> b -> c class Subtract a b c | a b -> c where subtract :: a -> b -> c ...you get the idea. Cheers, Andrew Bromage

On Sun, 22 May 2005 ajb@spamcop.net wrote:
Quoting Ashley Yakeley
: 2. This one is more familiar for the English language and for the standard operators:
add :: Absolute -> Diff -> Absolute add a d = a + d subtract :: Absolute -> Diff -> Absolute subtract a d = a - d diff :: Absolute -> Absolute -> Diff diff a b = a - b
But even better would be if you could do both, and not distinguish between subtract and diff:
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.

In article
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.
They're actually for time: diffAbsoluteTime :: AbsoluteTime -> AbsoluteTime -> DiffTime diffUTCTime :: UTCTime -> UTCTime -> UTCDiffTime Ideally I'd make a two-parameter class, e.g. "class Diff diff abs | abs -> diff" which would have all three functions, but I'm sticking with Haskell 98 (plus FFI only) for portability. -- Ashley Yakeley, Seattle WA

On Mon, 23 May 2005, Ashley Yakeley wrote:
Henning Thielemann
wrote: I assume that these function are for computations like subtract :: DegreeCentigrade -> Kelvin -> DegreeCentigrade
sorry, I meant of course subtract :: Kelvin -> DegreeCentigrade -> DegreeCentigrade :-)

G'day all.
Quoting Henning Thielemann
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

Ashley Yakeley
Which of these argument orders is more intuitive to you?
Consistent with + and -. -- __("< Marcin Kowalczyk \__/ qrczak@knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/
participants (4)
-
ajb@spamcop.net
-
Ashley Yakeley
-
Henning Thielemann
-
Marcin 'Qrczak' Kowalczyk