关于SYB,我是初学者
我尝试编写代码以使用代码获取表达式中的变量
variables = removeDuplicate $ (everything (++) ([] `mkQ` f))
where
f (ExprVar st) = [st]
f _ = []
whereremoveDuplicate
消除列表中的重复变量
ExprVar
是我的数据类型 数据类型还包括ExprAdd
, Exprsub
, ExprMul
, ExprDiv
,ExprNum
分别表示加法、减法乘法、除法和数字。
我在编译时收到以下错误:
No instance for (Data a0) arising from a use of `everything'
The type variable `a0' is ambiguous
Possible cause: the monomorphism restriction applied to the following:
variables :: a0 -> [[Char]] (bound at ParserExpr.hs:107:1)
Probable fix: give these definition(s) an explicit type signature
or use -XNoMonomorphismRestriction
Note: there are several potential instances:
instance Data Expr -- Defined at ParserExpr.hs:24:28
instance (Data a, Data b) => Data (a -> b)
-- Defined in `Data.Generics.Instances'
instance Data DataType -- Defined in `Data.Generics.Instances'
...plus 43 others
In the expression: (everything (++) ([] `mkQ` f))
In an equation for `variables':
variables
= (everything (++) ([] `mkQ` f))
where
f (ExprVar st) = [st]
f _ = []
请让我知道我哪里出错了?
谢谢