[Haskell-cafe] Re: Tutorial uploaded
Peter Simons
simons at cryp.to
Wed Dec 21 13:35:28 EST 2005
> 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"]))
Um, maybe it's just me, but I think the first program is far
superior to the second one. The last thing you want your I/O
code to be is lazy. You want the exact opposite: you want it
to be as strict as possible. Not only does the second
version waste a lot of CPU time and memory for pointlessly
constructing a lazily evaluated list nobody ever needs, it
will also explode into your face the moment you use that
approach to write any non-trivial number of bytes.
Peter
More information about the Haskell-Cafe
mailing list