[Haskell-cafe] Newbie: Appending arrays?

Reid Barton rwbarton at math.harvard.edu
Fri Jul 11 13:44:34 EDT 2008


This doesn't require any fancy data structures.

On Fri, Jul 11, 2008 at 08:07:50PM +0400, Dmitri O.Kondratiev wrote:
> For example, array of unique vectors:
> [[10, 6, 80, 25, 6, 7],
> [1, 2, 15, 17, 33, 22],
> [21, 34, 56, 78, 91, 2]]
> 
> may have a corresponding counts array:
> [5,1,3]

Instead store this as a list of pairs [([10,6,80,25,6,7], 5), ...]
and it'll be easy to write a recursive function that accepts a new
vector and either increments the appropriate count or adds the new
vector at the end with count 1.

> I will also need to access vectors at different index in unique
> array later.

Then once you've finished constructing the list, turn it into an array
with listArray and use random access into that.

Regards,
Reid Barton


More information about the Haskell-Cafe mailing list