Calendar Types

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Mon Feb 14 07:07:57 EST 2005


"Bayley, Alistair" <Alistair_Bayley at ldn.invesco.com> writes:

>> From: Ketil Malde [mailto:ketil+haskell at 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 at knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/


More information about the Libraries mailing list