[Haskell-beginners] Extract and integer from a ByteString

Stephen Tetley stephen.tetley at gmail.com
Tue Jun 15 16:15:54 EDT 2010


Hi Tom

Try ...

extractInt :: [Word8] -> Int
extractInt = foldl addDigit 0
               where
               addDigit num d = 10*num + (fromIntegral d)


You might find you want to keep your functions monadic, and mostly use
the Get monad from the module Data.Binary.Get for working with binary
data.For instance there is a function getWord32be to do the work that
extractInt is doing

Best wishes

Stephen


More information about the Beginners mailing list