Reputation: 1116
I am able to export simple haskell functions through FFI containing standard data types. However, I do not know how to export a function that takes data type other than standard data types.
E.g.
data SomeType a = SomeType a
data SomeOtherType b = SomeOtherType b
doSomething:: SomeType a -> SomeOtherType b
How can I export function doSomething?
The existing documents talks about very simple examples.
Upvotes: 5
Views: 521
Reputation: 1116
The alternative is to lift the function to use StablePtr, and export the function with the StablePtr. Of Course as pointed out in the above answer you have use the function with instance that cane be exported.
It would be great to use something like H/Direct to plumb this code into c++ objects so that it can be accessed as object.
Upvotes: 2
Reputation: 2697
Short answer is, you can't.
You need to pick an instance of the function and export that.
e.g. doSomething :: SomeType Int -> SomeOtherType Int
is exportable. I wrote a longer answer here that might be helpful
The reason is that the Haskell side needs to know how to marshall the structure, how much memory to allocate etc.
Upvotes: 1