MessagePack是一种二进制序列化格式,显然可以在 Haskell 和 Python 中使用,我需要在我的项目中混合使用这两种语言。
我需要序列化的结构相当简单:
data Citation = Citation {
sourceDocument :: Document,
targetDocument :: Document,
links :: [ Reference ]
}
type Reference = (Int, Int)
data Document = Document {
words :: [ ByteString ],
wordNums :: [ Int ]
}
但我不知道从哪里开始。显然 MessagePack 库支持某种 deriving mechanism通过使“Document”自动成为 OBJECT 的实例,这将使上述操作变得容易,但到目前为止,我调用自动派生的尝试都失败了......
你觉得怎么样?
这是该库的链接:http://hackage.haskell.org/package/msgpack-0.7.1.5 这里是一些示例的链接,根据上述版本的文档,这些示例都不起作用:
最佳答案
我不熟悉 msgpack,但猜测这样的东西应该可以工作。
{-# LANGUAGE TemplateHaskell #-}
import Data.MessagePack.Derive
-- I don't know which of these lines you need
-- I also don't know whether the True should actually be False
$(deriveObject True ''Document)
$(derivePack True ''Document)
$(deriveUnpack True ''Document)
(注意。一般来说,向我们展示您尝试过但不起作用的代码会很有帮助,而不是让我们猜测您的尝试可能不起作用,因为您没有启用 TemplateHaskell 或其他任何东西。)
关于python - 如何在 Haskell 中使用 Data.MessagePack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15385041/