
On Wednesday, March 27, 2013 11:30:24 AM, Henning Thielemann wrote:
Writing orphan instances is generally a bad idea. Instead you could put your roundTo function into a nice package and import it everywhere.
Yup! So let's put the Integral, etc. instances right in Foreign.C.Types. That way no one will make the mistake you're accusing me of.
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. CTime is a newtype of an integer type, and the quotient of two integers is an integer. Foreign.C.Types certainly doesn't have a problem dividing even stranger things, like graphemes by graphemes. I'm quite sure that the reason that CTime doesn't have an Integral instance is that technically the C spec allows time_t to be a float. However, since time_t is practically always an integer value, we should expose that by defining the Integral instance right in Foreign.C.Types. I looked through the header files for FreeBSD's platforms, and time_t is always an __int32 or __int64. Maybe Linux or NetBSD can provide an exception. Jeff