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: http://stackoverflow.com/questions/1494478/call-a-haskell-function-in-net – caesay Nov 06 '10 at 02: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 Nov 06 '10 at 02:10
-
Possible duplicate of [Call a Haskell function in .NET](https://stackoverflow.com/questions/1494478/call-a-haskell-function-in-net) – Răzvan Flavius Panda Aug 16 '17 at 03: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.

- 1
- 1

- 76,893
- 19
- 209
- 302
-
I guess this seems to be the best resource I've found as well. I also found this thread http://stackoverflow.com/questions/3338940/automatic-conversion-of-types-for-ffi-calls-in-haskell – Ochowie Nov 06 '10 at 02:45