[Haskell-cafe] Re: FFI and lists?
Maciej Piechotka
uzytkownik2 at gmail.com
Tue Mar 2 21:17:28 EST 2010
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20100302/aa735e1b/attachment.bin
More information about the Haskell-Cafe
mailing list