Open viferga opened 4 years ago
Some work done by @neilvillamizar : https://github.com/neilvillamizar/Haskell-Browse-Module-Signatures Haskell-Browse-Module-Signatures-main.zip
Have you see tweag's work on inline-r, inline-c, inline-js and more? I'm a big fan of more cross language interop. Especially since python has such great math and number processing libraries like numpy.
Haskell has a compiler generation tool that provides the stubs in C language to Haskell (https://wiki.haskell.org/Calling_Haskell_from_C). Due to this design, the loader must be implemented mostly with Haskell. The load from file, memory, introspection, the FFI dynamic calls, and others must be implemented in Haskell side.
For conversion types, Haskell must return a structure containing the raw pointer plus information about how to retrieve the data stored in its custom types. This is achieved by Foreing.Storable (http://hackage.haskell.org/package/base-4.12.0.0/docs/Foreign-Storable.html) with the following C API (https://gitlab.haskell.org/ghc/ghc/blob/master/includes/rts/storage/InfoTables.h). The conversion can be done from C side meanwhile the dynamic call exposes its types with this interface.
Example of interfacing Haskell with Rust using Storage API: https://github.com/AndyShiue/ende/blob/155b772b9ae584deb987a4dc171f6cf0fa94e713/backend/src/trans.rs
In order to get compiler flags for GHC for C/C++ (or Cargo): https://github.com/AndyShiue/ende/blob/155b772b9ae584deb987a4dc171f6cf0fa94e713/frontend/get_args.sh
This hints and implementation ideas are thanks to @petercommand .
Other references: Information about Storage and GC: https://stackoverflow.com/a/57154026 Threading and FFI: http://www.cs.toronto.edu/~trebla/personal/haskell/ghc-conc-ffi.xhtml Alternative way of serialization of data types: https://github.com/nh2/call-haskell-from-anything