7
votes

I would like to expose a function from a Haskell source library using FFI and use it in OCaml code. I saw various examples using the foreign export ccallsyntax in Haskell which I believe exports the function for usage in C. Is there something similar for OCaml? What would be the best approach to achieve this?

1
Probably one needs to use C as a lingua franca, and doing all the required marshalling Haskell<->C<->Ocaml. I don't think there's anything easier, as Haskell and Ocaml have quite different runtime systems. For instance, a pair of integers has a very different representation in the two languages, so one needs to convert accordingly. - chi
See interfacing C with OCaml in the manual and the ctypes library. - antron

1 Answers

0
votes

If this foreign export ccall works as I think it should, then you should end up with a shared object file roughly identical to what would be generated by a C compiler. Just pretend that's the case and feed that object file to your linker.