Yeah, it's the unusual "why does this work" question. I have this piece of code:
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE UndecidableInstances #-}
data F a = A (F a) | B (a (F a)) -- a :: * -> *
deriving instance (forall b. Eq b => Eq (a b)) => Eq (F a)
-- the following errors, asking me to add (Eq b) into the context
deriving instance (forall b. Eq (a b)) => Eq (F a)
The second version errors out if one define
data T a = C | D a deriving Eq
x = B C == B C
From a logical aspect, adding (Eq b) to the constraints should be something like (forall b. Eq b && Eq (a b)) => Eq (F a), because we need to keep it in the scope of forall. It is conceivable that (Eq b) is assumed implicitly, as most deriving instances do. But if so, why doesn't the second version work?