RE: Difference Argument Order

On 23 May 2005 01:43, Ashley Yakeley wrote:
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
If you have the second form, then it would make sense to call them "plus", and "minus", because they correspond to the infix operators. BTW, the Prelude already has "subtract" with the opposite argument order to infix "-", but this was provided mainly because (-1) means (negate 1) rather than ((-) 1). For the "diff" functions, the first form seems more natural to me, because the arguments increase left-to-right, ie. in (diff T1 T2) T2 is later than T1. Cheers, Simon
participants (1)
-
Simon Marlow