Passing a matrix from C to Haskell

Cyril Schmidt cschmidt at deds.nl
Wed Feb 8 11:39:51 EST 2006


Chris Kuklewicz wrote:
> Cyril Schmidt wrote:
>> I need to pass a big 2-dimensional array of doubles from a legacy
>> C code to a Haskell module. Of this huge array, the Haskell code will
>> actually use only
>> a few elements (say, 10 out of 100x20 matrix). Unfortunately, the C code
>> does not know
>> which data are actually needed in the Haskell module.
>
> You probably want Foreign.Marshal.Array
>
> http://www.haskell.org/ghc/docs/6.4.1/html/libraries/base/Foreign-Marshal-Array.html
>
> peekArray :: Storable a => Int -> Ptr a -> IO [a]
>
This works, but peekArray is very slow.

Cheers

Cyril





More information about the Glasgow-haskell-users mailing list