2013-03-24 43 views
1

从Data.Binary:如何使用参数化实例删除(Data.Binary)?

instance (Binary e) => Binary (IntMap.IntMap e) where 
    put = put . IntMap.toAscList 
    get = liftM IntMap.fromDistinctAscList get 

我认为这意味着任何IntMap (Binary e)类型是serialisable,但它并不:

Data.Binary Data.IntMap> encode $ ((fromList [])::IntMap Int) 

<interactive>:12:1: 
    No instance for (Binary (IntMap Int)) 
     arising from a use of `encode' 

如何使用所提供的实例?

回答

6

我认为这意味着任何IntMap (Binary e)类型是serialisable,但它并不:

它做(除了鸡蛋里挑骨头,它应该读任何IntMap e是serialisable如果有instance Binary e)。

Prelude Data.IntMap Data.Binary> encode (fromList [] :: IntMap Int) 
"\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL" 

,你有几乎肯定意味着你使用的是IntMap是不是从你的binary与建造的containersIntMap,但从另一个版本的错误消息。来自containers的不同版本的IntMap s是不同的类型,并且Binary实例仅用于与之建立的确切版本binary

自从您安装binary以来,您可能已经安装了较新版本的containers

由ghci中的命令行上指定一个-package标志,并通过使用Cabal编译使用containers版本binary与建。

+0

啊!恰当地,我之前被警告说升级容器会导致问题!谢谢 – Scott 2013-03-24 22:14:25