[Haskell-cafe] Releasing head of lazy ByteString

Helgi Kristvin Sigurbjarnarson helgikrs at gmail.com
Sun Feb 20 19:07:45 CET 2011

On Sun, Feb 20, 2011 at 03:38:17PM +0000, tsuraan wrote:
> lazy <- getContents clientSock
> let (lenBS, rest1) = splitAt 8 lazy
> let length = runGet getWord64be lenBS
> let (msg, rest2) = splitAt (fromIntegral length) rest1
> -- process msg
> The program never uses that initial "lazy" again, but it's there, and
> it's been assigned, so I assume that reference to the head of the
> stream will always be around, and thus always consuming memory.

The compiler should be able to figure it out, but if not you could
rewrite the first two lines as:

(lenBS, rest1) <- splitAt 8 `fmap` getContents clientSock

Helgi Kristvin Sigurbjarnarson <helgikrs (at) gmail (dot) com>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110220/581bde92/attachment.pgp>

More information about the Haskell-Cafe mailing list