Outputing UTF-8 string on Mac OS's Terminal
I got a programm in haskell outputting utf-8 using the package utf8-string
and using only the output functions of this package.
I set the encoding of each file I write to this way :
hSetEncoding myFile utf8
{- myFile may be stdout -}
but when I try to output :
alpha = [toEnum 0x03B1] {- α -}
instead of the nice alpha letter I got on Linux (or in a file on windows), I got the following :
α
The weird thing is even if I try to write the output on a file, I can't read it back with mvim as an utf-8 file. Is there any way to get the correct behaviour开发者_如何学Go
Tried this on GHC 6.12 just now. The new encoding feature eliminates the need
for utf8-string
in this simple case.
import System.IO
main = do
out alpha stdout
alpha = [toEnum 0x03B1] {- α -}
out s handle = do
hSetEncoding handle utf8
hPutStrLn handle s
Please let me know if this works for you on OS X. Please post full code next time -- it would have made it much easier for me to help you.
There are at least two things you have to make sure:
- The Terminal encoding must be set to UTF8:
alt text http://files.droplr.com.s3.amazonaws.com/files/35740123/15WO3z.Picture%2026.png
- The file is indeed encoded in UTF8 (it should be if you observe the right result on Linux)
精彩评论