[Haskell-cafe] Re: Tutorial uploaded
lemming at henning-thielemann.de
Wed Dec 21 08:50:33 EST 2005
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")
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
text :: String
text = unlines (["bla"] ++ replicate 5 "blub" ++ ["end"])
main = putStr text
More information about the Haskell-Cafe