对我来说,汉字打印并不顺畅。与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中既不显示中文字符。为什么以及如何克服它?谢谢!