4

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

2
  • I think you mean toEnum not fromEnum. May 30, 2010 at 1:14
  • Using utf8-string in combination with the GHC native encoding stuff (setting the encoding of the handle) seems like it'd lead to double-escaping. I've only ever used utf8-string on earlier GHCs, before there was supported for specifying the encoding of handles.
    – solidsnack
    May 30, 2010 at 2:22

2 Answers 2

3

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.

1
  • Effectively, removing utf8-string removed my problem, I wouldn't have guessed. Thanks for the idea :) May 31, 2010 at 13:48
1

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)
2
  • Which file do you mean -- the output file or the source file?
    – solidsnack
    May 30, 2010 at 2:38
  • 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. May 30, 2010 at 7:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.