[Haskell-cafe] Is it safe to use unsafePerformIO here?
Daniel Fischer
daniel.is.fischer at web.de
Tue Sep 15 17:31:09 EDT 2009
Am Dienstag 15 September 2009 23:00:40 schrieb Cristiano Paris:
> On Tue, Sep 15, 2009 at 10:42 PM, Daniel Fischer
>
> <daniel.is.fischer at web.de> 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
More information about the Haskell-Cafe
mailing list