[Haskell-cafe] Accessing to a Haskell type in C

Yves Parès limestrael at gmail.com
Thu Mar 31 00:27:22 CEST 2011


Hello,

To access a haskell type from C code, do we have to make this type instance
of Storable (and so to also define an homomorph structure on the C side), or
does FFI specifies some C function to enable C code to access the fields, or
even some GHC-specific functions? (Even if I'd prefer a portable way)

I mean, if I have the type:

data Character = Character {
    pos :: (Float, Float),
    size :: Float,
    sprite :: Image
}

Do I compulsorily have to double its definition on C side:

stuct CCharacter {
    float x;
    float y;
    float size;
    Image sprite;
}

and then make Character instance of Storable, which will make the program
*copy* Characters to CCharacters each time that I must call a C function to,
say, draw a character?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110331/d0966d85/attachment.htm>


More information about the Haskell-Cafe mailing list