1 {-# OPTIONS -fno-implicit-prelude #-}
2 -----------------------------------------------------------------------------
4 -- Module : Foreign.C.TypesISO
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 -- A mapping of C types defined by the ISO C standard to corresponding Haskell
13 -- types. Like CTypes, this is a cool hack...
15 -----------------------------------------------------------------------------
17 module Foreign.C.TypesISO
18 ( -- Integral types, instances of: Eq, Ord, Num, Read, Show, Enum,
19 -- Typeable, Storable, Bounded, Real, Integral, Bits
20 CPtrdiff(..), CSize(..), CWchar(..), CSigAtomic(..)
22 -- Numeric types, instances of: Eq, Ord, Num, Read, Show, Enum,
24 , CClock(..), CTime(..)
26 -- Instances of: Eq and Storable
27 , CFile, CFpos, CJmpBuf
30 import Data.Bits ( Bits(..) )
34 import Foreign.Storable
36 #ifdef __GLASGOW_HASKELL__
51 INTEGRAL_TYPE(CPtrdiff,tyConCPtrdiff,"CPtrdiff",HTYPE_PTRDIFF_T)
52 INTEGRAL_TYPE(CSize,tyConCSize,"CSize",HTYPE_SIZE_T)
53 INTEGRAL_TYPE(CWchar,tyConCWchar,"CWchar",HTYPE_WCHAR_T)
54 INTEGRAL_TYPE(CSigAtomic,tyConCSigAtomic,"CSigAtomic",HTYPE_SIG_ATOMIC_T)
57 "fromIntegral/a->CPtrdiff" fromIntegral = \x -> CPtrdiff (fromIntegral x)
58 "fromIntegral/a->CSize" fromIntegral = \x -> CSize (fromIntegral x)
59 "fromIntegral/a->CWchar" fromIntegral = \x -> CWchar (fromIntegral x)
60 "fromIntegral/a->CSigAtomic" fromIntegral = \x -> CSigAtomic (fromIntegral x)
62 "fromIntegral/CPtrdiff->a" fromIntegral = \(CPtrdiff x) -> fromIntegral x
63 "fromIntegral/CSize->a" fromIntegral = \(CSize x) -> fromIntegral x
64 "fromIntegral/CWchar->a" fromIntegral = \(CWchar x) -> fromIntegral x
65 "fromIntegral/CSigAtomic->a" fromIntegral = \(CSigAtomic x) -> fromIntegral x
68 INTEGRAL_TYPE(CClock,tyConCClock,"CClock",HTYPE_CLOCK_T)
69 INTEGRAL_TYPE(CTime,tyConCTime,"CTime",HTYPE_TIME_T)
71 -- FIXME: Implement and provide instances for Eq and Storable
74 data CJmpBuf = CJmpBuf
76 -- C99 types which are still missing include:
77 -- intptr_t, uintptr_t, intmax_t, uintmax_t, wint_t, wctrans_t, wctype_t