Hello i want to know is there any way having a type that implements a typeclass to put a constraint on a field without decomposing all the type?(or simply put without enumerating all its other fields in the instance declaration? )
Example:
data A=A | BB | CCC deriving( Show)
class T a where
mymethod::a->Bool
instance T A where
mymethod a = length . show $ a >1
data Complex b = Complex{
a::Int,
b::A,
c::String
}
instance (T b) => T (Complex a b c)
Looking above in the last line, is there any way to enumerate just the fields that we want to put constraints on? (in our case b which implements T typeclass).
Can we put wildcards or any other thing to not put all fields?
E.g:instance (T b) => T (Complex _ b _)
or even better
instance (T b) => T Complex {b ? }
a. The number of parameters of the data constructor is three, but of the type constructor (instances work on that meta-level), there is one parameter. - Willem Van Onsemahas no use here, since you never specify a field with a type that is defined in terms ofa. - Willem Van OnsemComplexthat implements theTtypeclass isb. - Bercovici Adrianbparameter has typeAwhich is a real type, nota... - Willem Van Onsem