What would be necessary to implement a c++ ffi

i love haskell and would love to write more of it, for that to happen i believe we need more cross language support. there is a lot of c++ code out there and although you can interface with c++ through c with the current ffi,
c++ supports a form of polymorphism(templates) and more recently something similar to typeclasses(concepts).
being able to use these features alone makes in my opinion a c++ ffi desirable and depending on how it is done we could potentially pack even more features into a c++ ffi.
i personally want a c++ ffi, but i have no idea on how to start implementing it and i believe someone at least must have thought about this before, what steps would need to be taken to implement such an ffi in ghc and is there anyone working on it already?

1 Like

The first step is to be able to extract information from compiled C++ libraries. That must be done via the ABI, which is compiler dependent. From a quick internet search, I believe GCC and Clang both use the standard Itanium C++ ABI (there is already a itanium-abi package on Hackage but it is still missing some things like templates), but MSVC uses it’s own thing which might even change between different versions.

The second step would be to figure out how to represent C++ features in Haskell. Templates and concepts might look similar to polymorphism and type classes in Haskell, but it is really exactly the same? There is probably some work required to convert between the two.

1 Like

Assuming i care about compatibility only for clang and GCC, i would need to only query the itanium abi of a c++ library and generate haskell objects? about c++ features ideally we would have many people discussing this and implementing it, the only thing that really crosses my mind is using a myriad of type classes to represent things from c++ but someone else could have a better idea. so the steps would be
requirement gathering β†’ implement code to query the abi for relevant things β†’ ??
β†’ make ghc recognize cplusplus calling convention
compared to the previous of
requirement gathering β†’ ?? β†’ make ghc recognize cplusplus calling convention.
this is a massive improvement.