[Haskell-cafe] Incrementially updating an array

Robert Clausecker fuzxxl at gmail.com
Tue Dec 28 13:46:24 CET 2010

Hi folks!

I have the following problem. As code is most time easier to understand,
let give an example what I try to do in C:

unsigned int i,j;
unsigned int r[100];
for (i = 0; i < 1000000; i++) {
  j = makeResult(); //j is known to be smaller than 100.
  r[j] = r[j] + 1;

(My C is poor, so please don't laugh)

Currently I'm using a Data.Map for this, but as the result is bounded in
this area, an array seems to be more appropreate. I don't want to mess
with mutable arrays, but I can't find anything which does the same like
Data.Map.insertWith for arrays in a reasonable way.

In my example, the input comes from a lazy list and is than folded into
the Map by insertWith (+) j 1 r. Is there any nice, quick way to do this
with Arrays without using mutable ones?

Yours, Robert Clausecker

More information about the Haskell-Cafe mailing list