Haskell中没有打印中文字符

时间:2014-09-04 03:27:39

标签: haskell unicode-string

对我来说,汉字打印并不顺畅。与putStrLn案例一样:

*Main> putStrLn "中文"
- 

*Main> putStrLn "中文!"

-?

然后我按照stackoverflow的建议使用"MyPrint.hs"在输出中打印中文字符,而不会看到显示的字符。加载的原始MyPrint如下:

module MyPrint (myPrint, myShow) where
-- preparing for the 7.6.1
myPrint :: Show a => a -> IO ()
myPrint = putStrLn . myShow

myShow :: Show a => a -> String
myShow x = con (show x) where
   con :: String -> String
   con [] = []
   con li@(x:xs) | x == '\"' = '\"':str++"\""++(con rest)
            | x == '\'' = '\'':char:'\'':(con rest')
            | otherwise = x:con xs where
              (str,rest):_ = reads li
              (char,rest'):_ = reads li

在winGHCi中,结果如下:

*MyPrint> myPrint "asf萨芬速读法"
"asf(?"

GHCi中既不显示中文字符。为什么以及如何克服它?谢谢!

0 个答案:

没有答案