Mutable arrays

Hal Daume III hdaume@ISI.EDU
Thu, 8 May 2003 07:35:30 -0700 (PDT)

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                                   |
 "Arrest this man, he talks in maths."           |

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