Skip to content

Instantly share code, notes, and snippets.

@qnikst
Created February 27, 2012 14:49
Show Gist options
  • Save qnikst/1924310 to your computer and use it in GitHub Desktop.
Save qnikst/1924310 to your computer and use it in GitHub Desktop.
writer + binary
{-# 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