
Am Dienstag 15 September 2009 23:00:40 schrieb Cristiano Paris:
On Tue, Sep 15, 2009 at 10:42 PM, Daniel Fischer
wrote: .... Aaawww. let b' = length b or let b' = foldl' seq () b or let b' = b `using` rnf
if you want to force the whole file to be read. But then you should definitely be using ByteStrings.
Yep. But that doesn't solve the original problem of not reading the body at all when not needed. Unless using unsafePerformIO.
Yeah, you do *not* want the whole file to be read here, except above for testing purposes. Still, ByteStrings are probably the better choice (if you want the body and that can be large). To avoid reading the body without unsafePerformIO: readBit fn = Control.Exception.bracket (openFile fn ReadMode) hClose (\h -> do l <- hGetLine h let i = read l bdy <- hGetContents h return $ Bit i bdy)
Cristiano