Msgpack: haskell & python

I am confused by the differences between haskell and python for msgpack. It:

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

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

and this:

import msgpack

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

give me different files:

$ diff test_haskell test_python
Binary files test_haskell and test_python differ

Can anyone explain what I'm doing wrong? Maybe I misunderstood something about ByteStringusage?

+4
source share
1 answer

An empty tuple ()in Haskell is not like an empty tuple or an empty list in Python. This is similar to Nonein Python. (in the context of msgpack).

So, to get the same result, change the haskell program as:

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

Or change the python program as:

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

See the demo .

+9
source

All Articles