Passing a matrix from C to Haskell

Ben Rudiak-Gould Benjamin.Rudiak-Gould at
Wed Feb 8 16:38:04 EST 2006

Cyril Schmidt wrote:
> I was thinking of something like passing the array as Ptr Int#, but how 
> do I fetch the elements that I am interested in?

I think you want Ptr CInt and peekElemOff. If the array is declared in C as

     int a[100][20]

and p :: Ptr CInt is a Haskell pointer to it, then a[y][x] can be accessed 
as peekElemOff p (y * 20 + x). This should be 100% portable.

-- Ben

More information about the Glasgow-haskell-users mailing list