[Haskell-cafe] Running out of space while concatinating a list of bytestring
C K Kashyap
ckkashyap at gmail.com
Wed Feb 27 09:02:45 CET 2013
Hi,
I have the following code - It looks like things go okay until
concatination is attempted. I get the following output
There are 2258 ByteStrings
*** Exception: <stdout>: hPutBuf: resource exhausted (Not enough space)
I am thinking that I should do strict concatination at each point in the
support function - how can I go about doing so? (BS is the lazy.char8
bytestring)
connectionGetNBytes :: NC.Connection -> Int -> IO ByteString
connectionGetNBytes c n = do
bs <- connectionGetNBytes' c n
putStrLn ("There are " ++ (show (length bs)) ++ "
ByteStrings")
return (BS.concat bs)
connectionGetNBytes' :: NC.Connection -> Int -> IO [ByteString]
connectionGetNBytes' _ 0 = return []
connectionGetNBytes' c n = do
l <- NC.connectionGet c n
let ll = BS.length l
remaining <- connectionGetNBytes' c (n - ll)
return (l:crlfStr:remaining)
Regards,
Kashyap
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130227/b5f0bb9b/attachment.htm>
More information about the Haskell-Cafe
mailing list