ByteString.Lazy.Char8 (Not enough space)

112 views Asked by At

This code gives <stdin>: hGetBufSome: resource exhausted (Not enough space) error as soon as it's executed.

import qualified Data.ByteString.Lazy.Char8 as B8
main = do
    (l:_) <- B8.lines `fmap` B8.getContents
    B8.putStrLn l

I'm just trying to get the first line. So because of lazy loading it wouldn't try to get others right? I can't figure out how to avoid this error.

2

There are 2 answers

4
ErikR On BEST ANSWER

There seems to be a problem with lazy bytestrings on 64-bit Windows 7, e.g.

Since the reports are all from over a year ago, I would try using GHC 7.8.3 (for example, from the Haskell Platform 2014.2.0.0) if you are not already using that version.

0
sclv On

Here's the bug report against GHC on this issue: https://ghc.haskell.org/trac/ghc/ticket/11009#ticket

I guess the solution for now is to not use getContents on lazy bytestrings (switch to strict or just read incrementally).