msgpack:haskell&;python
我对msgpack和客户端之间的差异感到困惑。 这: 这是:msgpack:haskell&;python,python,haskell,msgpack,Python,Haskell,Msgpack,我对msgpack和客户端之间的差异感到困惑。 这: 这是: 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 谁能解释一下,我做错了什么?也许我通过testring误解了用法
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
谁能解释一下,我做错了什么?也许我通过testring误解了用法?Haskell中的空元组()
与Python中的空元组或空列表不同。它类似于Python中的None
。(在msgpack的上下文中)
因此,要获得相同的结果,请将haskell程序更改为:
MP.pack (0, 2, 28, []) -- empty list
f.write(msgpack.packb([0, 2, 28, None]))
或者将python程序更改为:
MP.pack (0, 2, 28, []) -- empty list
f.write(msgpack.packb([0, 2, 28, None]))
msgpack是否关心列表与元组?在haskell中,您使用的是一个元组(其最后一个元素是unit aka()
),而在python中,您使用的是一个列表(其最后一个元素是[]
,即空列表)。试试看。@pythonpackb
带元组的rampion结果与列表相同。