Regarding SYB,I am a beginner at it
I tried wring a code to get the variables in an expression with the code
variables = removeDuplicate $ (everything (++) ([] `mkQ` f))
where
f (ExprVar st) = [st]
f _ = []
where removeDuplicate
elimates the duplicate variables in the list
ExprVar
is my Datatype
Datatype also includes ExprAdd
, Exprsub
,ExprMul
, ExprDiv
,ExprNum
for addtion,subtraction Multiplication ,division and for a number respectively.
I am getting the following error on compiling :
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 _ = []
Please let me know where am I going wrong?
Thank you