--- During deriving and instance specialisation operations
--- we can't get the instances of the class from inside the
--- class, because the latter ain't ready yet. Instead we
--- find a mapping from classes to envts inside the dict origin.
-
-get_inst_env :: Class -> InstOrigin s -> ClassInstEnv
--- get_inst_env clas (DerivingOrigin inst_mapper _ _)
--- = fst (inst_mapper clas)
-get_inst_env clas (InstanceSpecOrigin inst_mapper _ _)
- = fst (inst_mapper clas)
-get_inst_env clas other_orig = classInstEnv clas
-
-
-pprOrigin :: String -> InstOrigin s -> SrcLoc -> Error
-
-pprOrigin hdr orig locn
- = addErrLoc locn hdr $ \ sty ->
- case orig of
- OccurrenceOf id ->
- ppBesides [ppPStr SLIT("at a use of an overloaded identifier: `"),
- ppr sty id, ppChar '\'']
- OccurrenceOfCon id ->
- ppBesides [ppPStr SLIT("at a use of an overloaded constructor: `"),
- ppr sty id, ppChar '\'']
- InstanceDeclOrigin ->
- ppStr "in an instance declaration"
- LiteralOrigin lit ->
- ppCat [ppStr "at an overloaded literal:", ppr sty lit]
- ArithSeqOrigin seq ->
- ppCat [ppStr "at an arithmetic sequence:", ppr sty seq]
- SignatureOrigin ->
- ppStr "in a type signature"
- DoOrigin ->
- ppStr "in a do statement"
- ClassDeclOrigin ->
- ppStr "in a class declaration"
- InstanceSpecOrigin _ clas ty ->
- ppBesides [ppStr "in a SPECIALIZE instance pragma; class \"",
- ppr sty clas, ppStr "\" type: ", ppr sty ty]
- ValSpecOrigin name ->
- ppBesides [ppStr "in a SPECIALIZE user-pragma for `",
- ppr sty name, ppStr "'"]
- CCallOrigin clabel Nothing{-ccall result-} ->
- ppBesides [ppStr "in the result of the _ccall_ to `",
- ppStr clabel, ppStr "'"]
- CCallOrigin clabel (Just arg_expr) ->
- ppBesides [ppStr "in an argument in the _ccall_ to `",
- ppStr clabel, ppStr "', namely: ", ppr sty arg_expr]
- LitLitOrigin s ->
- ppBesides [ppStr "in this ``literal-literal'': ", ppStr s]
- UnknownOrigin ->
- ppStr "in... oops -- I don't know where the overloading came from!"
+lookupSimpleInst :: Class
+ -> [Type] -- Look up (c,t)
+ -> NF_TcM (Maybe ThetaType) -- Here are the needed (c,t)s
+
+lookupSimpleInst clas tys
+ = tcGetInstEnv `thenNF_Tc` \ inst_env ->
+ case lookupInstEnv inst_env clas tys of
+ FoundInst tenv dfun
+ -> returnNF_Tc (Just (substTheta (mkSubst emptyInScopeSet tenv) theta))
+ where
+ (_, rho) = tcSplitForAllTys (idType dfun)
+ (theta,_) = tcSplitRhoTy rho
+
+ other -> returnNF_Tc Nothing