[Haskell-beginners] Simple UTF-8 output

Christopher Howard christopher.howard at frigidcode.com
Sat May 28 06:01:51 CEST 2011


On 05/26/2011 11:38 PM, Erik de Castro Lopo wrote:
> Elvio Toccalino wrote:
> 
>> I usually pull such values as ByteStrings. The utf8-strings package
>> provides printing functions for such data.
>> Also, if you'd like to work on it as Text, there's the
>> Data.Text.Encodings module, to decodeUTF8 or decodeASCII ByteString's
>> into Text.
> 
> I would recommend Data.Text because that is designed for Text
> encodings while ByteString is designed for handling arrays
> of bytes (eg things like data read from an network socket).
> 
> Cheers,
> Erik

Thank you everyone for your responses, but I'm still having trouble with
this issue. This is what I've learned so far:

- The problem is not my terminal: commands like putStrLn "\228" produce
the correct character.
- The problem doesn't seem to be my MySQL database. The character
encoding on the database and on the table are set to UTF-8. I can view
the characters just fine when in the MySQL client.
- I looked again at the character numbers on the special characters
being outputted by my program: They are not the correct Unicode numbers.
Apparently the special characters are somehow getting mangled when I
pull them from the database.
- The choice to put the query results into ByteStrings was not mine,
that is just what is in the results list that quickQuery gives me. I
tried converting to Text and then to String by using "unpack (decodeUtf8
byte_str)"; however, when the program goes to print its first line with
an extended character, it just throws the exception: "*** Exception:
Cannot decode byte '\xe6': Data.Text.Encoding.decodeUtf8: Invalid UTF-8
stream".

-- 
frigidcode.com
theologia.indicium.us



More information about the Beginners mailing list