I have following datatype:
data My a = Constr a Int String Float VariousComplexTypes ...
I want to be able to call over template (+1) on it to change all Int fields in this data type and down the road. However, I can't request a to be an instance of Data (its constructors are hidden). At the same time, I don't really interested in changing it with over template call, so I tried to write an instance Data (My a) manually, making it ignore first field of type a, but failed. The following code
instance Data (My a) where
gunfold k z _ = k (k (k (z Constr)))
toConstr _ = con
dataTypeOf _ = ty
con = mkConstr ty "Constr" [] Prefix
ty = mkDataType "Mod.My" [con]
produces following error:
• No instance for (Data a) arising from a use of ‘k’
• In the first argument of ‘k’, namely ‘(k (z Constr))’
In the first argument of ‘k’, namely ‘(k (k (z Constr)))’
In the expression: k (k (k (z Constr)))
|
61 | gunfold k z _ = k (k (k (z Constr)))
Is this possible at all? What other options do I have, except writing all the boilerplate by hand?