Concerning Time.TimeDiff

Jon Fairbairn Jon.Fairbairn@cl.cam.ac.uk
Wed, 18 Jun 2003 16:08:05 +0100


On 2003-06-18 at 15:19+0200 ketil@ii.uib.no (Ketil Z. Malde)  wrote:
> "Simon Marlow" <simonmar@microsoft.com> writes:
> >   - calendarTimeToClockTime now returns a Maybe.
> 
> Okay, this is perhaps more "functional", but is it really what I want?
> Wouldn't an illegal calendarTime often be a bug in the code, and if
> so, isn't it better to just crash?  I don't much care for wrapping
> things in Maybe, could we have an 'isCalendarTimeValid' instead (in
> order to verify values that aren't static)?
> 
> I.e., isn't this 
> 
>         foo ct | isCalendarTimeValid ct -> ...calendarTimeToClockTime ct...
>                | otherwise -> error ...
> 
> as useful as this
>       
>         foo ct = case calendarTimeToClockTime ct of
>                 Just t -> ....
>                 Nothing -> error ...
> 
> ?  And of course cleaner in the cases where you *don't* need to check?

If you want to write in that style, there's nothing to stop
you writing wrappers to do it. You can write
crashableCalendarTimeToClockTime (which would look much like
foo above. I think that standard things in Haskell should
not use crashing as a solution if it can possible be avoided.

Best would be if the type system could enforce validity of
calendar times and restrict the possibility of errors to
conversion from strings and suchlike. Given the peculiar
constraints on calender times this is too much to ask,
however.

  Jón


-- 
Jón Fairbairn                                 Jon.Fairbairn@cl.cam.ac.uk
31 Chalmers Road                                         jf@cl.cam.ac.uk
Cambridge CB1 3SZ            +44 1223 570179 (after 14:00 only, please!)