- -- NB: Since there is a call to mkCanonicals,
- -- this will add *recursively* all superclasses
- where
- inst_one pred n = newGivOrDerEvVar pred (EvSuperClass ev n)
- flavor = case orig_flavor of
- Given loc -> Given loc
- Wanted loc -> Derived loc DerSC
- Derived {} -> orig_flavor
- -- NB: the non-immediate superclasses will show up as
- -- Derived, and we want their superclasses too!
+
+ | isEmptyVarSet (tyVarsOfTypes xis)
+ = return emptyCCan -- Wanteds with no variables yield no deriveds.
+ -- See Note [Improvement from Ground Wanteds]
+
+ | otherwise -- Wanted case, just add those SC that can lead to improvement.
+ = do { let sc_rec_theta = transSuperClasses cls xis
+ impr_theta = filter is_improvement_pty sc_rec_theta
+ Wanted wloc = orig_flavor
+ ; der_ids <- mapM newDerivedId impr_theta
+ ; mkCanonicals (Derived wloc) der_ids }
+
+
+is_improvement_pty :: PredType -> Bool
+-- Either it's an equality, or has some functional dependency
+is_improvement_pty (EqPred {}) = True
+is_improvement_pty (ClassP cls _ty) = not $ null fundeps
+ where (_,fundeps,_,_,_,_) = classExtraBigSig cls
+is_improvement_pty _ = False
+
+
+