我有一个AST类型,我想导出为Typeable,所以我可以做Scrap-your-boilerplate泛型遍历 .

但是,该树使用漂亮包中的Text.PrettyPrint库的 Doc 类型中的消息进行注释 . 要派生Typeable,需要有一个可输入的 Doc 实例 .

这是我尝试过但失败的原因:

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

给出了这个错误:

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'

或者,我尝试派生自己的实例:

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

这给出了这个错误:

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

难道我做错了什么?是否有一种标准方法可以为其他库中的类型派生类型?

问题是,实例并不是非常重要 . 我知道我的AST中没有任何部分以递归方式存储在Doc值中 . 但GHC抱怨说如果我没有那个例子 .