[Haskell-cafe] Make strict (IO String) lazy

Henning Thielemann lemming at henning-thielemann.de
Thu Mar 15 09:57:52 EDT 2007


 On the one hand, in the standard libraries there are functions like
readFile, getContents, hGetContents which read a file lazily. This is
often a nice feature, but sometimes lead to unexpected results, say when
reading a file and overwriting it with modified contents. Unfortunately
the standard libraries provide no functions for strict reading, and one
has to do this manually.
 On the other hand, when I write some IO function that returns a String, I
easily end up with a function which produces the String in a strict way.
(Say I call some shell commands and concatenate their outputs.)
 What is the preferred way to turn a strict (IO String) into a lazy one?
forkIO? forkOS? How would one derive readFile from a hypothetical
strictReadFile?


More information about the Haskell-Cafe mailing list