+ ; let dict_constr = classDataCon clas
+ this_dict_id = instToId this_dict
+ dict_bind = mkVarBind this_dict_id dict_rhs
+ dict_rhs = foldl mk_app inst_constr (sc_ids ++ meth_ids)
+ inst_constr = L loc $ wrapId (mkWpTyApps inst_tys')
+ (dataConWrapId dict_constr)
+ -- We don't produce a binding for the dict_constr; instead we
+ -- rely on the simplifier to unfold this saturated application
+ -- We do this rather than generate an HsCon directly, because
+ -- it means that the special cases (e.g. dictionary with only one
+ -- member) are dealt with by the common MkId.mkDataConWrapId code rather
+ -- than needing to be repeated here.
+
+ mk_app :: LHsExpr Id -> Id -> LHsExpr Id
+ mk_app fun arg_id = L loc (HsApp fun (L loc (wrapId arg_wrapper arg_id)))
+ arg_wrapper = mkWpApps dfun_lam_vars <.> mkWpTyApps (mkTyVarTys inst_tyvars')
+
+ -- Do not inline the dfun; instead give it a magic DFunFunfolding
+ -- See Note [ClassOp/DFun selection]
+ -- See also note [Single-method classes]
+ dfun_id_w_fun = dfun_id
+ `setIdUnfolding` mkDFunUnfolding dict_constr (sc_ids ++ meth_ids)
+ `setInlinePragma` dfunInlinePragma
+
+ main_bind = AbsBinds
+ inst_tyvars'
+ dfun_lam_vars
+ [(inst_tyvars', dfun_id_w_fun, this_dict_id, spec_inst_prags)]
+ (unitBag dict_bind)
+
+ ; showLIE (text "instance")
+ ; return (unitBag (L loc main_bind) `unionBags`
+ listToBag meth_binds `unionBags`
+ listToBag sc_binds)
+ }
+
+{-
+ -- Create the result bindings