Ger*_*_RU 3 linux unicode encoding haskell utf-8
我quoteFile
在虚拟环境中遇到问题(安装了GHC 7.8.4的Debian Wheezy)。我从描述了st
准报价单的面向文件的版本Text.Shakespeare.Text
:
import Language.Haskell.TH.Quote (QuasiQuoter, quoteFile)
import Text.Shakespeare.Text (st)
sfFile :: QuasiQuoter
stFile = quoteFile st
Run Code Online (Sandbox Code Playgroud)
这在我的主机上工作得很好,但是,在我的虚拟环境(Docker映像)上失败并出现以下错误:
尝试运行编译时代码时发生异常:test-file.md:hGetContents:无效参数(无效字节序列)
代码:Language.Haskell.TH.Quote.quoteExp stFile“ test-file.md”
我的一点REPL调查表明,该错误发生在文本文件中的第一个unicode字符上,在我当前的情况下,这是'«'左指针双角引号:
import System.IO (IOMode(..), hGetContents, openFile, openBinaryFile, utf8)
main =
do h <- openBinaryFile "test-file.md" ReadMode
hGetContentContents h
-- Binary read works fine out-of-box.
h' <- openFile "test-file.md" ReadMode
hSetEncoding h' utf8
hGetContentContents h'
-- This works only if encoding is explicitly set, otherwise
-- it gives "invalid byte sequence" error at run-time
Run Code Online (Sandbox Code Playgroud)
在我看来,我要么需要配置我的虚拟环境,要么可能需要重建GHC本身。
我试图将locale设置为en.UTF-8 UTF-8
,但是它没有帮助(最初我没有进行任何locale配置)。
更新:目标文件具有UTF-8
编码:
import System.IO (IOMode(..), hGetContents, openFile, openBinaryFile, utf8)
main =
do h <- openBinaryFile "test-file.md" ReadMode
hGetContentContents h
-- Binary read works fine out-of-box.
h' <- openFile "test-file.md" ReadMode
hSetEncoding h' utf8
hGetContentContents h'
-- This works only if encoding is explicitly set, otherwise
-- it gives "invalid byte sequence" error at run-time
Run Code Online (Sandbox Code Playgroud)
最后,我发现我的虚拟语言环境没有正确设置,例如,locale
命令显示所有LANG
变量都设置为POSIX
。
将LANG
变量导出到命令是最快的解决方法(bash示例):
export LANG=en_US.UTF8 cabal build
Run Code Online (Sandbox Code Playgroud)
但是,可能需要en_US
安装语言环境,Debian手动配置为:
/etc/locale.gen
,添加新行en_US.UTF-8 UTF-8
locale-gen
以生成语言环境。LANG
变量。Debian语言环境Wiki 1
PS我的默认Debian Wheezy安装C.UTF-8
在默认语言环境列表中,因此我认为出于极简主义的目的,可以使用它而不是安装其他英语语言环境,但是我没有亲自对其进行测试。
归档时间: |
|
查看次数: |
540 次 |
最近记录: |