Time Libraries Rough Draft

Simon Marlow simonmar at microsoft.com
Thu Feb 10 07:33:29 EST 2005

On 10 February 2005 10:15, Ashley Yakeley wrote:

> In article
<3429668D0E777A499EE74A7952C382D103238B8A at EUR-MSG-01.europe.corp.microso
> ft.com>,
>  "Simon Marlow" <simonmar at microsoft.com> wrote:
>>> module System.Time.Clock ( ... ) where
>>>   -- | standard Julian count of Earth days
>>>   type JulianDay = Integer
>>>   newtype DiffTime = MkDiffTime Integer
>> Rather than exposing the constructor, I'd make it an abstract type
>> with an instance of Integral.  You probably want the Integral
>> instance anyway, so that you can use overloaded literals, and then
>> there's not much use for the constructor.
> Do you mean for DiffTime or for JulianDay?

Maybe JulianDay should be an Integral type too.  Of the three choices:

 (a) type synonym for Integer
 (b) non-abstract newtype
 (c) abstract newtype

(a) and (c) are both better than (b).  (c) is better than (a) in the
sense that you can use different instances for existing classes: eg. we
can have a specialised instance of Show for JulianDay, if we want.

So, I'd go for abstract newtypes consistently.


More information about the Libraries mailing list