GHC: Display of unicode characters

て烟熏妆下的殇ゞ 提交于 2019-12-31 03:23:07

问题


Further to my first question on the management of the unicode characters in the production of .exe file, this is also a bug in GHC?

> print "Frère"
"Fr\233re"

回答1:


print x is equivalent to putStrLn (show x), where show converts a type of the Show class to a string representation.

In your case, x already has the String type. One might think that the String implementation of show would simply return its argument unchanged, but actually it transforms it into an ASCII string literal token with the same syntax as used in Haskell source code. This is done by surrounding it with quotes and by escaping 'special' characters (basically whatever is not on your keyboard).

So, this is not a bug but rather the expected behavior of print. If you want to output your string directly, use putStrLn instead.




回答2:


Try

> putStrLn "Frère"
Frère      


来源:https://stackoverflow.com/questions/21365317/ghc-display-of-unicode-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!