[Haskell-cafe] Get out structured data from a C/C++ library in Haskell

Carter Schonwald carter.schonwald at gmail.com
Fri Aug 8 14:53:43 UTC 2014

if you want to see a REALLY nice example of mapping (back and forth!)
between a C++ AST and an Haskell AST, llvm-general is a pretty good role

On Fri, Aug 8, 2014 at 10:34 AM, Nicola Gigante <nicola.gigante at gmail.com>

> Hello everybody.
> 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,
> Nicola
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140808/35687f10/attachment.html>

More information about the Haskell-Cafe mailing list