The numeric c types are (effectively) integral, too.

Jeff Shaw shawjef3 at
Wed Mar 27 17:55:17 CET 2013

On 3/27/2013 12:16 PM, Henning Thielemann wrote:
> On Wed, 27 Mar 2013, Jeff Shaw wrote:
>> On Wednesday, March 27, 2013 11:30:24 AM, Henning Thielemann wrote:
>>> I don't think that an Integral instance is the right way
>>> to go, since it would imply the signature:
>>> div :: CTime -> CTime -> CTime
>>> and the quotient of two time values is not a time.
>> That is irrelevant.
> It is highly relevant and certainly a major difference between Haskell 
> and C. A time can be represented with any unit and with either integer 
> or floating or fixed-point numbers. Actually, the integer can always 
> be read as fixed-point number, since the unit is somehow arbitrary. 
> The quotient of two time values is not a time value but a scalar value 
> and it is good if Haskell alerts you when you mix them up.
The functionality you want is located in Data.Time.Clock. 
Foreign.C.Types is for working with C values, which do permit integer 
division on time_t when it happens to be an integer, which as far as 
Haskell is concerned, is always.

Your argument can also be used to say that C values with the unit 
"grapheme" shouldn't be allowed division, either. However, they are. Do 
you think we should remove the Integral instance for CChar? What about 
the Bounded and Bits instances? Data.Char.Char only has Bounded.

Furthermore, CTime is an instance of Num, which means that you can do 
multiplication on CTime values. Do you think we should remove that? 
After all, Time * Time is Time ^2, not Time.


More information about the Libraries mailing list