streaming, state, etc...

Jorge Adriano
Sun, 3 Nov 2002 19:04:41 +0000

OK so I had completed my (search) algorithm implementation. And the 'last=
function was something like:  "until p f x0".=20
But now I wanted all iterations, I wanted to analyze the behavior of the=20
algorithm. What could I do? I thought about using  Trace... but it didn't=
seem adequate, I wanted to manipulate and use that info... maybe monads..=
that would cluter my algorithm so bad...
This feeling lasted for a few seconds, then I thought, Lazy Evaluation!
"iterate p f x0" There, done :)
I had an infinite list, and I'd just take as much as I wanted.
*Analysis* and the *algorithm* itself were *completely separated*, yet it=
using the information as soon as it was calculated - or maybe "it was bei=
calculated only when it was needed". I could not do this kind of stuff in=
imperative languages. Very nice :)

Problem 1:
I've used that many times since then, but lately it doesn't really seem t=
serve my needs. What if I need to get two different kinds of data, say=20
(list1, list2), and now I want to write them:

writeFile file1 (analyze list1)
writeFile file2 (analyze list2)

What if you need to evaluate list2 to evaluate list1? Not good!
I'm evaluating list2 and not consuming it, therefore space leak.
I could alternate between one list and another, but what if at a certain=20
point, evaluating the next elem in "list1" caused the evaluation of a few=
thousand elements of "list2"?

So how do you usually deal with this kind of stuff? Concurrency??

Problem 2:
Yes  "iterate p f x0" looks good. What if function "f" is not a pure one?
If my monad is a Lazy one, streaming can be used(*), if it is not, that w=
work. So streaming could work with monads like State, (lazy) ST. Not with=
or (lazy) ST.

  writeFile file1 (analyze list)

So, how do you usually do this kind of thing - extracting lists of info f=
an algorithm?