Haskell: read special characters from the console

I would like to read a line from the console containing special characters like ö, ä, ü, μ ... I tried:

do ... ts <- getLine ...

but this does not work for these characters. For example, unicode for ö is \ 246, but if I use getLine to read in ö haskell, read in "\ 195 \ 182" and putStr "\ 195 \ 182" gives me ö, which is not ö. What is the problem? Do I need another function to read these characters?

I am using WinGHCi 7.0.3 for windows xp. I would be glad if someone could help me, because I have not found anything so far.


@ Judah Jacobson:

I tried again before entering any other commands, and got the following:

Prelude> :m +System.IO
Prelude System.IO> hSetEncoding stdin utf8
Prelude System.IO> getLine
ασδφ
"\206\177\207\402\206\180\207\8224"
Prelude System.IO> putStr "\206\177\207\402\206\180\207\8224"
ασδφPrelude System.IO> 

I also tried the windows chcp 65001 command, but it didn’t change anything, I already had utf8 in windows.

+5
3

stdin UTF8. CP437 GHCi Windows XP UTF8 Mac.

hGetEncoding stdin (System.IO) hSetEncoding stdin utf8, .

. , Mac:

Prelude System.IO> hSetEncoding stdin latin1
Prelude System.IO> str <- getLine
ö
Prelude System.IO> putStr str
öPrelude System.IO> print str
"\195\182"
Prelude System.IO> hSetEncoding stdin utf8
Prelude System.IO> str <- getLine
ö
Prelude System.IO> putStr str
öPrelude System.IO> print str
"\246"
+2

GHC 6.12 UTF8 ( , ). , , . UTF8.

text, .

+3

; WinGHCi. GHC Windows Win32 -. WinGHCi GHC UTF8 , , 1252 (Latin-1).

, : hSetEncoding stdin utf8 . :

Prelude> :m +System.IO
Prelude System.IO> hSetEncoding stdin utf8
Prelude System.IO> getLine
ασδφ
"\945\963\948\966"

, , .

As an alternative, you are probably lucky with Unicode with the GHCi program (which, however, has a less pleasant graphical interface).

+1
source

All Articles