似乎GHC在它决定解码的字符编码中至少是不一致的.
考虑一个文件,omatase-shimashita.txt其中包含以下内容,以UTF-8编码:お待たせしました
readFile 似乎正确地读了这个......
Prelude> content <- readFile "/home/chris/Desktop/omatase-shimashita.txt"
Prelude> length content
8
Prelude> putStrLn content
????????
Run Code Online (Sandbox Code Playgroud)
但是,如果我编写一个简单的"echo"服务器,它不会使用默认的UTF-8进行解码.请考虑以下处理传入客户端的代码:
handleClient handle = do
line <- hGetLine handle
putStrLn $ "Read following line: " ++ toString line
handleClient handle
Run Code Online (Sandbox Code Playgroud)
以及相关的客户端代码,明确发送UTF-8:
Data.ByteString.hPutStrLn handle $ Codec.Binary.UTF8.Generic.fromString "????????"
Run Code Online (Sandbox Code Playgroud)
这不是不一致的行为吗?有这种疯狂的方法吗?我打算重写我的应用程序以显式使用ByteString对象并使用显式编码和解码Codec.Binary.UTF8,但是最好知道这里发生了什么......:o /
更新:我在Ubuntu Linux版本10.10上运行,其语言环境为en_US.UTF-8 ...
$ cat /etc/default/locale
LANG="en_US.UTF-8"
$ echo $LANG
en_US.UTF-8
Run Code Online (Sandbox Code Playgroud)