I was wondering if there is any good documentation out there for integrating Haskell with the outside world (specifically .NET). I would like to be able to call Haskell functions from within my .NET code. I saw that there was a previously posed question that showed how to pass strings back and forth, but I was wondering if there are more general references and the possibility of passing more complex type.
-
1Dupe: stackoverflow.com/questions/1494478/…caesay– caesay2010-11-06 02:08:01 +00:00Commented Nov 6, 2010 at 2:08
-
I read that thread an it showed one specific example of calling a string function. I am looking for more general documentation on how to export functions out of Haskell.Ochowie– Ochowie2010-11-06 02:10:34 +00:00Commented Nov 6, 2010 at 2:10
-
Possible duplicate of Call a Haskell function in .NETRăzvan Flavius Panda– Răzvan Flavius Panda2017-08-16 03:55:20 +00:00Commented Aug 16, 2017 at 3:55
2 Answers
You should probably read the stuff in that other question more clearly, because it does actually give links to relevant stuff. But here's a bullet-point version anyway:
You can call unmanaged native code from .NET using P/Invoke. See the end of the Wikipedia article for tutorials and documentation on this part.
You can export Haskell functions through Haskell's FFI. Make sure you export the functions with the correct calling convention (stdcall, not ccall). See also GHC's FFI documentation.
So basically what you want to do is export your Haskell functions as if you were going to use them from C, build a DLL with the functions you want, then use P/Invoke to call the Haskell functions. And definitely re-read the accepted answer to the other question, it mentions several pitfalls you'll need to avoid.