File: HeapUse.hs

package info (click to toggle)
haskell-binary 0.4.1-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 292 kB
  • ctags: 11
  • sloc: haskell: 4,054; makefile: 88; ansic: 39
file content (17 lines) | stat: -rw-r--r-- 510 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
-- Checks heap behavior of getBytes

import Data.Binary.Get (runGet, getBytes)

import Control.Monad (liftM)
import qualified Data.ByteString.Lazy as L

main = do
       let x = (L.take 110000042 $ L.iterate (+1) 0)
       mapM_ (print . L.length) (chunks 20000000 x)

chunks n = runGet (unfoldM f)
  where f = do x <- getBytes 20000000 
               return $ if L.null x then Nothing else Just x

unfoldM :: Monad m => m (Maybe a) -> m [a]
unfoldM f = f >>= maybe (return []) (\x -> liftM (x:) (unfoldM f))