我正在尝试使用Data.Binary来序列化Map,但是我收到了一个错误:没有足够的字节.然后我试着用一个整数列表做一个更简单的例子,在这里,这也不起作用.什么可能是错的?我的代码中是否有错误,我误解了或者我的安装有问题,在这种情况下我该如何解决?
以下是我的测试代码......
import Data.Binary
worldfile = "binarysimple.world"
main = do
ser <- decodeFileOrFail worldfile
case ser of
Right w -> showWorld $ show (w :: [Int])
Left (_,s) -> putStrLn ("the error:"++s) >> newworld
newworld = do
let world = [1,2,3] :: [Int]
showWorld $ show world
encodeFile worldfile $ encode world
showWorld = putStrLn
Run Code Online (Sandbox Code Playgroud)
...运行时的输出:
ghci binarysimple.hs
GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package …Run Code Online (Sandbox Code Playgroud)