4

For me, the Chinese characters printing is not smooth. Like the putStrLn cases:

*Main> putStrLn "中文"
- 

*Main> putStrLn "中文!"

-?

I then follow a suggestion from stackoverflow to use "MyPrint.hs" to print Chinese characters in output without seeing the character shown. The loaded original MyPrint is as following:

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

In winGHCi, the result is like this:

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

Neither Chinese characters be shown in GHCi. Why and how to overcome it? Thanks!

Tanuj Mathur
  • 1,408
  • 10
  • 20
Ben Chen
  • 61
  • 1
  • 4
  • The windows console doesn't display Unicode characters correctly. http://stackoverflow.com/questions/10779149/unicode-console-i-o-in-haskell-on-windows – Cirdec Sep 04 '14 at 03:56
  • 2
    This boils down to exactly the same problem as described in the marked duplicate, but it's a good signpost to the problem as it describes the symptoms much more directly and visually. – Ganesh Sittampalam Sep 04 '14 at 04:42

0 Answers0