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/core/LICENSE)
8 -- Maintainer : ffi@haskell.org
9 -- Stability : provisional
10 -- Portability : portable
12 -- $Id: Types.hs,v 1.2 2001/07/03 11:37:50 simonmar Exp $
14 -- Mapping of C types to corresponding Haskell types. A cool hack...
16 -----------------------------------------------------------------------------
18 module Foreign.C.Types
19 ( -- Integral types, instances of: Eq, Ord, Num, Read, Show, Enum,
20 -- Typeable, Storable, Bounded, Real, Integral, Bits
21 CChar(..), CSChar(..), CUChar(..)
22 , CShort(..), CUShort(..), CInt(..), CUInt(..)
23 , CLong(..), CULong(..), CLLong(..), CULLong(..)
25 -- Floating types, instances of: Eq, Ord, Num, Read, Show, Enum,
26 -- Typeable, Storable, Real, Fractional, Floating, RealFrac, RealFloat
27 , CFloat(..), CDouble(..), CLDouble(..)
30 import Data.Bits ( Bits(..) )
31 import Data.Int ( Int8, Int16, Int32, Int64 )
32 import Data.Word ( Word8, Word16, Word32, Word64 )
35 #ifdef __GLASGOW_HASKELL__
47 INTEGRAL_TYPE(CChar,tyConCChar,"CChar",HTYPE_CHAR)
48 INTEGRAL_TYPE(CSChar,tyConCSChar,"CSChar",HTYPE_SIGNED_CHAR)
49 INTEGRAL_TYPE(CUChar,tyConCUChar,"CUChar",HTYPE_UNSIGNED_CHAR)
51 INTEGRAL_TYPE(CShort,tyConCShort,"CShort",HTYPE_SHORT)
52 INTEGRAL_TYPE(CUShort,tyConCUShort,"CUShort",HTYPE_UNSIGNED_SHORT)
54 INTEGRAL_TYPE(CInt,tyConCInt,"CInt",HTYPE_INT)
55 INTEGRAL_TYPE(CUInt,tyConCUInt,"CUInt",HTYPE_UNSIGNED_INT)
57 INTEGRAL_TYPE(CLong,tyConCLong,"CLong",HTYPE_LONG)
58 INTEGRAL_TYPE(CULong,tyConCULong,"CULong",HTYPE_UNSIGNED_LONG)
60 INTEGRAL_TYPE(CLLong,tyConCLLong,"CLLong",HTYPE_LONG_LONG)
61 INTEGRAL_TYPE(CULLong,tyConCULLong,"CULLong",HTYPE_UNSIGNED_LONG_LONG)
64 "fromIntegral/a->CChar" fromIntegral = \x -> CChar (fromIntegral x)
65 "fromIntegral/a->CSChar" fromIntegral = \x -> CSChar (fromIntegral x)
66 "fromIntegral/a->CUChar" fromIntegral = \x -> CUChar (fromIntegral x)
67 "fromIntegral/a->CShort" fromIntegral = \x -> CShort (fromIntegral x)
68 "fromIntegral/a->CUShort" fromIntegral = \x -> CUShort (fromIntegral x)
69 "fromIntegral/a->CInt" fromIntegral = \x -> CInt (fromIntegral x)
70 "fromIntegral/a->CUInt" fromIntegral = \x -> CUInt (fromIntegral x)
71 "fromIntegral/a->CLong" fromIntegral = \x -> CLong (fromIntegral x)
72 "fromIntegral/a->CULong" fromIntegral = \x -> CULong (fromIntegral x)
73 "fromIntegral/a->CLLong" fromIntegral = \x -> CLLong (fromIntegral x)
74 "fromIntegral/a->CULLong" fromIntegral = \x -> CULLong (fromIntegral x)
76 "fromIntegral/CChar->a" fromIntegral = \(CChar x) -> fromIntegral x
77 "fromIntegral/CSChar->a" fromIntegral = \(CSChar x) -> fromIntegral x
78 "fromIntegral/CUChar->a" fromIntegral = \(CUChar x) -> fromIntegral x
79 "fromIntegral/CShort->a" fromIntegral = \(CShort x) -> fromIntegral x
80 "fromIntegral/CUShort->a" fromIntegral = \(CUShort x) -> fromIntegral x
81 "fromIntegral/CInt->a" fromIntegral = \(CInt x) -> fromIntegral x
82 "fromIntegral/CUInt->a" fromIntegral = \(CUInt x) -> fromIntegral x
83 "fromIntegral/CLong->a" fromIntegral = \(CLong x) -> fromIntegral x
84 "fromIntegral/CULong->a" fromIntegral = \(CULong x) -> fromIntegral x
85 "fromIntegral/CLLong->a" fromIntegral = \(CLLong x) -> fromIntegral x
86 "fromIntegral/CULLong->a" fromIntegral = \(CULLong x) -> fromIntegral x
89 FLOATING_TYPE(CFloat,tyConCFloat,"CFloat",HTYPE_FLOAT)
90 FLOATING_TYPE(CDouble,tyConCDouble,"CDouble",HTYPE_DOUBLE)
91 -- HACK: Currently no long double in the FFI, so we simply re-use double
92 FLOATING_TYPE(CLDouble,tyConCLDouble,"CLDouble",HTYPE_DOUBLE)
96 INSTANCE_TYPEABLE0(CChar,cCharTc,"CChar")
97 INSTANCE_TYPEABLE0(CSChar,cSCharTc,"CSChar")
98 INSTANCE_TYPEABLE0(CUChar,cUCharTc,"CUChar")
100 INSTANCE_TYPEABLE0(CShort,cShortTc,"CShort")
101 INSTANCE_TYPEABLE0(CUShort,cUShortTc,"CUShort")
103 INSTANCE_TYPEABLE0(CInt,cIntTc,"CInt")
104 INSTANCE_TYPEABLE0(CUInt,cUIntTc,"CUInt")
106 INSTANCE_TYPEABLE0(CLong,cLongTc,"CLong")
107 INSTANCE_TYPEABLE0(CULong,cULongTc,"CULong")
109 INSTANCE_TYPEABLE0(CLLong,cLLongTc,"CLLong")
110 INSTANCE_TYPEABLE0(CULLong,cULLongTc,"CULLong")
112 INSTANCE_TYPEABLE0(CFloat,cFloatTc,"CFloat")
113 INSTANCE_TYPEABLE0(CDouble,cDoubleTc,"CDouble")
114 INSTANCE_TYPEABLE0(CLDouble,cLDoubleTc,"CLDouble")