[Haskell-cafe] Odd lack of laziness

Chris Kuklewicz haskell at list.mightyreason.com
Thu Jun 21 15:17:10 EDT 2007


The (BS.length f) can only be computed by reading until the end of the file!

> breakIntoDocuments :: RawDocument -> [RawDocument]
> breakIntoDocuments f | BS.length f > 0 = if len > 0
>                                          then (BS.take bytes f) :
>                                               (breakIntoDocuments
>                                                  (BS.drop bytes f))
>                                          else (breakIntoDocuments
>                                                  (BS.drop bytes f))
>                      | otherwise      = []
>                      where len = decodeLengthBits f
>                            bytes = fromIntegral (len * 2 + len * 4 + 4)
> 
> 
> and a main function of:
> 
> main = do
>  f <- B.readFile "Documents.bin"
>  print (take 1 (breakIntoDocuments f))
> 
> 
> Shouldn't the program only read in enough of the lazy byte-string to
> create the first return value of breakIntoDocuments?  The return value
> of decodeLengthBits is only 277.  I watched it, and it's reading in my
> whole 2gb file...
> 
> -- Jeff
> 
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list