- ; rhs <- case dict_component_tys of
- [rep_ty] -> mkNewTyConRhs tycon_name rec_tycon dict_con
- other -> return (mkDataTyConRhs [dict_con])
+ ; sc_sel_names <- mapM (newImplicitBinder class_name . mkSuperDictSelOcc)
+ [1..length (dataConDictTheta dict_con)]
+ -- We number off the Dict superclass selectors, 1, 2, 3 etc so that we
+ -- can construct names for the selectors. Thus
+ -- class (C a, C b) => D a b where ...
+ -- gives superclass selectors
+ -- D_sc1, D_sc2
+ -- (We used to call them D_C, but now we can have two different
+ -- superclasses both called C!)
+ ; let sc_sel_ids = [mkDictSelId sc_name rec_clas | sc_name <- sc_sel_names]
+
+ -- Use a newtype if the class constructor has exactly one field:
+ -- i.e. exactly one operation or superclass taken together
+ -- Watch out: the sc_theta includes equality predicates,
+ -- which don't count for this purpose; hence dataConDictTheta
+ ; rhs <- if ((length $ dataConDictTheta dict_con) + length sig_stuff) == 1
+ then mkNewTyConRhs tycon_name rec_tycon dict_con
+ else return (mkDataTyConRhs [dict_con])