Martin Stein <[EMAIL PROTECTED]> writes: 
> 
> Hi,
> 
> > By manually copying over the bytes - here's the version that I'll
> > probably add to the MutableArray interface:
> > 
> > ...
> > 
> > The unsafe version of this and thawArray should be supported in the
> > next release too.
> 
> Do unsafeThawArray and unsafeFreezeArray avoid the copying?
> That would be necessary because the array's are large.
> 

Yes, that's right, leaving you the programmer with the obligation to
prove that doing so is safe.

> A last question: Why do hFillBufBA and hPutBufBA only support 
> the indextype Int?

They're low-level IO ops, no Ix'ery required (nor wanted.)
Converting a "ByteArray (Int,Int)" to a "ByteArray Int" is
possible (and, in this context, safe):

hFillBufBA :: Ix ix => Handle -> ByteArray ix -> Int -> IO ()
hFillBufBA h ba bytes = PrelHandle.hFillBufBA h coerced_ba bytes
  where
   coerced_ba = unsafeCoerce# ba

hPutBufBA :: Ix ix => Handle -> ByteArray ix -> Int -> IO ()
hPutBufBA h ba bytes = PrelHandle.hPutBufBA h coerced_ba bytes
  where
   coerced_ba = unsafeCoerce# ba

> I would need (Int,Int)? Or is there any *cheap* convertion present?

unsafeCoerce# has very low run-time costs :-)

> 
> PS: I ever thought that such file operations are quite usual. 
> Why don't they appear in the standard prelude?
> 


Who knows, but a concrete proposal of what operations you'd like
to see supported here would be more than welcome.

--Sigbjorn

Reply via email to