acid-state / safecopy

An extension to Data.Serialize with built-in version control
60 stars 37 forks source link

Fully generic implementation of putCopy and getCopy #71

Closed ddssff closed 5 years ago

ddssff commented 5 years ago

Since 2011 there have been default implementations for SafeCopy's putCopy and getCopy, but these just used the serialize operations to create values that could not be migrated and, I suspect, might lead to problems if used for values that themselves contained types with SafeCopy instances. This implementation has been inter-operating well for me with the instances produced by deriveSafeCopy, and in fact I have now removed them all. You can now write

instance SafeCopy AnyGenericInstance where version = 8; kind = extension

The limitations of the implementation are

  1. The version type is pinned to Int32 (oops, Version has always been pinned to Int32)
  2. The values must have Typeable instances

    If anyone can puzzle out either of these issues this issue that would be interesting. Its necessary to keep track of which types you've output version tags for, so I build a Set of TypeRep in the State monad. Is there a GHC.Generic alternative to TypeRep?

The patch adds dependencies on generic-data and transformers. I've bumped the version number to 0.9.5 so the MIN_VERSION_safecopy macro can be used. Fixes issue #2 .