我在我的虛擬環境(安裝了GHC 7.8.4的Debian Wheezy)中遇到了與quoteFile
相關的問題。我所描述的st
準加引號的面向文件的版本從Text.Shakespeare.Text
:Haskell:quoteFile在unicode字符上帶有「無效字節序列」的文本文件失敗
import Language.Haskell.TH.Quote (QuasiQuoter, quoteFile)
import Text.Shakespeare.Text (st)
sfFile :: QuasiQuoter
stFile = quoteFile st
這個作品非常好我的主機上,但是,這種失敗對我的虛擬環境(泊塢窗圖像)以下錯誤:
異常試圖運行時編譯時的代碼: test-file.md:hGetContents:無效的參數(無效字節序列)
代碼:Language.Haskell.TH.Quote.quoteExp stFile「測試音響le.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
在我看來,我需要配置我的虛擬環境,或者重建GHC本身。
我試圖設置語言環境爲en.UTF-8 UTF-8
,但這並沒有幫助(最初我沒有做過任何語言環境配置)。
更新:目標文件有UTF-8
編碼:
$ file -bi test-file.md
text/x-c++; charset=utf-8
給'hSetEncoding'一試... http://hackage.haskell.org/package/base-4.8.0.0/docs/System-IO.html#v:hSetEncoding – Arnon
@Arnon的問題是,我有由於讀取操作是內部的,因此不能訪問'stFile'引用的句柄。也許有一種方法設置所有句柄的默認編碼? –
不是我所知道的,沒有將它設置在整個操作系統的環境中,你聲稱你已經嘗試過..... – Arnon