-
- returnTc (const_lie `plusLIE` spec_lie, inst_binds)
-\end{code}
-
-@mkMethodId@ manufactures an id for a local method.
-It's rather turgid stuff, because there are two cases:
-
- (a) For methods with no local polymorphism, we can make an Inst of the
- class-op selector function and a corresp InstId;
- which is good because then other methods which call
- this one will do so directly.
-
- (b) For methods with local polymorphism, we can't do this. For example,
-
- class Foo a where
- op :: (Num b) => a -> b -> a
-
- Here the type of the class-op-selector is
-
- forall a b. (Foo a, Num b) => a -> b -> a
-
- The locally defined method at (say) type Float will have type
-
- forall b. (Num b) => Float -> b -> Float
-
- and the one is not an instance of the other.
-
- So for these we just make a local (non-Inst) id with a suitable type.
-
-How disgusting.
-
-\begin{code}
-newMethodId sel_id inst_ty origin loc
- = let (sel_tyvars,sel_theta,sel_tau) = splitSigmaTy (idType sel_id)
- (_:meth_theta) = sel_theta -- The local theta is all except the
- -- first element of the context
- in
- case sel_tyvars of
- -- Ah! a selector for a class op with no local polymorphism
- -- Build an Inst for this
- [clas_tyvar] -> newMethod origin (RealId sel_id) [inst_ty]
-
- -- Ho! a selector for a class op with local polymorphism.
- -- Just make a suitably typed local id for this
- (clas_tyvar:local_tyvars) ->
- tcInstType [(clas_tyvar,inst_ty)]
- (mkSigmaTy local_tyvars meth_theta sel_tau)
- `thenNF_Tc` \ method_ty ->
- newLocalId (getLocalName sel_id) method_ty `thenNF_Tc` \ meth_id ->
- returnNF_Tc (emptyLIE, meth_id)
-\end{code}
-
-The next function makes a default method which calls the global default method, at
-the appropriate instance type.
-
-See the notes under default decls in TcClassDcl.lhs.
-
-\begin{code}
-makeInstanceDeclDefaultMethodExpr
- :: InstOrigin s
- -> [TcIdOcc s]
- -> [Id]
- -> TcType s
- -> TcIdOcc s
- -> Int
- -> NF_TcM s (TcExpr s)
-
-makeInstanceDeclDefaultMethodExpr origin meth_ids defm_ids inst_ty this_dict tag
- = newDicts origin op_theta `thenNF_Tc` \ (op_lie,op_dicts) ->
-
- -- def_op_id = /\ op_tyvars -> \ op_dicts ->
- -- defm_id inst_ty op_tyvars this_dict op_dicts
- returnNF_Tc (
- mkHsTyLam op_tyvars (
- mkHsDictLam op_dicts (
- mkHsDictApp (mkHsTyApp (HsVar (RealId defm_id))
- (inst_ty : mkTyVarTys op_tyvars))
- (this_dict : op_dicts)
- )))
- where
- idx = tag - 1
- meth_id = meth_ids !! idx
- defm_id = defm_ids !! idx
- (op_tyvars, op_theta, op_tau) = splitSigmaTy (tcIdType meth_id)
-
-makeInstanceDeclNoDefaultExpr
- :: InstOrigin s
- -> [TcIdOcc s]
- -> [Id]
- -> TcType s
- -> Class
- -> Maybe Module
- -> Int
- -> NF_TcM s (TcExpr s)
-
-makeInstanceDeclNoDefaultExpr origin meth_ids defm_ids inst_ty clas inst_mod tag
- = newDicts origin op_theta `thenNF_Tc` \ (op_lie, op_dicts) ->
-
- -- Produce a warning if the default instance method
- -- has been omitted when one exists in the class
- warnTc (not err_defm_ok)
- (omitDefaultMethodWarn clas_op clas_name inst_ty)
- `thenNF_Tc_`
- returnNF_Tc (mkHsTyLam op_tyvars (
- mkHsDictLam op_dicts (
- HsApp (mkHsTyApp (HsVar (RealId pAT_ERROR_ID)) [op_tau])
- (HsLitOut (HsString (_PK_ error_msg)) stringTy))))
- where
- idx = tag - 1
- meth_id = meth_ids !! idx
- clas_op = (getClassOps clas) !! idx
- defm_id = defm_ids !! idx
- (op_tyvars,op_theta,op_tau) = splitSigmaTy (tcIdType meth_id)
-
- Just (_, _, err_defm_ok) = isDefaultMethodId_maybe defm_id
-
- error_msg = "%E" -- => No explicit method for \"
- ++ escErrorMsg error_str
-
- mod_str = case inst_mod of { Nothing -> pRELUDE; Just m -> m }
-
- error_str = _UNPK_ mod_str ++ "." ++ _UNPK_ clas_name ++ "."
- ++ (ppShow 80 (ppr PprForUser inst_ty)) ++ "."
- ++ (ppShow 80 (ppr PprForUser clas_op)) ++ "\""
-
- clas_name = nameOf (origName clas)