data MyData a b = MyData a b b
Why is the first instantiation good and the second not ?
instance Foldable (MyData a) where
foldMap f (MyData x y z) = f y <> f z
instance Foldable (MyData a) where
foldMap f (MyData x y z) = f z
f maps both y and z into a monoid, so f z and f y <> f z are instances of that monoid. So, why is the second not ok ?
Your instance is alright as it does not violate any of the Foldable laws, as long as you keep it consequent. It is just odd that
MyDataholds two components of typeb, one of which is not considered in folds.