
Hello,
I am trying to make a program that outputs some Unicode characters but the
output doesn't match what I try to print.
Attached is a little test program. It tries to print the arrows "←↑→↓" but
instead it outputs "\220\221\222\223" (that is, character number 220, then
221, then 222). I've also tried writing the Unicode code points (although GHC
6.6 should deal just fine with Unicode source code) and I get the same
result. In case anybody wants to try, this would be the
string: "\8592\8593\8594\8595".
I am also attaching the output file, you can see that the contents are not
right.
Any ideas what am I doing wrong here ?
Thank you.
--
Pupeno

The problem is that GHC's output functions only print the lowest 8 bits of each code point. To print these higher code points, you'll need to translate your [Char] into a byte encoding that your terminal will understand (most likely UTF-8). I know there are several of these floating around in the wild, hopefully someone will chime in with a code snippet soon. Also, I seem to remember that Bulat's Streams library supports some Unicode encodings, perhaps you can check there? Cheers, Spencer Janssen On Nov 5, 2006, at 12:17 PM, Pupeno wrote:
Hello, I am trying to make a program that outputs some Unicode characters but the output doesn't match what I try to print. Attached is a little test program. It tries to print the arrows "←↑→↓" but instead it outputs "\220\221\222\223" (that is, character number 220, then 221, then 222). I've also tried writing the Unicode code points (although GHC 6.6 should deal just fine with Unicode source code) and I get the same result. In case anybody wants to try, this would be the string: "\8592\8593\8594\8595". I am also attaching the output file, you can see that the contents are not right. Any ideas what am I doing wrong here ? Thank you. -- Pupeno
(http://pupeno.com) _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hello, http://repetae.net/repos/jhc/UTF8.hs has some nice functions for UTF-8 - unicode conversions. Regards, -- Intelligence is like a river: the deeper it is, the less noise it makes

Pupeno wrote:
Hello, I am trying to make a program that outputs some Unicode characters but the output doesn't match what I try to print. Attached is a little test program. It tries to print the arrows "←↑→↓" but instead it outputs "\220\221\222\223" (that is, character number 220, then 221, then 222). I've also tried writing the Unicode code points (although GHC 6.6 should deal just fine with Unicode source code) and I get the same result. In case anybody wants to try, this would be the string: "\8592\8593\8594\8595". I am also attaching the output file, you can see that the contents are not right. Any ideas what am I doing wrong here ? Thank you.
------------------------------------------------------------------------
import qualified System.IO as IO
main = do let str = "←↑→↓" putStrLn str h <- IO.openFile "test.output" IO.WriteMode IO.hPutStrLn h str
The problem is with the output of putStrLn. You need to encode the string into utf8. You can find several modules on the web, i have been using this one: http://www.haskell.org/pipermail/haskell-i18n/2004-February/000127.html
participants (4)
-
Luis F. Araujo
-
Piotr Kalinowski
-
Pupeno
-
Spencer Janssen