[Haskell-cafe] Get out structured data from a C/C++ library in Haskell
nicola.gigante at gmail.com
Fri Aug 8 14:34:00 UTC 2014
I'm new to the list so I'd like to say hello to you.
I'm a student of computer science and early practitioner of Haskell.
I've decided to implement the next project in Haskell but I need to
interface a C++ library. I've read all the wikis material about the matter
and I have an understanding of how FFI to C works in general.
The library in question is a SAT solver for LTL formulas, and all I need
to do is to be able to create the AST of the formula (Haskell will do the
parsing) and pass it to the library, and then get back the reply.
From the C++ point of view, the AST of the formulas consists simply
of objects linked together with raw pointers. Nodes are of the same type,
with an internal enum that specifies the type of node, so it's not an
inheritance hierarchy or fancy things...
What I would like to do is to be able to declare an algebraic data type
that represents the AST and somehow mangle it to a form that can
be passed to the C++ function of the library (that I can wrap into an
extern "C" function to be able to use it through FFI if needed).
How can I do that? In general, I've only seen example of how to exchange
primitive types with C functions through the FFI, but not for example
structures or pointers to structures.
Note that I have control over the source code of the C++ library too,
so the question includes suggestions about how to structure the C++
data as well, to ease the integration.
Thank you for your help,
More information about the Haskell-Cafe