+ -- Generate EarlyDerivSpec's for Representable, if asked for
+ ; (xGenerics, xDeriveRepresentable) <- genericsFlags
+ ; let allTyNames = [ tcdName d | L _ d <- tycl_decls, isDataDecl d ]
+ ; allTyDecls <- mapM tcLookupTyCon allTyNames
+ -- Select only those types that derive Representable
+ ; derTyDecls <- mapM tcLookupTyCon $
+ filter (needsExtras all_tydata deriv_decls
+ xDeriveRepresentable) allTyNames
+ -- We need to generate the extras to add to what has
+ -- already been derived
+ ; generic_extras_deriv <- mapM mkGenDerivExtras derTyDecls
+ -- For the remaining types, if Generics is on, we need to
+ -- generate both the instances and the extras
+ ; let remTyDecls = filter (\x -> not (x `elem` derTyDecls)) allTyDecls
+ ; generic_instances <- if xGenerics
+ then mapM mkGenDerivSpec remTyDecls
+ else return []
+ ; generic_extras_flag <- if xGenerics
+ then mapM mkGenDerivExtras remTyDecls
+ else return []
+ -- Merge and return everything
+ ; return ( eqns1 ++ eqns2 ++ generic_instances
+ , generic_extras_deriv ++ generic_extras_flag) }