
I'm working with FFI to make a Haskell DLL that's called by C# code. I understand how to share simple types. I've found reasonable documentation for struct-equivalents. Is there a clean way to share lists, or should I make a linked-list struct and do it manually? In other words, if I have adder :: CInt -> CInt -> CInt adder x y = (x+y) then I can use foreign export stdcall adder :: CInt -> CInt -> CInt and on the other side it behaves like int adder(int a, int b); I'd like to know what to do if I have squares :: [CInt] -> [CInt] squares = map (^2) Advice? --Kim

On Tue, 2010-03-02 at 13:19 -0800, Kimberly Wallmark wrote:
I'm working with FFI to make a Haskell DLL that's called by C# code. I understand how to share simple types. I've found reasonable documentation for struct-equivalents. Is there a clean way to share lists, or should I make a linked-list struct and do it manually?
In other words, if I have adder :: CInt -> CInt -> CInt adder x y = (x+y)
then I can use foreign export stdcall adder :: CInt -> CInt -> CInt
and on the other side it behaves like int adder(int a, int b);
I'd like to know what to do if I have squares :: [CInt] -> [CInt] squares = map (^2)
Advice?
--Kim
You have to marshal it from/into C array so: foreign export stdcall squares :: Int -> Ptr CInt -> Ptr CInt -> IO () squares n f t = pokeArray t =<< map (^2) `fmap` peekArray n f Regards
participants (2)
-
Kimberly Wallmark
-
Maciej Piechotka