
Hi, Am Dienstag, den 04.10.2011, 09:39 +0300 schrieb Roman Cheplyaka:
Suppose I want a foldl which is evaluated many times on the same list but with different folding functions.
I used this pattern successfully in SAT-Britney, where I generate a huge list quite quickly, and I don’t want this list to stay in memory. I had to pay a lot of attention to sharing, e.g. by making sure the parameters to the function that generate the left fold are only passed when the folding functions are also given, see in http://git.nomeata.de/?p=sat-britney.git;a=commitdiff;h=e8a1eea156b76d76729a... the changes to TransRules.hs. Otherwise, I’d get a huge thunk of closures representing the list, as Jan-Willem predicted. Note that I want to achieve something differently than you, unless I am mistaken: In my case, I want to make sure the list can be fused or at least immediately garbage-collected with every use, even if the code that calculates the list has to be run multiple times. Greetings, Joachim -- Joachim "nomeata" Breitner mail@joachim-breitner.de | nomeata@debian.org | GPG: 0x4743206C xmpp: nomeata@joachim-breitner.de | http://www.joachim-breitner.de/