Using Haskell components in C++ projects

I am looking into writing specific components in Haskell to use inside a c++ project packaged with cmake.

CMake should be able to call cabal to prepare the component, right?

I also found this repo but nothing changed there for 11 years so I don’t know if thats still accurate.

1 Like

I’d recommend starting with figuring out how to include Haskell packages in regular C projects, before moving on to C++.

I think Cabal’s foreign-libraries documentation is relevant, but I’ve also never used that before.

1 Like

CMake should be able to call cabal to prepare the component, right?

Correct, with the right configuration in your projectname.cabal file, the output of calling cabal build projectname will be a .so (or .dylib or .dll depending on your OS) file, which you can dynamically load in your C++ program at link time.

A more recent example you might be able to get some inspiration from is my virgil-FFI example project, which integrates Haskell with (in this case) Python.

2 Likes