Time

Wed Jan 26 02:46:32 EST 2005

Ashley Yakeley <ashley at semantic.org> writes:

Thanks for picking up the thread!

>>    data T = Y Int | M Int T | Wy Int T | Wm Int T | Dy Int T | Dm Int T
>>        | Dw Int T | Hr Int T | Min Int T
>>        deriving (Eq,Show)

>> The idea is that time can be a year, or a month in some year, or a
>> week in some year (yes, I know it's ambigous), week in month (in
>> year), day in year, day in month in year, and so on.

> This seems to be equivalent to DateTime::Incomplete in Perl's DateTime.

(That's a pretty odd name for it.)

> If so I'd consider representing it more like this:
>
>  data T = MkT
>    y :: Maybe Int
>    m :: Maybe Int
>    wy :: Maybe Int
>    wm :: Maybe Int
>    ...

Yes, that's a possibility.  And of course, it is possible to leave
fields undefined in a record as well.  I'd like there to be a good way
of using the type system to ensure that the dates are "sensible"
(e.g. you don't specify both wm and wy etc), but I'm not sure how.

Note that MkT is not quite similar, in my suggestion, you would need
at least to specify the year to have the precise date.  So if I want
to specify my birthday, the natural representation would be as a
function:
\(Y y) -> (Dm 19 (M 5 (Y y)))

Perhaps another approach, making better use of the type system, would
be to say something like:

data Year = Y Int
data Month = M Int Year
data Week  = Wy Int Year | Wm Int Month
data Day   = Dy Int Year | Dm Int Month | Dw Int Week
:
data Second = S Int Hour | S Int Day -- of year, for UTC

I guess I'm just rambling, and should sit down and think things
through a bit.  Or at least post to -cafe :-)

-kzm
--
If I haven't seen further, it is by standing in the footprints of giants