
lemming:
On Fri, 2 Nov 2007, Felipe Lessa wrote:
On 11/2/07, Stuart Cook
wrote: The solution would be to use a version of "readFile" that works in a stricter way, by reading the file when it's told to, but I don't have an implementation handy.
I guess this does the job:
readFile' fp = do contents <- readFile fp let ret (x:xs) = x `seq` ret xs ret [] = return contents ret contents
Maybe the "x `seq`" part isn't necessary at all.
Awful. It reminds me on MatLab where the developers have implemented many automatisms which do arbitrary clever things in every corner case, but nothing consistent, because they thought programmers want it that way. Then the programmers must write wrappers in order to get functions with consistent behaviour around the fully automated functions.
The "unlazying" procedure looks much like the "lazying" one, and I wonder whether it would be a good idea to eventually add "readFileStrict", "getContentStrict" and "hGetContentStrict" to the standard library.
Yes, I have often thought System.IO.Strict should be added to the strict package on hackage, maybe in terms of bytestring.readFile >>= return . unpack, since we're being strict anyway. The above is also a rather odd implementation of readFile', which is usually implemented by forcing the last element of the list instead. -- Don