2010/1/26 José Pedro Magalhães <j...@cs.uu.nl>

> Hi Jeremy,
>
> As Neil Mitchell said before, if you really don't want to expose the
> internals of Text (by just using a derived instance) then you have no other
> alternative than to use String conversion. If you've been using it already
> and performance is not a big problem, then I guess it's ok.
>
> Regarding the Serialize issue, maybe I am not understanding the problem
> correctly: isn't that just another generic function? There are generic
> implementations of binary get and put for at least two generic programming
> libraries in Hackage [1, 2], and writing one for SYB shouldn't be hard
> either, I think. Then you could have a trivial way of generating instances
> of Serialize, namely something like
>
>> instance Serialize MyType where
>>   getCopy = gget
>>   putCopy = gput
>
>
But in what package does, instance Serialize Text, live? text?
happstack-data? a new package, serialize-text? That is the question at hand.
Each of those choices has rather annoying complications.

As for using generics, Serialization can not be 100% generic, because we
also support migration when the type changes. For example, right now
ClockTime is defined:

data ClockTime = TOD Integer Integer

Let's say that it is later changed to:

data ClockTime = TOD Bool Integer Integer

Attempting to read the old data you saved would now fail, because the saved
data does not have the 'Bool' value. However, perhaps the old data can be
migrated by simply setting the Bool to True or False by default. In
happstack we would have:

$(deriveSerialize ''Old.ClockTime)
instance Version Old.ClockTime

$(deriveSerialize ''ClockTime)
instance Version ClockTime where
   mode = extension 1 (Proxy :: Proxy Old.ClockTime)

instance Migrate Old.ClockTime ClockTime where
   migrate (Old.TOD i j) = TOD False i j

The Version class is a super class of the Serialize class, which is required
so that when the deserializer is trying to deserialize ClockTime, and runs
across an older version of the data type, it knows how to find the older
deserialization function that works with that version of the type, and where
to find the migrate function to bring it up to the latest version.

- jeremy
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to