Hi, 
OK so I had completed my (search) algorithm implementation. And the 'last' 
function was something like:  "until p f x0". 
But now I wanted all iterations, I wanted to analyze the behavior of the 
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 was 
using the information as soon as it was calculated - or maybe "it was being 
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 to 
serve my needs. What if I need to get two different kinds of data, say 
(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 
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 won't 
work. So streaming could work with monads like State, (lazy) ST. Not with IO, 
or (lazy) ST.

(*) 
do
  list<-myalgorithm
  writeFile file1 (analyze list)


So, how do you usually do this kind of thing - extracting lists of info from 
an algorithm?
J.A.


_______________________________________________
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to