[Haskell-cafe] Array copying
jules at jellybean.co.uk
Tue Dec 4 09:32:09 EST 2007
Andrew Coppin wrote:
> Andrew Coppin wrote:
>> copy :: Word32 -> IOUArray Word32 Bool -> Word32 -> IO (IOUArray
>> Word32 Bool)
>> copy p grid size = do
>> let size' = size * p
>> grid' <- newArray (1,size') False
>> (\n -> do
>> b <- readArray grid n
>> if b
>> then mapM_ (\x -> writeArray grid' (n + size*x) True) [0..p-1]
>> else return ()
>> return grid'
> Actually, thinking about this... for most kinds of arrays (whether boxed
> or unboxed, mutable or immutable) there's probably a more efficient way
> to copy the data then this. Maybe we should add something to the various
> array APIs to allow efficient copying of arrays / large chunks of arrays?
Ideally we'd have the compiler generate optimal code anyway, then you
wouldn't need such things.
So, let's hope those compiler/optimiser guys keep working hard!
More information about the Haskell-Cafe