<div dir="ltr">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 model<div><a href="http://hackage.haskell.org/package/llvm-general">http://hackage.haskell.org/package/llvm-general</a><br>

</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Aug 8, 2014 at 10:34 AM, Nicola Gigante <span dir="ltr"><<a href="mailto:nicola.gigante@gmail.com" target="_blank">nicola.gigante@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello everybody.<br>
<br>
I'm new to the list so I'd like to say hello to you.<br>
I'm a student of computer science and early practitioner of Haskell.<br>
<br>
I've decided to implement the next project in Haskell but I need to<br>
interface a C++ library. I've read all the wikis material about the matter<br>
and I have an understanding of how FFI to C works in general.<br>
<br>
The library in question is a SAT solver for LTL formulas, and all I need<br>
to do is to be able to create the AST of the formula (Haskell will do the<br>
parsing) and pass it to the library, and then get back the reply.<br>
<br>
>From the C++ point of view, the AST of the formulas consists simply<br>
of objects linked together with raw pointers. Nodes are of the same type,<br>
with an internal enum that specifies the type of node, so it's not an<br>
inheritance hierarchy or fancy things...<br>
What I would like to do is to be able to declare an algebraic data type<br>
that represents the AST and somehow mangle it to a form that can<br>
be passed to the C++ function of the library (that I can wrap into an<br>
extern "C" function to be able to use it through FFI if needed).<br>
<br>
How can I do that? In general, I've only seen example of how to exchange<br>
primitive types with C functions through the FFI, but not for example<br>
structures or pointers to structures.<br>
<br>
Note that I have control over the source code of the C++ library too,<br>
so the question includes suggestions about how to structure the C++<br>
data as well, to ease the integration.<br>
<br>
Thank you for your help,<br>
Nicola<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br></div>