optimistic evaluation

Tomasz Zielonka tomasz.zielonka at gmail.com
Tue Feb 7 16:16:49 EST 2006

On Tue, Feb 07, 2006 at 09:52:49PM +0100, Tomasz Zielonka wrote:
> There's also a related idea to decrease the priority of garbage
> producing threads (and/or increase for garbage reducing threads). This
> way it would be possible to make the idiomatic Haskell 'wc' (word count)
> implementation space efficient with some simple 'par' annotations:
>     main = do
>         cs <- getContents
>         let nChars = length cs
>             nWords = length (words cs)
>             nLines = length (lines cs)
>         (nChars `par` nWords `par` nLines) `seq` return ()
>         print (nChars, nWords, nLines)
> (I am not sure I used "par" correctly, but I hope you know what I mean).

Intuitively, the three threads computing nChars, nWords and nLines would
chase each other on the cs list. The thread that is causing bigger
memory residency would get his priority lowered. At last it would be
stopped and other threads would have a chance to consume what was
produced. Thus longer and longer prefixes of cs could be reclaimed.

But I am not sure it's possible to implement. One question is how to
measure thread's impact on memory use. Counting allocations seems to be
not enough. In our example, the "nWords" threads consuming what was
produced by the "nChars" thread, would probably allocate at the same
speed as "nChars" thread (it creates the word list), but it should get a
higher priority.

Best regards

I am searching for programmers who are good at least in
(Haskell || ML) && (Linux || FreeBSD || math)
for work in Warsaw, Poland

More information about the Glasgow-haskell-users mailing list