
From: Ketil Malde [mailto:ketil+haskell@ii.uib.no]
You also need to specify, or let the user specify, the order of arithmetic. I.e. adding a day and then a second is different from doing it the other way around.
Duration arithmetic is not commutative? Can you give some examples please, because I'm not able to imagine any. ----------------------------------------- ***************************************************************** Confidentiality Note: The information contained in this message, and any attachments, may contain confidential and/or privileged material. It is intended solely for the person(s) or entity to which it is addressed. Any review, retransmission, dissemination, or taking of any action in reliance upon this information by persons or entities other than the intended recipient(s) is prohibited. If you received this in error, please contact the sender and delete the material from any computer. *****************************************************************

"Bayley, Alistair"
From: Ketil Malde [mailto:ketil+haskell@ii.uib.no]
You also need to specify, or let the user specify, the order of arithmetic. I.e. adding a day and then a second is different from doing it the other way around.
Duration arithmetic is not commutative? Can you give some examples please, because I'm not able to imagine any.
This depends on the intended semantics. What is "March 31" + 1 month or "May 31" - 1 month? If this is "April 30", which I find the most intuitive solution, then "March 30" + 1 month + 1 day = "May 1" "March 30" + 1 day + 1 month = "April 30" This means that it's meaningless to add a single interval consisting of several parts expressed in different units. It is meaningful however to 1. add an interval expressed in a single unit, 2. set multiple fields simultaneously to given values. My language Kogut provides only the latter. Setting a field to a value out of range causes wrapping of that field and the appropriate change to larger units. But if a change causes a smaller unit to become out of range without being changed explicitly, then the smaller unit is clamped to its new maximum value instead of wrapping. Without leap seconds this can only happen with the day when larger units change, with leap seconds this also applies to the number of seconds. -- __("< Marcin Kowalczyk \__/ qrczak@knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/

Bayley, Alistair wrote:
You also need to specify, or let the user specify, the order of arithmetic. I.e. adding a day and then a second is different from doing it the other way around.
Only when leap seconds are involved. A month and a day would be a better example.
Duration arithmetic is not commutative? Can you give some examples please, because I'm not able to imagine any.
April 30th + 1 month + 1 day = May 30th + 1 day = May 31st
April 30th + 1 day + 1 month = May 1st + 1 month = June 1st
--
Glynn Clements

Glynn Clements wrote:
Bayley, Alistair wrote:
You also need to specify, or let the user specify, the order of arithmetic. I.e. adding a day and then a second is different from doing it the other way around.
Only when leap seconds are involved. A month and a day would be a better example.
Duration arithmetic is not commutative? Can you give some examples please, because I'm not able to imagine any.
April 30th + 1 month + 1 day = May 30th + 1 day = May 31st April 30th + 1 day + 1 month = May 1st + 1 month = June 1st
What reason is there to say May 30 + 1 day == May 31st? May 30 + 1 day = June first. So the answer is the same either way, as long as your result for May 30 + 1 day is correct.

Seth Kurtzberg
April 30th + 1 month + 1 day = May 30th + 1 day = May 31st April 30th + 1 day + 1 month = May 1st + 1 month = June 1st
What reason is there to say May 30 + 1 day == May 31st?
Well, because May 31st is the next day after May 30th. -- __("< Marcin Kowalczyk \__/ qrczak@knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/

Seth Kurtzberg wrote:
Glynn Clements wrote:
Bayley, Alistair wrote:
You also need to specify, or let the user specify, the order of arithmetic. I.e. adding a day and then a second is different from doing it the other way around.
Only when leap seconds are involved. A month and a day would be a better example.
Duration arithmetic is not commutative? Can you give some examples please, because I'm not able to imagine any.
April 30th + 1 month + 1 day = May 30th + 1 day = May 31st April 30th + 1 day + 1 month = May 1st + 1 month = June 1st
What reason is there to say May 30 + 1 day == May 31st? May 30 + 1 day = June first. So the answer is the same either way, as long as your result for May 30 + 1 day is correct.
oops, got my months mixed up, sorry about that. The fallacy here is that month is a unit. Your example proves that it is not. Whether a day is a unit might be controversial (as noted in the thread, it depends on which assumptions you start from) but a month is definitely never a unit.
!DSPAM:421117b0210897468917868!
------------------------------------------------------------------------
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
!DSPAM:421117b0210897468917868!

Seth Kurtzberg
The fallacy here is that month is a unit. Your example proves that it is not.
Okay - but this is going to be a weird calendar, if it doesn't handle months. (Or minutes, which have a similar -- although less frequent -- problem with seconds) (Which is one reason I argue that calendar units should be an algebraic data type, and not a record.) -kzm -- If I haven't seen further, it is by standing in the footprints of giants
participants (5)
-
Bayley, Alistair
-
Glynn Clements
-
Ketil Malde
-
Marcin 'Qrczak' Kowalczyk
-
Seth Kurtzberg