[Haskell-Cafe] Parsing bytestream

C K Kashyap ckkashyap at gmail.com
Tue Nov 9 05:51:02 EST 2010

Thanks Ozgur and Felipe,

Could you also show how I could actually use it to parse a bytestring please?

import qualified Data.ByteString.Lazy as BS
import Control.Applicative ((<$>))
import Data.Word
import Data.Binary.Get

data MyAction = A1 Word8 | A2 Word16

a,b :: Get MyAction
a = A1 <$> getWord8
b = A2 <$> getWord16be

listOfActions :: [Get MyAction]
listOfActions = [a,b,a]

--sequence :: Monad m => [m a] -> m [a]
--runGet :: Get a -> ByteString -> a

bs = BS.pack [1,0,2]

How exactly can I get back a list of integers from bs?


More information about the Haskell-Cafe mailing list