1 {-# OPTIONS -fno-implicit-prelude #-}
2 -----------------------------------------------------------------------------
4 -- Module : Foreign.C.Types
5 -- Copyright : (c) The FFI task force 2001
6 -- License : BSD-style (see the file libraries/base/LICENSE)
8 -- Maintainer : ffi@haskell.org
9 -- Stability : provisional
10 -- Portability : portable
12 -- Mapping of C types to corresponding Haskell types. A cool hack...
14 -----------------------------------------------------------------------------
16 module Foreign.C.Types
17 ( -- Integral types, instances of: Eq, Ord, Num, Read, Show, Enum,
18 -- Typeable, Storable, Bounded, Real, Integral, Bits
20 , CShort, CUShort, CInt, CUInt
22 , CPtrdiff, CSize, CWchar, CSigAtomic
24 -- Numeric types, instances of: Eq, Ord, Num, Read, Show, Enum,
28 -- Floating types, instances of: Eq, Ord, Num, Read, Show, Enum,
29 -- Typeable, Storable, Real, Fractional, Floating, RealFrac,
31 , CFloat, CDouble, CLDouble
33 -- Instances of: Eq and Storable
34 , CFile, CFpos, CJmpBuf
39 ( CChar, CSChar, CUChar
40 , CShort, CUShort, CInt, CUInt
41 , CLong, CULong, CLLong, CULLong
42 , CPtrdiff, CSize, CWchar, CSigAtomic
44 , CFloat, CDouble, CLDouble
45 , CFile, CFpos, CJmpBuf
50 import Foreign.C.TypesISO
51 import Foreign.Storable
52 import Data.Bits ( Bits(..) )
53 import Data.Int ( Int8, Int16, Int32, Int64 )
54 import Data.Word ( Word8, Word16, Word32, Word64 )
57 #ifdef __GLASGOW_HASKELL__
73 INTEGRAL_TYPE(CChar,tyConCChar,"CChar",HTYPE_CHAR)
74 INTEGRAL_TYPE(CSChar,tyConCSChar,"CSChar",HTYPE_SIGNED_CHAR)
75 INTEGRAL_TYPE(CUChar,tyConCUChar,"CUChar",HTYPE_UNSIGNED_CHAR)
77 INTEGRAL_TYPE(CShort,tyConCShort,"CShort",HTYPE_SHORT)
78 INTEGRAL_TYPE(CUShort,tyConCUShort,"CUShort",HTYPE_UNSIGNED_SHORT)
80 INTEGRAL_TYPE(CInt,tyConCInt,"CInt",HTYPE_INT)
81 INTEGRAL_TYPE(CUInt,tyConCUInt,"CUInt",HTYPE_UNSIGNED_INT)
83 INTEGRAL_TYPE(CLong,tyConCLong,"CLong",HTYPE_LONG)
84 INTEGRAL_TYPE(CULong,tyConCULong,"CULong",HTYPE_UNSIGNED_LONG)
86 INTEGRAL_TYPE(CLLong,tyConCLLong,"CLLong",HTYPE_LONG_LONG)
87 INTEGRAL_TYPE(CULLong,tyConCULLong,"CULLong",HTYPE_UNSIGNED_LONG_LONG)
90 "fromIntegral/a->CChar" fromIntegral = \x -> CChar (fromIntegral x)
91 "fromIntegral/a->CSChar" fromIntegral = \x -> CSChar (fromIntegral x)
92 "fromIntegral/a->CUChar" fromIntegral = \x -> CUChar (fromIntegral x)
93 "fromIntegral/a->CShort" fromIntegral = \x -> CShort (fromIntegral x)
94 "fromIntegral/a->CUShort" fromIntegral = \x -> CUShort (fromIntegral x)
95 "fromIntegral/a->CInt" fromIntegral = \x -> CInt (fromIntegral x)
96 "fromIntegral/a->CUInt" fromIntegral = \x -> CUInt (fromIntegral x)
97 "fromIntegral/a->CLong" fromIntegral = \x -> CLong (fromIntegral x)
98 "fromIntegral/a->CULong" fromIntegral = \x -> CULong (fromIntegral x)
99 "fromIntegral/a->CLLong" fromIntegral = \x -> CLLong (fromIntegral x)
100 "fromIntegral/a->CULLong" fromIntegral = \x -> CULLong (fromIntegral x)
102 "fromIntegral/CChar->a" fromIntegral = \(CChar x) -> fromIntegral x
103 "fromIntegral/CSChar->a" fromIntegral = \(CSChar x) -> fromIntegral x
104 "fromIntegral/CUChar->a" fromIntegral = \(CUChar x) -> fromIntegral x
105 "fromIntegral/CShort->a" fromIntegral = \(CShort x) -> fromIntegral x
106 "fromIntegral/CUShort->a" fromIntegral = \(CUShort x) -> fromIntegral x
107 "fromIntegral/CInt->a" fromIntegral = \(CInt x) -> fromIntegral x
108 "fromIntegral/CUInt->a" fromIntegral = \(CUInt x) -> fromIntegral x
109 "fromIntegral/CLong->a" fromIntegral = \(CLong x) -> fromIntegral x
110 "fromIntegral/CULong->a" fromIntegral = \(CULong x) -> fromIntegral x
111 "fromIntegral/CLLong->a" fromIntegral = \(CLLong x) -> fromIntegral x
112 "fromIntegral/CULLong->a" fromIntegral = \(CULLong x) -> fromIntegral x
115 FLOATING_TYPE(CFloat,tyConCFloat,"CFloat",HTYPE_FLOAT)
116 FLOATING_TYPE(CDouble,tyConCDouble,"CDouble",HTYPE_DOUBLE)
117 -- HACK: Currently no long double in the FFI, so we simply re-use double
118 FLOATING_TYPE(CLDouble,tyConCLDouble,"CLDouble",HTYPE_DOUBLE)