4

I'm confused by the differences between haskell and python clients for msgpack. This:

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 the different files:

$ diff test_haskell test_python
Binary files test_haskell and test_python differ

Can anybody explain, what I'm doing wrong? Maybe I misunderstood something about ByteString usage?

falsetru
  • 357,413
  • 63
  • 732
  • 636
erthalion
  • 3,094
  • 2
  • 21
  • 28
  • Does msgpack care about lists vs tuples? In haskell you're using a tuple (whose last element is unit aka `()`), and in python you're using a list (whose last element is `[]`, the empty list). Try [using python tuples](http://www.tutorialspoint.com/python/python_tuples.htm). – rampion Sep 20 '14 at 15:47
  • @rampion Result of the python ``packb`` with tuples is the same as for lists. – erthalion Sep 20 '14 at 15:53

1 Answers1

9

The empty tuple () in Haskell is not like empty tuple or empty list in Python. It's similar to None in 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 a demo.

xiº
  • 4,605
  • 3
  • 28
  • 39
falsetru
  • 357,413
  • 63
  • 732
  • 636