[Haskell-cafe] How to put a string into Data.Binary.Put

C K Kashyap ckkashyap at gmail.com
Sat Nov 6 08:30:45 EDT 2010


Hi,
I was trying to put a String in a ByteString

import qualified Data.ByteString.Lazy as BS
message :: BS.ByteString
message = runPut $ do
                                  let string="SOME STRING"
                                  map (putWord8.fromIntegral.ord)
string  -- this ofcourse generates [Put]

How can I convert the list of Put's such that it could be used in the Put monad?

For now I used the workaround of first converting the string to
ByteString like this -

stringToByteString :: String -> BS.ByteString
stringToByteString str = BS.pack (map (fromIntegral.ord) str)

and then using putLazyByteString inside the Put monad.

-- 
Regards,
Kashyap


More information about the Haskell-Cafe mailing list