2012-04-14 39 views
2

努力學習如何使用Data.Binary和猛擊這裏的障礙:有人可以修復以下Data.Binary示例代碼嗎?

http://www.haskell.org/haskellwiki/Serialisation_and_compression_with_Data_Binary

D:\Projects\haskell\serialize\ex1.hs:114:26: 
    Couldn't match expected type `bytestring-0.9.1.10:Data.ByteString.Lazy.Internal.ByteString' 
       with actual type `L.ByteString' 
    Expected type: Int 
        -> bytestring-0.9.1.10:Data.ByteString.Lazy.Internal.ByteString 
     Actual type: Int -> L.ByteString 
    In the return type of a call of `toByteString' 
    In the second argument of `(.)', namely `toByteString f' 

D:\Projects\haskell\serialize\ex1.hs:122:21: 
    Couldn't match expected type `L.ByteString' 
       with actual type `bytestring-0.9.1.10:Data.ByteString.Lazy.Internal.ByteString' 
    In the first argument of `L.length', namely `fs' 
    In the first argument of `(+)', namely `L.length fs' 
    In the first argument of `(==)', namely `L.length fs + L.length is' 
[Finished] 

回答

7

它看起來像你的驚天動地包一團糟;您安裝了多個版本的bytestring軟件包,並且它們存在衝突。最有可能的情況是binary程序包取決於您導入Data.ByteString.Lazy時獲得的不同版本的bytestring

最簡單的做法可能是從頭開始清理出你的Cabal目錄。在Windows上,這些目錄似乎是C:\Program Files\HaskellC:\Documents And Settings\username\Application Data\cabal。不過,我認爲不加區別地清除前者會完全卸載Haskell平臺,所以要小心;另一方面,最簡單的事情可能是卸載Haskell平臺並重新開始。 (此外,您可能首先需要複製config文件,以避免覆蓋您的Cabal配置。)

cabal-dev對於保持像這樣的問題非常有用;它將自己的沙箱中的每個程序構建起來,這樣包程序問題的影響就會被本地化並且可以很容易地清理乾淨。不過,我不知道它在Windows上的運行情況如何。

+0

我從\ user \ AppData \ Roaming \刪除cabal和ghc,然後卸載haskell平臺,然後刪除剩餘的目錄並重新安裝。現在我已經安裝了cabal-dev,並且使用它來獲取二進制包,但是現在在示例代碼中出現以下錯誤:'無法找到模塊'Data.Binary': 它是隱藏包'ghc -binary-0.5.0.2''。 – joshj 2012-04-14 02:42:47

+0

忘記將cabal-dev安裝的二進制文件添加到C:\ Users \ ... \ cabal-dev/binary-0.5.1.0 \ ghc-7.0.4 – joshj 2012-04-14 02:46:08

+0

使用cabal-dev,您必須爲您編寫一個Cabal文件項目列出您的所有依賴項。 'cabal init'會引導你生成一個基本的Cabal文件,但是最簡單的方法就是'cabal install binary',然後再次編譯程序,而不是試圖讓cabal-dev工作。 (你可以刪除那個cabal-dev目錄,它的目的是去你的項目的目錄,而不是在系統目錄中。) – ehird 2012-04-14 02:47:17

相關問題