Converting [Word8] to String

Folks, How do I convert a list of bytes to a string? Cale has suggested a neat way of parsing binary packets in this thread: http://www.mail-archive.com/haskell-cafe@haskell.org/msg09413.html and I'm trying to create a packet reader for a Pascal-style string where the length is the first byte and the list of characters follows. I understand that I can take the first X bytes of the byte list but how do I make this into a string? I'll probably use fast packed strings to read from the socket handle and will unpack the fps into a list of bytes for parsing. Thanks, Joel -- http://wagerlabs.com/

Tomasz Zielonka wrote:
How do I convert a list of bytes to a string?
I assume you don't care about Unicode:
That should have said "I assume that the data is encoded using ISO-8859-1 (or a subset thereof, e.g. US-ASCII)".
map (Char.chr . fromIntegral)
or
map (toEnum . fromEnum)
For anything else, you will have to either to write a decoder (or use
someone else's; several exist for UTF-8), or interface to iconv()
using the FFI.
--
Glynn Clements

Am Sonntag, 2. Oktober 2005 12:52 schrieb Joel Reymont:
Folks,
How do I convert a list of bytes to a string?
Cale has suggested a neat way of parsing binary packets in this thread:
http://www.mail-archive.com/haskell-cafe@haskell.org/msg09413.html
and I'm trying to create a packet reader for a Pascal-style string where the length is the first byte and the list of characters follows.
You seem to think that one byte has to correspond to one character but this isn't the case in certain character encodings. In addition, even if one byte corresponds to one character, a byte b doesn't necessarily denote a character c with ord c == b. One has to take the encoding into account.
[...]
Best wishes, Wolfgang

I know it does since I control the protocol :-). On Oct 4, 2005, at 11:04 AM, Wolfgang Jeltsch wrote:
You seem to think that one byte has to correspond to one character but this isn't the case in certain character encodings. In addition, even if one byte corresponds to one character, a byte b doesn't necessarily denote a character c with ord c == b. One has to take the encoding into account.
participants (4)
-
Glynn Clements
-
Joel Reymont
-
Tomasz Zielonka
-
Wolfgang Jeltsch