Question

MessagePack is a binary serialization format, which apparently can be used from both Haskell and Python, languages that I need to mix in a project of mine.

The structures that I need to serialize are fairly trivial:

data Citation = Citation {
    sourceDocument :: Document,
    targetDocument :: Document,
    links :: [ Reference ]
}

type Reference = (Int, Int)

data Document = Document {
    words :: [ ByteString ],
    wordNums :: [ Int ]
}

but I have no idea where to start. Apparently the library for MessagePack supports some kind of deriving mechanism that would make easy to do the above, by making "Document" automatically an instance of OBJECT, but my attempts to invoke automatic derivation have so far failed....

What do you think?

Here is a link to the library: http://hackage.haskell.org/package/msgpack-0.7.1.5 And here is a link to some examples, none of which would work according to the documentation for the above version:

  1. http://wiki.msgpack.org/display/MSGPACK/QuickStart+for+Haskell
Was it helpful?

Solution

I'm not familiar with msgpack, but at a guess something like this should work.

{-# LANGUAGE TemplateHaskell #-}

import Data.MessagePack.Derive

-- I don't know which of these lines you need
-- I also don't know whether the True should actually be False
$(deriveObject True ''Document)
$(derivePack True ''Document)
$(deriveUnpack True ''Document)

(n.b. In general it's helpful to show us the code you tried that didn't work, instead of leaving us to guess that your attempts probably didn't work because you didn't enable TemplateHaskell or whatever.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top