如何使Haskell或ghci能够显示汉字和运行汉字命名脚本? [英] How to make Haskell or ghci able to show Chinese characters and run Chinese characters named scripts?

查看:341
本文介绍了如何使Haskell或ghci能够显示汉字和运行汉字命名脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个Haskell脚本来读取我的/ home文件夹中的文件。但是有许多文件命名为汉字,Haskell和Ghci无法管理它。看起来Haskell和Ghci不擅长显示UTF-8字符。



这是我遇到的:

 前导> 让Haskell或者Ghci能正确显示汉字并且读取汉字命名的文档

\35753Haskell\25110\32773Ghci\33021\27491\30830\26174\31034 \27721\23383\24182\19988\35835\21462\27721\23383\21629\21517\30340\25991\26723

p>

解决方案

  Prelude& putStrLn\35753Haskell\ 25110\32773Ghci\33021\27491\30830\26174\31034\27721\23383\24182\19988\35835\21462\27721\23383 \21629\21517\30340\25991\26723
让Haskell或者Ghci能正确显示汉字并且读取汉字命名的文档

GHC处理unicode就好了。这些是你应该知道的事情:



它使用你的系统编码从字节到字符的转换,以及从控制台读取或写入时。因为它在你的例子中正确地从字节转换为字符,我想说你的系统编码设置正确。



show 函数 String 具有有限的输出字符集。 GHCI使用 show 函数打印计算表达式的结果,并通过 print 函数将值传递到 String 表示。



putStr putStrLn 函数实际上是向控制台写入一个 String 。 >

I want to make a Haskell script to read files in my /home folder. However there are many files named with Chinese characters, and Haskell and Ghci cannot manage it. It seems Haskell and Ghci aren't good at displaying UTF-8 characters.

Here is what I encountered:

Prelude> "让Haskell或者Ghci能正确显示汉字并且读取汉字命名的文档"

"\35753Haskell\25110\32773Ghci\33021\27491\30830\26174\31034\27721\23383\24182\19988\35835\21462\27721\23383\21629\21517\30340\25991\26723"

解决方案

Prelude> putStrLn "\35753Haskell\25110\32773Ghci\33021\27491\30830\26174\31034\27721\23383\24182\19988\35835\21462\27721\23383\21629\21517\30340\25991\26723"
让Haskell或者Ghci能正确显示汉字并且读取汉字命名的文档

GHC handles unicode just fine. These are the things you should know about it:

It uses your system encoding for converting from byte to characters and back when reading from or writing to the console. Since it did the conversion from bytes to characters properly in your example, I'd say your system encoding is set properly.

The show function on String has a limited output character set. The show function is used by GHCI to print the result of evaluating an expression, and by the print function to convert the value passed in to a String representation.

The putStr and putStrLn functions are for actually writing a String to the console exactly as it was provided to them.

这篇关于如何使Haskell或ghci能够显示汉字和运行汉字命名脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆