Copyright | (c) The FFI task force 2001 |
---|---|
License | BSD-style (see the file libraries/base/LICENSE) |
Maintainer | ffi@haskell.org |
Stability | provisional |
Portability | portable |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
Mapping of C types to corresponding Haskell types.
Synopsis
- newtype CChar = CChar Int8
- newtype CSChar = CSChar Int8
- newtype CUChar = CUChar Word8
- newtype CShort = CShort Int16
- newtype CUShort = CUShort Word16
- newtype CInt = CInt Int32
- newtype CUInt = CUInt Word32
- newtype CLong = CLong Int64
- newtype CULong = CULong Word64
- newtype CPtrdiff = CPtrdiff Int64
- newtype CSize = CSize Word64
- newtype CWchar = CWchar Int32
- newtype CSigAtomic = CSigAtomic Int32
- newtype CLLong = CLLong Int64
- newtype CULLong = CULLong Word64
- newtype CBool = CBool Word8
- newtype CIntPtr = CIntPtr Int64
- newtype CUIntPtr = CUIntPtr Word64
- newtype CIntMax = CIntMax Int64
- newtype CUIntMax = CUIntMax Word64
- newtype CClock = CClock Word64
- newtype CTime = CTime Int64
- newtype CUSeconds = CUSeconds Word32
- newtype CSUSeconds = CSUSeconds Int32
- newtype CFloat = CFloat Float
- newtype CDouble = CDouble Double
- data CFile
- data CFpos
- data CJmpBuf
Representations of C types
These types are needed to accurately represent C function prototypes,
in order to access C library interfaces in Haskell. The Haskell system
is not required to represent those types exactly as C does, but the
following guarantees are provided concerning a Haskell type CT
representing a C type t
:
- If a C function prototype has
t
as an argument or result type, the use ofCT
in the corresponding position in a foreign declaration permits the Haskell program to access the full range of values encoded by the C type; and conversely, any Haskell value forCT
has a valid representation in C.
will yield the same value assizeOf
(undefined
:: CT)sizeof (t)
in C.
matches the alignment constraint enforced by the C implementation foralignment
(undefined
:: CT)t
.- The members
peek
andpoke
of theStorable
class map all values ofCT
to the corresponding value oft
and vice versa. - When an instance of
Bounded
is defined forCT
, the values ofminBound
andmaxBound
coincide witht_MIN
andt_MAX
in C. - When an instance of
Eq
orOrd
is defined forCT
, the predicates defined by the type class implement the same relation as the corresponding predicate in C ont
. - When an instance of
Num
,Read
,Integral
,Fractional
,Floating
,RealFrac
, orRealFloat
is defined forCT
, the arithmetic operations defined by the type class implement the same function as the corresponding arithmetic operations (if available) in C ont
. - When an instance of
Bits
is defined forCT
, the bitwise operation defined by the type class implement the same function as the corresponding bitwise operation in C ont
.
Platform differences
This module contains platform specific information about types. __/As such the types presented on this page reflect the platform on which the documentation was generated and may not coincide with the types on your platform./__
Integral types
These types are represented as newtype
s of
types in Data.Int and Data.Word, and are instances of
Eq
, Ord
, Num
, Read
,
Show
, Enum
, Typeable
, Storable
,
Bounded
, Real
, Integral
and
Bits
.
Haskell type representing the C char
type.
Instances
Bounded CChar # | |
Enum CChar # | |
Eq CChar # | |
Integral CChar # | |
Num CChar # | |
Ord CChar # | |
Defined in Foreign.C.Types | |
Read CChar # | |
Real CChar # | |
Defined in Foreign.C.Types toRational :: CChar -> Rational # | |
Show CChar # | |
FiniteBits CChar # | |
Defined in Foreign.C.Types finiteBitSize :: CChar -> Int # countLeadingZeros :: CChar -> Int # countTrailingZeros :: CChar -> Int # | |
Bits CChar # | |
Defined in Foreign.C.Types (.&.) :: CChar -> CChar -> CChar # (.|.) :: CChar -> CChar -> CChar # xor :: CChar -> CChar -> CChar # complement :: CChar -> CChar # shift :: CChar -> Int -> CChar # rotate :: CChar -> Int -> CChar # setBit :: CChar -> Int -> CChar # clearBit :: CChar -> Int -> CChar # complementBit :: CChar -> Int -> CChar # testBit :: CChar -> Int -> Bool # bitSizeMaybe :: CChar -> Maybe Int # shiftL :: CChar -> Int -> CChar # unsafeShiftL :: CChar -> Int -> CChar # shiftR :: CChar -> Int -> CChar # unsafeShiftR :: CChar -> Int -> CChar # rotateL :: CChar -> Int -> CChar # | |
Storable CChar # | |
Haskell type representing the C signed char
type.
Instances
Haskell type representing the C unsigned char
type.
Instances
Haskell type representing the C short
type.
Instances
Haskell type representing the C unsigned short
type.
Instances
Haskell type representing the C int
type.
Instances
Bounded CInt # | |
Enum CInt # | |
Eq CInt # | |
Integral CInt # | |
Num CInt # | |
Ord CInt # | |
Read CInt # | |
Real CInt # | |
Defined in Foreign.C.Types toRational :: CInt -> Rational # | |
Show CInt # | |
FiniteBits CInt # | |
Defined in Foreign.C.Types | |
Bits CInt # | |
Defined in Foreign.C.Types (.&.) :: CInt -> CInt -> CInt # (.|.) :: CInt -> CInt -> CInt # complement :: CInt -> CInt # shift :: CInt -> Int -> CInt # rotate :: CInt -> Int -> CInt # setBit :: CInt -> Int -> CInt # clearBit :: CInt -> Int -> CInt # complementBit :: CInt -> Int -> CInt # testBit :: CInt -> Int -> Bool # bitSizeMaybe :: CInt -> Maybe Int # shiftL :: CInt -> Int -> CInt # unsafeShiftL :: CInt -> Int -> CInt # shiftR :: CInt -> Int -> CInt # unsafeShiftR :: CInt -> Int -> CInt # rotateL :: CInt -> Int -> CInt # | |
Storable CInt # | |
Defined in Foreign.C.Types |
Haskell type representing the C unsigned int
type.
Instances
Bounded CUInt # | |
Enum CUInt # | |
Eq CUInt # | |
Integral CUInt # | |
Num CUInt # | |
Ord CUInt # | |
Defined in Foreign.C.Types | |
Read CUInt # | |
Real CUInt # | |
Defined in Foreign.C.Types toRational :: CUInt -> Rational # | |
Show CUInt # | |
FiniteBits CUInt # | |
Defined in Foreign.C.Types finiteBitSize :: CUInt -> Int # countLeadingZeros :: CUInt -> Int # countTrailingZeros :: CUInt -> Int # | |
Bits CUInt # | |
Defined in Foreign.C.Types (.&.) :: CUInt -> CUInt -> CUInt # (.|.) :: CUInt -> CUInt -> CUInt # xor :: CUInt -> CUInt -> CUInt # complement :: CUInt -> CUInt # shift :: CUInt -> Int -> CUInt # rotate :: CUInt -> Int -> CUInt # setBit :: CUInt -> Int -> CUInt # clearBit :: CUInt -> Int -> CUInt # complementBit :: CUInt -> Int -> CUInt # testBit :: CUInt -> Int -> Bool # bitSizeMaybe :: CUInt -> Maybe Int # shiftL :: CUInt -> Int -> CUInt # unsafeShiftL :: CUInt -> Int -> CUInt # shiftR :: CUInt -> Int -> CUInt # unsafeShiftR :: CUInt -> Int -> CUInt # rotateL :: CUInt -> Int -> CUInt # | |
Storable CUInt # | |
Haskell type representing the C long
type.
Instances
Bounded CLong # | |
Enum CLong # | |
Eq CLong # | |
Integral CLong # | |
Num CLong # | |
Ord CLong # | |
Defined in Foreign.C.Types | |
Read CLong # | |
Real CLong # | |
Defined in Foreign.C.Types toRational :: CLong -> Rational # | |
Show CLong # | |
FiniteBits CLong # | |
Defined in Foreign.C.Types finiteBitSize :: CLong -> Int # countLeadingZeros :: CLong -> Int # countTrailingZeros :: CLong -> Int # | |
Bits CLong # | |
Defined in Foreign.C.Types (.&.) :: CLong -> CLong -> CLong # (.|.) :: CLong -> CLong -> CLong # xor :: CLong -> CLong -> CLong # complement :: CLong -> CLong # shift :: CLong -> Int -> CLong # rotate :: CLong -> Int -> CLong # setBit :: CLong -> Int -> CLong # clearBit :: CLong -> Int -> CLong # complementBit :: CLong -> Int -> CLong # testBit :: CLong -> Int -> Bool # bitSizeMaybe :: CLong -> Maybe Int # shiftL :: CLong -> Int -> CLong # unsafeShiftL :: CLong -> Int -> CLong # shiftR :: CLong -> Int -> CLong # unsafeShiftR :: CLong -> Int -> CLong # rotateL :: CLong -> Int -> CLong # | |
Storable CLong # | |
Haskell type representing the C unsigned long
type.
Instances
Haskell type representing the C ptrdiff_t
type.
Instances
Haskell type representing the C size_t
type.
Instances
Bounded CSize # | |
Enum CSize # | |
Eq CSize # | |
Integral CSize # | |
Num CSize # | |
Ord CSize # | |
Defined in Foreign.C.Types | |
Read CSize # | |
Real CSize # | |
Defined in Foreign.C.Types toRational :: CSize -> Rational # | |
Show CSize # | |
FiniteBits CSize # | |
Defined in Foreign.C.Types finiteBitSize :: CSize -> Int # countLeadingZeros :: CSize -> Int # countTrailingZeros :: CSize -> Int # | |
Bits CSize # | |
Defined in Foreign.C.Types (.&.) :: CSize -> CSize -> CSize # (.|.) :: CSize -> CSize -> CSize # xor :: CSize -> CSize -> CSize # complement :: CSize -> CSize # shift :: CSize -> Int -> CSize # rotate :: CSize -> Int -> CSize # setBit :: CSize -> Int -> CSize # clearBit :: CSize -> Int -> CSize # complementBit :: CSize -> Int -> CSize # testBit :: CSize -> Int -> Bool # bitSizeMaybe :: CSize -> Maybe Int # shiftL :: CSize -> Int -> CSize # unsafeShiftL :: CSize -> Int -> CSize # shiftR :: CSize -> Int -> CSize # unsafeShiftR :: CSize -> Int -> CSize # rotateL :: CSize -> Int -> CSize # | |
Storable CSize # | |
Haskell type representing the C wchar_t
type.
Instances
newtype CSigAtomic #
Haskell type representing the C sig_atomic_t
type.
Instances
Haskell type representing the C long long
type.
Instances
Haskell type representing the C unsigned long long
type.
Instances
Haskell type representing the C bool
type.
Since: base-4.10.0.0
Instances
Bounded CBool # | |
Enum CBool # | |
Eq CBool # | |
Integral CBool # | |
Num CBool # | |
Ord CBool # | |
Defined in Foreign.C.Types | |
Read CBool # | |
Real CBool # | |
Defined in Foreign.C.Types toRational :: CBool -> Rational # | |
Show CBool # | |
FiniteBits CBool # | |
Defined in Foreign.C.Types finiteBitSize :: CBool -> Int # countLeadingZeros :: CBool -> Int # countTrailingZeros :: CBool -> Int # | |
Bits CBool # | |
Defined in Foreign.C.Types (.&.) :: CBool -> CBool -> CBool # (.|.) :: CBool -> CBool -> CBool # xor :: CBool -> CBool -> CBool # complement :: CBool -> CBool # shift :: CBool -> Int -> CBool # rotate :: CBool -> Int -> CBool # setBit :: CBool -> Int -> CBool # clearBit :: CBool -> Int -> CBool # complementBit :: CBool -> Int -> CBool # testBit :: CBool -> Int -> Bool # bitSizeMaybe :: CBool -> Maybe Int # shiftL :: CBool -> Int -> CBool # unsafeShiftL :: CBool -> Int -> CBool # shiftR :: CBool -> Int -> CBool # unsafeShiftR :: CBool -> Int -> CBool # rotateL :: CBool -> Int -> CBool # | |
Storable CBool # | |
Instances
Instances
Instances
Instances
Numeric types
These types are represented as newtype
s of basic
foreign types, and are instances of
Eq
, Ord
, Num
, Read
,
Show
, Enum
, Typeable
and Storable
.
Haskell type representing the C clock_t
type.
Instances
Enum CClock # | |
Defined in Foreign.C.Types | |
Eq CClock # | |
Num CClock # | |
Ord CClock # | |
Defined in Foreign.C.Types | |
Read CClock # | |
Real CClock # | |
Defined in Foreign.C.Types toRational :: CClock -> Rational # | |
Show CClock # | |
Storable CClock # | |
Haskell type representing the C time_t
type.
Instances
Enum CTime # | |
Eq CTime # | |
Num CTime # | |
Ord CTime # | |
Defined in Foreign.C.Types | |
Read CTime # | |
Real CTime # | |
Defined in Foreign.C.Types toRational :: CTime -> Rational # | |
Show CTime # | |
Storable CTime # | |
Haskell type representing the C useconds_t
type.
Since: base-4.4.0.0
Instances
Enum CUSeconds # | |
Defined in Foreign.C.Types succ :: CUSeconds -> CUSeconds # pred :: CUSeconds -> CUSeconds # fromEnum :: CUSeconds -> Int # enumFrom :: CUSeconds -> [CUSeconds] # enumFromThen :: CUSeconds -> CUSeconds -> [CUSeconds] # enumFromTo :: CUSeconds -> CUSeconds -> [CUSeconds] # enumFromThenTo :: CUSeconds -> CUSeconds -> CUSeconds -> [CUSeconds] # | |
Eq CUSeconds # | |
Num CUSeconds # | |
Ord CUSeconds # | |
Defined in Foreign.C.Types | |
Read CUSeconds # | |
Real CUSeconds # | |
Defined in Foreign.C.Types toRational :: CUSeconds -> Rational # | |
Show CUSeconds # | |
Storable CUSeconds # | |
Defined in Foreign.C.Types |
newtype CSUSeconds #
Haskell type representing the C suseconds_t
type.
Since: base-4.4.0.0
Instances
To convert CTime
to UTCTime
, use the following:
\t -> posixSecondsToUTCTime (realToFrac t :: POSIXTime)
Floating types
These types are represented as newtype
s of
Float
and Double
, and are instances of
Eq
, Ord
, Num
, Read
,
Show
, Enum
, Typeable
, Storable
,
Real
, Fractional
, Floating
,
RealFrac
and RealFloat
. That does mean
that CFloat
's (respectively CDouble
's) instances of
Eq
, Ord
, Num
and
Fractional
are as badly behaved as Float
's
(respectively Double
's).
Haskell type representing the C float
type.
Instances
Enum CFloat # | |
Defined in Foreign.C.Types | |
Eq CFloat # | |
Floating CFloat # | |
Fractional CFloat # | |
Num CFloat # | |
Ord CFloat # | |
Defined in Foreign.C.Types | |
Read CFloat # | |
Real CFloat # | |
Defined in Foreign.C.Types toRational :: CFloat -> Rational # | |
RealFloat CFloat # | |
Defined in Foreign.C.Types floatRadix :: CFloat -> Integer # floatDigits :: CFloat -> Int # floatRange :: CFloat -> (Int, Int) # decodeFloat :: CFloat -> (Integer, Int) # encodeFloat :: Integer -> Int -> CFloat # significand :: CFloat -> CFloat # scaleFloat :: Int -> CFloat -> CFloat # isInfinite :: CFloat -> Bool # isDenormalized :: CFloat -> Bool # isNegativeZero :: CFloat -> Bool # | |
RealFrac CFloat # | |
Show CFloat # | |
Storable CFloat # | |
Haskell type representing the C double
type.
Instances
Enum CDouble # | |
Eq CDouble # | |
Floating CDouble # | |
Fractional CDouble # | |
Num CDouble # | |
Ord CDouble # | |
Read CDouble # | |
Real CDouble # | |
Defined in Foreign.C.Types toRational :: CDouble -> Rational # | |
RealFloat CDouble # | |
Defined in Foreign.C.Types floatRadix :: CDouble -> Integer # floatDigits :: CDouble -> Int # floatRange :: CDouble -> (Int, Int) # decodeFloat :: CDouble -> (Integer, Int) # encodeFloat :: Integer -> Int -> CDouble # significand :: CDouble -> CDouble # scaleFloat :: Int -> CDouble -> CDouble # isInfinite :: CDouble -> Bool # isDenormalized :: CDouble -> Bool # isNegativeZero :: CDouble -> Bool # | |
RealFrac CDouble # | |
Show CDouble # | |
Storable CDouble # | |