On Wed, 21 Dec 2005, Creighton Hogg wrote: > On Wed, 21 Dec 2005, Henning Thielemann wrote: > > > The drawback is that I saw many Haskell programs implemented with IO > > read/write functions which could be easily implemented without IO, using > > laziness. > > Can you think of any examples of things like that? Given > that I'm still learning how to take advantage of laziness > it'd be pretty interesting.
Some example for writing a text the IO oriented way: do putStrLn "bla" replicateM 5 (putStrLn "blub") putStrLn "end" whereas the lazy way is putStr (unlines (["bla"] ++ replicate 5 "blub" ++ ["end"])) You see that the construction of the text is separated from the output, but the effect is rather the same in both variants: The text is constructed simultaneously with output. You could also make the separation explicit: text :: String text = unlines (["bla"] ++ replicate 5 "blub" ++ ["end"]) main = putStr text _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe