streamly
streamly copied to clipboard
Serialization template haskell helpers should handle constructor order and name change
We should have another config option that can define the order of constructors so the tag for the constructor is stable.
For example, say we have a datatype:
data List a
= Nil
| Cons a (List a)
Say the datatype is updated in a later version to,
data List a
= Cons a (List a)
| Nil
The tag given to Cons and Nil will differ. The upgrade process will become rather complex because of this.
We should have another config option named constructorOrder to define the order of constructors manually.
$(deriveSerializeWith
(defaultConfig { constructorOrder = [''Nil, ''Cons] })
[d|instance Serialize a => Serialize (List a)|])
This can also possibly be solved by constructorTagAsString if the names of the constructors don't change.
constructorOrder is more powerful as it also handles any constructor name changes and is more performant than the former.
Practical use-case:
bytestring-0.10:
data ByteString = Empty | Chunk_ Strict.Bytestring
bytestring-0.12
data ByteString = Empty | Chunk Strict.Bytestring
Pushing this to 0.12.0. This is a nice feature to have but we can think about it later.