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

Gregory Crosswhite gcross at phys.washington.edu
Sat Nov 6 13:08:44 EDT 2010


On 11/6/10 6:38 AM, C K Kashyap wrote:
> Thanks a lot Gregory and Daniel,
>
> I think I'll go with the "mapM_ (putWord8 . fromIntegral . ord)" approach.
>

If your string has any chance of containing Unicode characters then you 
will want to use the "encode" function in the module 
"Codec.Binary.UTF8.String" in the package "utf8-string", so that the 
code becomes

     mapM_ putWord8 . encode

Cheers,
Greg


More information about the Haskell-Cafe mailing list