[Haskell-cafe] handling multiple versions of a data structure

Jeremy Shaw jeremy at n-heptane.com
Mon Dec 20 18:58:27 CET 2010


I'm not sure off-hand.. I think it would involve some hackery. How
long do you want to keep support for the old Show format around? If
you just want to convert some data you have right now, then you could
write some code that uses the old Show based code to read in the old
data and write it out using Serialize in the new  format.

If you want to support Show based migration for a long time -- then
that could be trickier. While serialize does  give you complete
control over how the actual data is converted to a byte stream and
back, it also assumes that there is some other meta-data involved (the
Version stuff). So the problem I see is what happens if you try to
read data from the old format which does not have that meta data..

I think what you would need to do is have your own code which detects
if the saved data is in the Show format or the Serialize format. If it
is in the Serialize format, then you just call the normal
deserialization code.

If it is in the old Show format, then you call your code to read the
old Show format. That will give you data that is in the 'old' type
that was last supported by the Show code. You would then is migrate
function from the Migrate class to migrate it to the latest type.

Does that make sense?

- jeremy

On Sun, Dec 19, 2010 at 10:58 AM, Dmitry V'yal <akamaus at gmail.com> wrote:
> On 17.12.2010 01:09, Jeremy Shaw wrote:
>> Hello,
>> You should use happstack-data for this (you do not need the other
>> happstack components to use happstack-data)*. It was created to solve
>> this exact problem.
>> happstack-data builds on type of the 'binary' library and adds versioned
>> data types and automatic version migration.
> Thanks! Looks like what I need. There is a one problem, though. I don't have
> a time machine. I mean right now I have A primitive format based on Show
> instance and I'd like to maintain the compatibility with it.
> Is it possible to force a particular on-disk format for a particular version
> of data type? I guess I should write a Serialize instance myself. Are there
> any pitfalls awaiting me?
> Best wishes,
> Dmitry

More information about the Haskell-Cafe mailing list