[Haskell-cafe] UTF-8 in Haskell.

Magicloud Magiclouds magicloud.magiclouds at gmail.com
Thu Dec 23 06:29:49 CET 2010

  Recently, I am reading ssh hackage
(http://hackage.haskell.org/package/ssh). When at the part of deal
with string, I got confused. I am not sure if this is a bug for the
hackage, or I am just misunderstanding.
  An ascii char takes a Word8. So this works (LBS stands for
toLBS :: String -> LBS.ByteString
toLBS = LBS.pack . map (fromIntegral . fromEnum)
  But a UTF-8 char takes a Int (Word32). Then I think the above code
would break the data, right?
  If so, OK, then I think I could make a packInt which turns an Int
into 4 Word8 first. Thus under all situation (ascii, UTF-8, or even
UTF-32), my program always send 4 bytes through the network. Is that

More information about the Haskell-Cafe mailing list