On Jun 26, 2009, at 01:11 , Hector Guilarte wrote:
Ok, I got it this time, thanks! I should really talk this with my teacher. I'll post whatever he tells me... Let's hope he lets me just acumulate all the strings and print them in the end.
You're still missing what lazy evaluation means. If you write the equivalent of
while x := read line do mylist = mylist ++ x doneresult = process mylist -- this is the "accumulate all the strings" part.. except it isn't
for x in result do print x done what you get is actually something like while x := read line do print (process [x]) doneThis is because of laziness: each part of the program requests only the minimum that is needed at any given time, and execution is interleaved as necessary. You can think of it as: "print x" requires a single item "x", so it steps through "process" until a single item is produced; "process" then steps through the "while read" until it gets enough information to produce that single item being demanded at the moment. How much depends on what "process" actually does: if, for example, it's adding 1 to each item in the list, then it only needs to do 1 iteration of the "while read" in order to get something to add 1 to and pass on to the "print x" that is demanding an item from it.
-- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH
PGP.sig
Description: This is a digitally signed message part
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe