Deriving Typeable for Text.PrettyPrint.Doc

158 Views Asked by At

I have an AST type that I want to derive as Typeable, so that I can do Scrap-your-boilerplate generic traversals of it.

However, the tree is annotated with messages in the Doc type of the Text.PrettyPrint library from the pretty package. To derive Typeable, there needs to be a typeable instance of Doc.

Here's what I've tried and failed:

deriving instance Data P.Doc
deriving instance Typeable P.Doc

gives this error:

Can't make a derived instance of `Data P.Doc':
  The data constructors of `P.Doc' are not all in scope
    so you cannot derive an instance for it
In the stand-alone deriving instance for `Data P.Doc'

Or, I try to derive my own instance:

instance Typeable P.Doc where 
    typeRep v = typeRep $ show v   

which gives this error:

 `typeRep' is not a (visible) method of class `Typeable'      

Am I doing something wrong? Is there a standard way to derive typeable for types given in other libraries?

The thing is, the instance isn't super important. I know that there aren't any parts of my AST stored recursively within a Doc value. But GHC complains if I don't have that instance.

0

There are 0 best solutions below