
15 Mar
2007
15 Mar
'07
9:57 a.m.
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?