Handle to haskell data

David Waern davve at dtek.chalmers.se
Sun Nov 30 13:43:29 EST 2003


Hi. I want to know if it is possible via FFI and GHC to allocate
haskell data structures and return some kind of handle to their internal
representation in the haskell runtime to another language that calls
haskell code (c/c++).

Say, for example, that I want code a simple 3d-modelling program which
uses haskell to create and modify objects and c to use this functionality
and to present it to the user.

When an object is to be created the c code would call some haskell
function "Create" which returns the handle to the created object so that it
can be passed along to other haskell functions that modifies the object. The
c code would never have to know of the haskell datastructures representing
the object (Of course, there would have to be a haskell function that
returns a datastructure suited for drawing the object).

I had a quick look at the FFI-spec and saw that it is possible to
allocate and pass pointers to Storable types. I just don't want to
reconstruct my datastructures back and forth to Storable types each time I
need to do something on the haskell side.

Does any of this make sense? I should probably look into the spec more
before ranting so much :)

I don't have much haskell experience so maybe this is just something that
wouldn't come up if I would design my code properly.

/David Waern



More information about the FFI mailing list