[Haskell-beginners] hGetContents, unicode and linux

Erik de Castro Lopo mle+hs at mega-nerd.com
Sun Nov 28 02:18:55 EST 2010


Yitzchak Gale wrote:

> You can check to see what encoding GHC has picked up from your
> environment by examining localeEncoding.

How do I do that? TextEncoding doesn't seem to be Showable.

> You can force the encoding to UTF-8 by
> 
> hSetEncoding stdin utf8
> hSetEncoding stdout utf8
> 
> All of the above in the context of import System.IO, of course.

Thank you. My program:

    main :: IO ()
    main
     = do   h <- openFile "unicode.txt" ReadMode
            hSetEncoding h utf8
            hSetEncoding stdout utf8
            text <- hGetContents h
            putStr text

now works as it should.

Cheers,
Erik
-- 
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/


More information about the Beginners mailing list