我创建了一个简单的项目来演示这个问题:https://github.com/jdevelop/testcabal
如果我使用'cabal install'编译和安装模块,我无法用二进制序列化TestData:
> ghci
GHCi, version 7.0.4: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
ghci> :m +TestBinary.Test Data.Binary
ghci> randomData . decode $ encode emptyTest
<interactive>:1:24:
No instance for (Binary TTestData)
arising from a use of `encode'
Possible fix: add an instance declaration for (Binary TTestData)
In the second argument of `($)', namely `encode emptyTest'
In the expression: randomData . decode $ encode emptyTest
In an equation for `it':
it = randomData . decode $ encode emptyTest
如果我直接将Test.hs加载到ghci中 - 一切都按预期工作,
> ghci TestBinary/Test.hs
GHCi, version 7.0.4: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
[1 of 1] Compiling TestBinary.Test ( TestBinary/Test.hs, interpreted )
Ok, modules loaded: TestBinary.Test.
ghci> randomData . decode $ encode emptyTest
Loading package array-0.3.0.2 ... linking ... done.
Loading package bytestring-0.9.1.10 ... linking ... done.
Loading package containers-0.4.0.0 ... linking ... done.
Loading package binary-0.5.1.0 ... linking ... done.
"123456"
Haskell编译器的版本:
> ghci --version
The Glorious Glasgow Haskell Compilation System, version 7.0.4