1 % -----------------------------------------------------------------------------
2 % $Id: PrelCTypes.lhs,v 1.3 2001/02/22 16:48:24 qrczak Exp $
4 % (c) The FFI task force, 2000
7 A mapping of C types to corresponding Haskell types. A cool hack...
9 #include "cbits/CTypes.h"
13 ( -- Integral types, instances of: Eq, Ord, Num, Read, Show, Enum,
14 -- Typeable, Storable, Bounded, Real, Integral, Bits
15 CChar(..), CSChar(..), CUChar(..)
16 , CShort(..), CUShort(..), CInt(..), CUInt(..)
17 , CLong(..), CULong(..), CLLong(..), CULLong(..)
19 -- Floating types, instances of: Eq, Ord, Num, Read, Show, Enum,
20 -- Typeable, Storable, Real, Fractional, Floating, RealFrac, RealFloat
21 , CFloat(..), CDouble(..), CLDouble(..)
26 import PrelBase ( unsafeCoerce# )
27 import PrelBits ( Bits(..) )
28 import PrelInt ( Int8, Int16, Int32, Int64 )
29 import PrelWord ( Word8, Word16, Word32, Word64 )
33 INTEGRAL_TYPE(CChar,tyConCChar,"CChar",HTYPE_CHAR)
34 INTEGRAL_TYPE(CSChar,tyConCSChar,"CSChar",HTYPE_SIGNED_CHAR)
35 INTEGRAL_TYPE(CUChar,tyConCUChar,"CUChar",HTYPE_UNSIGNED_CHAR)
37 INTEGRAL_TYPE(CShort,tyConCShort,"CShort",HTYPE_SHORT)
38 INTEGRAL_TYPE(CUShort,tyConCUShort,"CUShort",HTYPE_UNSIGNED_SHORT)
40 INTEGRAL_TYPE(CInt,tyConCInt,"CInt",HTYPE_INT)
41 INTEGRAL_TYPE(CUInt,tyConCUInt,"CUInt",HTYPE_UNSIGNED_INT)
43 INTEGRAL_TYPE(CLong,tyConCLong,"CLong",HTYPE_LONG)
44 INTEGRAL_TYPE(CULong,tyConCULong,"CULong",HTYPE_UNSIGNED_LONG)
46 INTEGRAL_TYPE(CLLong,tyConCLLong,"CLLong",HTYPE_LONG_LONG)
47 INTEGRAL_TYPE(CULLong,tyConCULLong,"CULLong",HTYPE_UNSIGNED_LONG_LONG)
50 "fromIntegral/a->CChar" fromIntegral = \x -> CChar (fromIntegral x)
51 "fromIntegral/a->CSChar" fromIntegral = \x -> CSChar (fromIntegral x)
52 "fromIntegral/a->CUChar" fromIntegral = \x -> CUChar (fromIntegral x)
53 "fromIntegral/a->CShort" fromIntegral = \x -> CShort (fromIntegral x)
54 "fromIntegral/a->CUShort" fromIntegral = \x -> CUShort (fromIntegral x)
55 "fromIntegral/a->CInt" fromIntegral = \x -> CInt (fromIntegral x)
56 "fromIntegral/a->CUInt" fromIntegral = \x -> CUInt (fromIntegral x)
57 "fromIntegral/a->CLong" fromIntegral = \x -> CLong (fromIntegral x)
58 "fromIntegral/a->CULong" fromIntegral = \x -> CULong (fromIntegral x)
59 "fromIntegral/a->CLLong" fromIntegral = \x -> CLLong (fromIntegral x)
60 "fromIntegral/a->CULLong" fromIntegral = \x -> CULLong (fromIntegral x)
62 "fromIntegral/CChar->a" fromIntegral = \(CChar x) -> fromIntegral x
63 "fromIntegral/CSChar->a" fromIntegral = \(CSChar x) -> fromIntegral x
64 "fromIntegral/CUChar->a" fromIntegral = \(CUChar x) -> fromIntegral x
65 "fromIntegral/CShort->a" fromIntegral = \(CShort x) -> fromIntegral x
66 "fromIntegral/CUShort->a" fromIntegral = \(CUShort x) -> fromIntegral x
67 "fromIntegral/CInt->a" fromIntegral = \(CInt x) -> fromIntegral x
68 "fromIntegral/CUInt->a" fromIntegral = \(CUInt x) -> fromIntegral x
69 "fromIntegral/CLong->a" fromIntegral = \(CLong x) -> fromIntegral x
70 "fromIntegral/CULong->a" fromIntegral = \(CULong x) -> fromIntegral x
71 "fromIntegral/CLLong->a" fromIntegral = \(CLLong x) -> fromIntegral x
72 "fromIntegral/CULLong->a" fromIntegral = \(CULLong x) -> fromIntegral x
75 FLOATING_TYPE(CFloat,tyConCFloat,"CFloat",HTYPE_FLOAT)
76 FLOATING_TYPE(CDouble,tyConCDouble,"CDouble",HTYPE_DOUBLE)
77 -- HACK: Currently no long double in the FFI, so we simply re-use double
78 FLOATING_TYPE(CLDouble,tyConCLDouble,"CLDouble",HTYPE_DOUBLE)