[Haskell-cafe] Newbie: Appending arrays?

Dmitri O.Kondratiev dokondr at gmail.com
Fri Jul 11 10:18:35 EDT 2008


How does Data.Sequence
http://www.haskell.org/ghc/docs/latest/html/libraries/containers/Data-Sequence.html
compares with ArrayRef for appending and accessing arrays efficiently ?

On Fri, Jul 11, 2008 at 4:58 PM, Chaddaï Fouché <chaddai.fouche at gmail.com>
wrote:

> 2008/7/11 Dmitri O.Kondratiev <dokondr at gmail.com>:
> > I don't quite understand how Data.Array.Diff work.
> > I tried this:
> >
> >> let arr = listArray (1,3) [1..3] :: DiffArray Int Int
> >
> > then:
> >> replaceDiffArray arr [(1, 777)]
> > array (1,3) [(1,1),(2,777),(3,3)]
> > Why when replacing first element the second one changes?
>
> replaceDiffArray is low-level, nobody should use it, use the normal
> IArray interface instead.
> (To answer your question, replaceDiffArray works with low level index,
> not the Ix class, all array are indexed by 0, 1, .. for it, so 1 is
> the index of the second element of the array)
>
> > and also trying to add 4-th element results in:
> > Prelude Data.Array.Diff> replaceDiffArray arr [(4, 444)]
> > array (1,3) [(1,1),(2,2),(3,3)]
> >
> > It looks like replaceDiffArray can not be used to add new element to the
> end
> > of array?
>
> No, the size of a DiffArray can't be changed : DiffArray are just an
> IArray instance with better performances for update than the classic
> IArray instance (which copy the entire content on every update...).
>
> There are some libraries that allows you to change the size of your
> array, be aware though that this operation is very costly (in every
> language).
> http://hackage.haskell.org/cgi-bin/hackage-scripts/package/ArrayRef
>
> --
> Jedaï
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080711/71645bce/attachment.htm


More information about the Haskell-Cafe mailing list