views:

134

answers:

2

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

+1  A: 

There are at least two things you have to make sure:

  • The Terminal encoding must be set to UTF8:

alt text

  • The file is indeed encoded in UTF8 (it should be if you observe the right result on Linux)
Olivier
Which file do you mean -- the output file or the source file?
Jason Dusek
You have an output file? I thought the output was in the Terminal... The input file must be encoded in UTF8. But in your case, I suppose the problem lies in the Terminal's encoding.
Olivier
+2  A: 

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.

Jason Dusek
Effectively, removing utf8-string removed my problem, I wouldn't have guessed. Thanks for the idea :)
Raoul Supercopter