Safe Haskell | None |
---|---|
Language | Haskell2010 |
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.
Documentation
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
Complex number for FFI with the same memory layout as std::complex<T>
CComplex !a !a |