[Haskell-cafe] Re: Could FFI support pass-by-value of structs?

John Meacham john at repetae.net
Wed Jul 1 20:24:31 EDT 2009

On Wed, Jul 01, 2009 at 09:05:06PM -0300, Maurí­cio wrote:
>>> Do you imagine an objection on creating a ticket asking for
>>> something like CComplex on Foreign.C.Types?
>> No, I would like it. Also add a 'CBool' that maps to the calling
>> convention for _Bool while you are at it. 
> Here is a draft. Please comment:
> Proposal: complement Foreign.C.Types
> A few more types could be usefull in Foreign.C.Types. These
> are sugested to be included:
> * CBool
>     Related to 'bool' (or _Bool) from stdbool.h.

Good. It appears from the FFI spec that it is possible to define HsBool
as '_Bool' and let 'Bool' translate to a 'bool' calling convention.
However, it is not guarenteed so a CBool type that is guarenteed to map
to _Bool is still good.

It would be odd to define CBool as an intergral type though, perhaps we
should specify it be defined as

newtype CBool = CBool Bool

so we can convert between haskell Bool and CBool easily. Though,
for consistency with other C types, we may want to 

> * CComplexFloat, CComplexDouble
>     Related to 'float complex' and 'double complex'.

We need a way to actually examine the values, since 'fromIntegral' won't
work. I think the easiest way is to actually reuse Complex which is
already in Haskell 98, defining

Complex Foo where Foo is a FFI marshable type translates to the complex
version of said type. so 'Complex CDouble' translates to the external C
type of 'double complex'.

We may also want to add 'long double' as a c marshable type too.


John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/

More information about the Haskell-Cafe mailing list