I make extensive use of this by compiling haskell shared libs that are called outside Haskell.
usually the tasks involved would be to
- create the proper foreign export declarations
- create Storable instances for any datatypes you need to marshal
- create the C structures (or structures in the language you're using) to read this information
- since I don't want to manually initialize the haskell RTS, i add initiallisation/termination code to the lib itself. (dllmain in windows __attribute__ ((constructor)) on unix)
- since I no longer need any of them, I create a .def file to hide all the closure and rts functions from being in the export table (windows)
- use GHC to compile everything together
These tasks are rather robotic and structured, to a point you could write something to automate them. Infact what I use myself to do this is a tool I created which does dependency tracing on functions you marked to be exported, and it'll wrap them up and compile the shared lib for you along with giving you the declarations in C/C++.
(unfortunately, this tool is not yet on hackage, because there is something I still need to fix and test alot more before I'm comfortable doing so)