4

我对 msgpack的haskellpython客户端之间的差异感到困惑。这个:

import Data.MessagePack as MP
import Data.ByteString.Lazy as BL

BL.writeFile "test_haskell" $ MP.pack (0, 2, 28, ())

和这个:

import msgpack

with open("test_python", "w") as f:
    f.write(msgpack.packb([0, 2, 28, []]))

给我不同的文件:

$ diff test_haskell test_python
Binary files test_haskell and test_python differ

谁能解释一下,我做错了什么?也许我误解了一些关于ByteString使用的东西?

4

1 回答 1

9

Haskell 中的空()元组与 Python 中的空元组或空列表不同。这与 Python 中的类似None。(在 msgpack 的上下文中)。

因此,要获得相同的结果,请将 haskell 程序更改为:

MP.pack (0, 2, 28, [])  -- empty list

或者将python程序更改为:

f.write(msgpack.packb([0, 2, 28, None]))

看一个演示。

于 2014-09-20T16:19:14.413 回答