exports and (cereal) Serialize instance #8

Closed
ozgurakgun opened this Issue Dec 10, 2012 · 4 comments

Projects

None yet

2 participants

@ozgurakgun

Hi,

For a program I am developing, I need to serialize a data type which contains Doc's in it. I am using cereal, but obviously can't give Doc a Serialize instance because it is an abstract type (i.e. constructors not exported). I am currently using the following instance:

instance Serialize Doc where
    put = put . show
    get = liftM text get

This instance goes through the Serialize instance of String and it clearly looses some information. (Like nesting and optimal width stuff if the Doc is used within another Doc after serialisation/deserialisation.)

One easy solution is exporting the constructors of Doc from a .Internal module. Failing that, what about deriving a GHC.Generics.Generic instance for Doc so I can use generic deriving mechanisms to get the Serialize instance?

Either way, I am happy to prepare a patch. Just let me know if you want one.

Thanks, Ozgur.

@dterei
Haskell member

Hi Ozgur,

This sounds good. I'll try to get to it soon.

@ozgurakgun

Just so that I understand you better, which one sounds good? Adding a GHC.Generics.Generic instance for Doc or the .Internal module approach?

I can create a patch if you tell me which one you prefer. To be honest, I'd do both if I were you :)

@dterei
Haskell member

Basically, I'm waiting on some changes from another guy coming through at this time. So these changes aren't high enough priority for me to want to make a release until those other, larger changes land. I probably prefer only the generic approach for now but I also haven't thought about it at all due to this being on hold in the queue.

@dterei
Haskell member

Closing as added in Generic instances to data types in v1.1.2.0

@dterei dterei closed this Dec 26, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment