Created
February 27, 2012 14:49
-
-
Save qnikst/1924310 to your computer and use it in GitHub Desktop.
writer + binary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE PackageImports #-} | |
import Data.Binary.Get | |
import "mtl" Control.Monad.Writer | |
import qualified Data.ByteString.Lazy as SL | |
import Data.Word | |
main = do | |
l <- SL.readFile "test" | |
let (a,b) = runWriter $ next l 0 | |
print a | |
print b | |
where | |
next bs off | SL.null bs = return off | |
| otherwise = do | |
let (t,bs',off') = runGetState readChunk bs off | |
tell [t] | |
next bs' off' | |
readChunk :: Get Word16 | |
readChunk = getWord16le | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment