我需要序列化一个DAWG
(由this library)提供的字节字符串。正如我在文档中看到有一个实例(Ord b, Binary b) => Binary (DAWG a b)
似乎提供支持,我直接尝试使用encode
:?序列化类型定义的数据类型
import qualified Data.DAWG.Dynamic as Dawg
import qualified Data.Binary as Bin
Bin.encode $ Dawg.fromList [("foo",1),("bar",2)]
但GHC抱怨有no instance for (Bin.Binary (Dawg.DAWG Char b0))
我得到的,这是必要告诉GHC的数据类型图形包含,但后来,它是如何完成的点,如果我错了,我应该怎么做呢?
编辑: 堆栈跟踪Bin.encode $ Dawg.fromList [("foo"::String,1::Int),("bar",2)]
:
<interactive>:19:1:
No instance for (Bin.Binary (Dawg.DAWG Char Int))
arising from a use of `Bin.encode'
Possible fix:
add an instance declaration for (Bin.Binary (Dawg.DAWG Char Int))
In the expression: Bin.encode
In the expression:
Bin.encode
$ Dawg.fromList [("foo" :: String, 1 :: Int), ("bar", 2)]
In an equation for `it':
it
= Bin.encode
$ Dawg.fromList [("foo" :: String, 1 :: Int), ("bar", 2)]
没有完整的错误我不能确定,但可能你被咬了,因为'1'和'2'是多态的。给他们中的一个签名(例如':: Int'),看看会发生什么。 –
您是否试过'Bin.encode $ Dawg.fromList [(“foo”,1 :: Int),(“bar”,2 :: Int)]'?我认为'Binary'需要一个具体的类型来自动序列化数字。 –
我刚试过这个,但是GHC仍然抱怨(虽然它知道图形类型是'Dawg.DAWG Char Int')。 – michaelmeyer