[Haskell-cafe] Re: Incremental array updates

Daniel Kraft d at domob.eu
Thu Feb 26 13:27:10 EST 2009

Ross Paterson wrote:
> On Thu, Feb 26, 2009 at 05:31:34PM +0100, Daniel Kraft wrote:
>> Well, my main problem was the lazy evaluation...
> No, your main problem was that you were creating 100,000 arrays,
> each only a little different from the one before.

Here I have to disagree (in my particular situation).  Even with 
Data.Array but the strict evaluation the program took about 5m, where it 
before wouldn't even get far because of all that memory swapping... 
With STUArray it took 1m--much better, but the worst of all was the 
horrific memory usage.

>> For this example program... yes of course :)  I'm trying to do so when  
>> possible, but for my real problem I couldn't figure out a nice way to do  
>> it like that, unfortunately.  Which does not mean it is impossible of  
>> course, but maybe just I need more experience in functional  
>> programming... :D
> Writing imperative programs in Haskell may not be the best way to gain
> that experience.  What is the pattern of updates in your actual program?

It was about this:  I needed to generate "all possibilities" for some 
combinations and each of those had a numeric property, say from 1 to 
10000; I then had to count how many of the possibilities were of a given 
"category".  So I created this array, generated all combinations, and 
incremented the matching slot each time.

I do not see how I could have done this another way, but I think it 
should be a fairly common pattern, so if there are ideas, I'd welcome them!


More information about the Haskell-Cafe mailing list