我对 haskell 之间的差异感到困惑和 python msgpack 的客户端。 这:
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
的用法?
最佳答案
Haskell 中的空元组 ()
不同于 Python 中的空元组或空列表。它类似于 Python 中的 None
。 (在 msgpack 的上下文中)。
因此,要获得相同的结果,请将 haskell 程序更改为:
MP.pack (0, 2, 28, []) -- empty list
或者把python程序改成:
f.write(msgpack.packb([0, 2, 28, None]))
关于python - msgpack: haskell 和 python ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25950447/