[Fwd: cvs commit: fptools/libraries/base/Foreign/C Types.hs fptools/libraries/base/System CPUTime.hsc Directory.hs Time.hsc fptools/libraries/base/System/Posix Types.hs fptools/libraries/base/include CTypes.h]
I've just commited a change to the fptools repository, proposing a minor change in the FFI spec, see below. Comments welcome. Cheers, S. -------- Original Message -------- Subject: cvs commit: fptools/libraries/base/Foreign/C Types.hs fptools/libraries/base/System CPUTime.hsc Directory.hs Time.hsc fptools/libraries/base/System/Posix Types.hs fptools/libraries/base/include CTypes.h Date: Sun, 13 Jun 2004 14:03:47 -0700 From: Sven Panne <panne@glass.cse.ogi.edu> To: cvs-libraries@haskell.org panne 2004/06/13 14:03:47 PDT Modified files: libraries/base/Foreign/C Types.hs libraries/base/System CPUTime.hsc Directory.hs Time.hsc libraries/base/System/Posix Types.hs libraries/base/include CTypes.h Log: Changes related to arithmetic types: * Renamed macros NUMERIC_FOO to ARITHMETIC_FOO to match C99-speak * ARITHMETIC_TYPEs now have a Real instance, otherwise they are quite useless. Note that this differs from the FFI spec, but the spec should very probably changed in this respect. * Some changes to fix the wrong assumption that CTime/CClock are integral types, C99 in fact guarantees only that they are arithmetic types. This has been accomplished by using realToInteger = round . realToFrac :: Real a => a -> Integer instead of fromIntegral for CTime/CClock. I'm not sure if we could do better, going via Double seems to be overkill, but I couldn't think of a better way. GHC could e.g. use RULES here. Improvements welcome. Revision Changes Path 1.22 +2 -2 fptools/libraries/base/Foreign/C/Types.hs 1.15 +5 -4 fptools/libraries/base/System/CPUTime.hsc 1.25 +2 -1 fptools/libraries/base/System/Directory.hs 1.26 +7 -4 fptools/libraries/base/System/Time.hsc 1.14 +3 -3 fptools/libraries/base/System/Posix/Types.hs 1.8 +12 -13 fptools/libraries/base/include/CTypes.h _______________________________________________ Cvs-libraries mailing list Cvs-libraries@haskell.org http://www.haskell.org/mailman/listinfo/cvs-libraries
I wrote:
I've just commited a change to the fptools repository, proposing a minor change in the FFI spec, see below. Comments welcome. [...]
My previous mail was a little bit terse, so I'd like to explain my proposal in more detail: A part of the FFI spec describes a mapping of some C types to Haskell types (CInt & friends), including the instances defined for them. The relevant C types are (in C99-speak) "integer types" (char, short int, ...), "floating types" (float, double, long double), and "arithmetic types" (= union of integer and floating types). The Haskell instances for the corresponding types should mirror what one can do with the C types. This is almost the case, but my point is that for the arithmetic types CTime and CClock (= clock_t/time_t), Real instances are missing in the spec. Having only Num available, one can convert an Integer (and other Integral types via fromIntegral) to such a type, but not the other way round, although this is perfectly possible in C. Having a Real instance available, too, one could do this, e.g. via: round . fromRational . toRational This would mirror being able to say in C: time_t t = ... int i = (int)t; In a nutshell: I propose to add Real instances to CTime and CClock. Additionally, the wording of the relevant part of the FFI spec should probably use the same terms as C99 (integer/floating/arithmetic types), define the instances for these kind of types, and say e.g. that CTime is an arithmetic type. This would make things a bit clearer and less redundant. Cheers, S.
participants (1)
-
Sven Panne