I can’t get GHCi or GHC to print unicode codepoint 221A (sqrt symbol: √).
I don’t think it’s my shell, because I can get ruby to do it:
irb> puts "\u221A"
√
GHC/GHCi is another issue:
ghci> putStrLn "\8730"
ghci> withFile "temp.out" WriteMode $ flip hPutStrLn "\8730"
ghci> readFile "temp.out"
"\SUB\n"
So what am I doing wrong?
(GHC v6.l0.3)
GHC’s behavior with unicode changed in GHC 6.12.1 to “do the right thing” with Unicode strings. Prior versions truncate to 8 bit characters on IO (forcing the use of an encoding library).
That is, ‘\8730’ is 0x221a, while ‘\SUB’ is 0x1a — the high byte is gone.
Here with GHC 7:
But I get your result with GHC 6.8. Like this:
as the unicode bits are being truncated to 8 bits.
GHC 7 + IO works as expected:
Can you upgrade to GHC 7 (in the Haskell Platform) to get full Unicode support? If this is not possible, you can use one of the encoding libraries, such as utf8-string