[Haskell-cafe] [Haskell] ANNOUNCE: time-recurrence-0.1

Yitzchak Gale gale at sefer.org
Wed May 25 09:02:38 CEST 2011


I wrote:
>> It's not a good idea for a basic time
>> library to introduce possible crashes. At least you should
>> provide an alternative safe interface. Similarly for toEnum.

Chris Heller wrote:
> are you suggesting something like doing modulo arithmetic rather
> than calling error on undefined values?

Well, the standard "safe interface" would just wrap the return
type in Maybe, like fromGregorianValid does. Then you might
use it something like this:

maybe [] (map moment . take 5 . recurBy 10 [] . Daily) maybeStartDate

Using modulo arithmetic for toEnum would indeed make the function
safe, but I'm not sure that would give the results that users are
expecting.

For the start date of a recurrence, though, you are right that you
might be able to do better than just using Maybe. Suppose you
had a function that rounds an invalid Gregorian date forward to
the nearest valid date. Then a user that asks for a recurrence
starting with, say, Feb. 30 would get dates starting at the
beginning of March, which is probably what was intended.

Regards,
Yitz



More information about the Haskell-Cafe mailing list