haskell - Lazy binary get -


why data.binary.get isn't lazy says? or doing wrong here?

import data.bytestring.lazy (pack) import data.binary.get (runget, isempty, getword8)  getwords =   empty <- isempty   if empty     return []     else       w <- getword8       ws <- getwords       return $ w:ws  main = print $ take 10 $ runget getwords $ pack $ repeat 1 

this main function hangs instead of printing 10 words.

the documentation linked provides several examples. first 1 needs read input before can return , looks lot have written. second 1 left-fold , processes input in streaming fashion. here's code rewritten in style:

module main  import data.word (word8) import qualified data.bytestring.lazy bl import data.binary.get (rungetstate, getword8)  getwords :: bl.bytestring -> [word8] getwords input    | bl.null input = []    | otherwise =       let (w, rest, _) = rungetstate getword8 input 0       in w : getwords rest  main :: io () main = print . take 10 . getwords . bl.pack . repeat $ 1 

testing:

*main> :main [1,1,1,1,1,1,1,1,1,1] 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -