haskell / pretty

Haskell Pretty-printer library
Other
69 stars 30 forks source link

exports and (cereal) Serialize instance #8

Closed ozgurakgun closed 9 years ago

ozgurakgun commented 11 years ago

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 commented 11 years ago

Hi Ozgur,

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

ozgurakgun commented 11 years ago

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 commented 11 years ago

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 commented 9 years ago

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