
Dear all, I wonder if anyone knows a good way of giving an unboxed mutable array (e.g. IOUArray) to the C world using the FFI in constant time? (I.e. a conversion to a Ptr.) I presume that an IOUArray is implemented as nothing but a Haskell object that has some information plus a pointer to a "normal" C array. I would like to get to that pointer! I could of course implement my own verion of IOUArray which uses a Ptr inside, but it seems silly to redo all the work that has gone into IOUArray. I have also a feature request for mutable arrays: Is it possible to prove a function like "realloc" which extends the array to a larger size, copying all existing information? Right now, I have to do this myself; I am using a type 'IORef (UArray ..)' which seems kind of silly and unnecessarily inefficient. Regards, /Koen

On Thu, May 08, 2003 at 02:34:14PM +0200, Koen Claessen wrote:
Dear all,
I have also a feature request for mutable arrays: Is it possible to prove a function like "realloc" which extends the array to a larger size, copying all existing information? Right now, I have to do this myself; I am using a type 'IORef (UArray ..)' which seems kind of silly and unnecessarily inefficient.
Unfortunately, it wouldn't be compatible with current MArray class. Its declaration begins with: class (HasBounds a, Monad m) => MArray a e m where It requires type constructor 'a' to belong to HasBounds constructor class. HasBounds' method 'bounds' knows nothing about Monad m, it is a pure function: bounds :: (Ix i) => a i e -> (i, i) With realloc it would return m (i, i) So, it is more a design issue than implementation issue.
Regards, /Koen
Regards, Tom -- .signature: Too many levels of symbolic links

You could use storable arrays (Data.Array.Storable), but as pointed out by someone else you're going to run into problems with bounds. I think what you'll have to do is do your own bounds in your own data type and then provide your own readArray/writeArray functions based on these bounds and the unsafeRead/Write functions. Not really any cleaner than using an IORef :). -- Hal Daume III | hdaume@isi.edu "Arrest this man, he talks in maths." | www.isi.edu/~hdaume On Thu, 8 May 2003, Koen Claessen wrote:
Dear all,
I wonder if anyone knows a good way of giving an unboxed mutable array (e.g. IOUArray) to the C world using the FFI in constant time? (I.e. a conversion to a Ptr.)
I presume that an IOUArray is implemented as nothing but a Haskell object that has some information plus a pointer to a "normal" C array. I would like to get to that pointer!
I could of course implement my own verion of IOUArray which uses a Ptr inside, but it seems silly to redo all the work that has gone into IOUArray.
I have also a feature request for mutable arrays: Is it possible to prove a function like "realloc" which extends the array to a larger size, copying all existing information? Right now, I have to do this myself; I am using a type 'IORef (UArray ..)' which seems kind of silly and unnecessarily inefficient.
Regards, /Koen
_______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
participants (3)
-
Hal Daume III
-
Koen Claessen
-
Tomasz Zielonka