+tcInstClassOp :: InstLoc -> Id -> [TcType] -> TcM Inst
+ -- Instantiate the specified class op, but *only* with the main
+ -- class dictionary. For example, given 'op' defined thus:
+ -- class Foo a where
+ -- op :: (?x :: String) => a -> a
+ -- (tcInstClassOp op T) should return an Inst with type
+ -- (?x :: String) => T -> T
+ -- That is, the class-op's context is still there.
+ -- This is really important in the use of tcInstClassOp in TcClassDcls.mkMethodBind
+tcInstClassOp inst_loc sel_id tys
+ = let
+ (tyvars,rho) = tcSplitForAllTys (idType sel_id)
+ rho_ty = ASSERT( equalLength tyvars tys )
+ substTy (mkTopTyVarSubst tyvars tys) rho
+ Just (pred_ty,tau) = tcSplitFunTy_maybe rho_ty
+ Just pred = tcSplitPredTy_maybe pred_ty
+ -- Split off exactly one predicate (see the example above)
+ in
+ ASSERT( isClassPred pred )
+ newMethodWith inst_loc sel_id tys [pred] tau
+