[Haskell-cafe] Re: Tutorial uploaded

Tomasz Zielonka tomasz.zielonka at gmail.com
Wed Dec 21 13:51:15 EST 2005

On Wed, Dec 21, 2005 at 07:35:28PM +0100, Peter Simons wrote:
>  > 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.

Isn't it just the usual elegance/efficiency trade-off?

Personally, I would prefer the first version, unless it was
not efficient enought. Actually this example is a bit too
simple to show the benefits and problems of both approaches.
Consider using a pretty printing library vs doing the same
thing as a sequence of putStr's.

Best regards

I am searching for a programmer who is good at least in some of
[Haskell, ML, C++, Linux, FreeBSD, math] for work in Warsaw, Poland

More information about the Haskell-Cafe mailing list