Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在Haskell中使用Data.MessagePack_Python_Haskell_Serialization_Messagepack - Fatal编程技术网

Python 如何在Haskell中使用Data.MessagePack

Python 如何在Haskell中使用Data.MessagePack,python,haskell,serialization,messagepack,Python,Haskell,Serialization,Messagepack,是一种二进制序列化格式,显然可以从Haskell和Python中使用,我需要在我的项目中混合使用这两种语言 我需要序列化的结构非常简单: data Citation = Citation { sourceDocument :: Document, targetDocument :: Document, links :: [ Reference ] } type Reference = (Int, Int) data Document = Document {

是一种二进制序列化格式,显然可以从Haskell和Python中使用,我需要在我的项目中混合使用这两种语言

我需要序列化的结构非常简单:

data Citation = Citation {
    sourceDocument :: Document,
    targetDocument :: Document,
    links :: [ Reference ]
}

type Reference = (Int, Int)

data Document = Document {
    words :: [ ByteString ],
    wordNums :: [ Int ]
}
但我不知道从哪里开始。显然,MessagePack库支持某种类型的自动派生,通过使“Document”自动成为OBJECT的实例,可以简化上述操作,但我调用自动派生的尝试迄今为止失败了

你觉得怎么样

以下是指向该库的链接: 下面是一些示例的链接,根据上述版本的文档,这些示例都不起作用:


  • 我不熟悉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)
    

    (注意:一般来说,向我们展示您尝试的不起作用的代码是有帮助的,而不是让我们猜测您的尝试可能不起作用,因为您没有启用或诸如此类。)

    谢谢@dave4420。是的,下次我会写下我的尝试,但事实是我没有想到$thing,我没有尝试。看起来msgpack Haskell lib作者在最新版本中禁用了自动派生。事实上@donatello。这在中是不可用的。