
21 Dec
2005
21 Dec
'05
1:35 p.m.
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