ccast-0.1.0.0: typesafe c-style casts; useful for FFI

Safe HaskellNone
LanguageHaskell2010

CCast

Description

This module provides type-safe conversions from Foreign C types to Haskell types, and vice versa. It is especially convenient when writing code with Haskell's C FFI.

This module will not compile on non-64-bit operating systems.

Synopsis

Documentation

class Cast a b where Source #

A typeclass for typesafe c-style casts from a to b, for use with Haskell's C FFI. This is just a convenience, to prevent from having to think about numeric conversions. Type inference is still weak here; I recommend two solutions:

With -XTypeApplications:

cast @CChar @Int8 x -- convert x from CChar to Int8

With explicit type annotations:

cast x :: Int8      -- convert x from CChar to Int8

Methods

cast :: Coercible a b => a -> b Source #

Instances

Cast Double CDouble Source # 

Methods

cast :: Double -> CDouble Source #

Cast Float CFloat Source # 

Methods

cast :: Float -> CFloat Source #

Cast Int CInt Source #

WARNING! This conversion is potentially lossy.

Methods

cast :: Int -> CInt Source #

Cast Int8 CChar Source # 

Methods

cast :: Int8 -> CChar Source #

Cast Int8 CSChar Source # 

Methods

cast :: Int8 -> CSChar Source #

Cast Int16 CShort Source # 

Methods

cast :: Int16 -> CShort Source #

Cast Int32 CInt Source # 

Methods

cast :: Int32 -> CInt Source #

Cast Int32 CWchar Source # 

Methods

cast :: Int32 -> CWchar Source #

Cast Int32 CSigAtomic Source # 
Cast Int64 CLong Source # 

Methods

cast :: Int64 -> CLong Source #

Cast Int64 CPtrdiff Source # 

Methods

cast :: Int64 -> CPtrdiff Source #

Cast Int64 CClock Source # 

Methods

cast :: Int64 -> CClock Source #

Cast Int64 CTime Source # 

Methods

cast :: Int64 -> CTime Source #

Cast Int64 CSUSeconds Source # 
Cast Int64 CIntPtr Source # 

Methods

cast :: Int64 -> CIntPtr Source #

Cast Int64 CIntMax Source # 

Methods

cast :: Int64 -> CIntMax Source #

Cast Word8 CUChar Source # 

Methods

cast :: Word8 -> CUChar Source #

Cast Word8 CBool Source # 

Methods

cast :: Word8 -> CBool Source #

Cast Word16 CUShort Source # 

Methods

cast :: Word16 -> CUShort Source #

Cast Word32 CUInt Source # 

Methods

cast :: Word32 -> CUInt Source #

Cast Word32 CUSeconds Source # 
Cast Word64 CULong Source # 

Methods

cast :: Word64 -> CULong Source #

Cast Word64 CSize Source # 

Methods

cast :: Word64 -> CSize Source #

Cast Word64 CUIntPtr Source # 

Methods

cast :: Word64 -> CUIntPtr Source #

Cast CChar Int8 Source # 

Methods

cast :: CChar -> Int8 Source #

Cast CSChar Int8 Source # 

Methods

cast :: CSChar -> Int8 Source #

Cast CUChar Word8 Source # 

Methods

cast :: CUChar -> Word8 Source #

Cast CShort Int16 Source # 

Methods

cast :: CShort -> Int16 Source #

Cast CUShort Word16 Source # 

Methods

cast :: CUShort -> Word16 Source #

Cast CInt Int Source # 

Methods

cast :: CInt -> Int Source #

Cast CInt Int32 Source # 

Methods

cast :: CInt -> Int32 Source #

Cast CUInt Word32 Source # 

Methods

cast :: CUInt -> Word32 Source #

Cast CLong Int64 Source # 

Methods

cast :: CLong -> Int64 Source #

Cast CULong Word64 Source # 

Methods

cast :: CULong -> Word64 Source #

Cast CLLong Int64 Source # 

Methods

cast :: CLLong -> Int64 Source #

Cast CULLong Word64 Source # 

Methods

cast :: CULLong -> Word64 Source #

Cast CBool Word8 Source # 

Methods

cast :: CBool -> Word8 Source #

Cast CFloat Float Source # 

Methods

cast :: CFloat -> Float Source #

Cast CDouble Double Source # 

Methods

cast :: CDouble -> Double Source #

Cast CPtrdiff Int64 Source # 

Methods

cast :: CPtrdiff -> Int64 Source #

Cast CSize Word64 Source # 

Methods

cast :: CSize -> Word64 Source #

Cast CWchar Int32 Source # 

Methods

cast :: CWchar -> Int32 Source #

Cast CSigAtomic Int32 Source # 
Cast CClock Int64 Source # 

Methods

cast :: CClock -> Int64 Source #

Cast CTime Int64 Source # 

Methods

cast :: CTime -> Int64 Source #

Cast CUSeconds Word32 Source # 
Cast CSUSeconds Int64 Source # 
Cast CIntPtr Int64 Source # 

Methods

cast :: CIntPtr -> Int64 Source #

Cast CUIntPtr Word64 Source # 

Methods

cast :: CUIntPtr -> Word64 Source #

Cast CIntMax Int64 Source # 

Methods

cast :: CIntMax -> Int64 Source #

Cast (Complex Double) (CComplex CDouble) Source # 
Cast (Complex Float) (CComplex CFloat) Source # 
Cast (CComplex CFloat) (Complex Float) Source # 
Cast (CComplex CDouble) (Complex Double) Source # 

data CComplex a Source #

Complex number for FFI with the same memory layout as std::complex<T>

Constructors

CComplex !a !a