为Text.PrettyPrint.Doc派生Typeable

时间:2014-12-31 21:43:01

标签: haskell ghc scrap-your-boilerplate ghc-generics

我有一个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抱怨说如果我没有那个例子。

0 个答案:

没有答案
相关问题