Passing a matrix from C to Haskell

Chris Kuklewicz haskell at
Tue Feb 7 18:35:39 EST 2006

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.
> What would be a good way to pass the array to Haskell and, once the data
> are handed over,
> what is the fastest way to fetch these elements?
> I was thinking of something like passing the array as Ptr Int#, but how
> do I fetch the elements
> that I am interested in?
> Cheers,
> Cyril

You probably want Foreign.Marshal.Array

peekArray :: Storable a => Int -> Ptr a -> IO [a]

More information about the Glasgow-haskell-users mailing list