2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4 \section[Inst]{The @Inst@ type: dictionaries or method instances}
8 LIE, emptyLIE, unitLIE, plusLIE, consLIE, zonkLIE,
9 plusLIEs, mkLIE, isEmptyLIE, lieToList, listToLIE,
12 pprInst, pprInsts, pprInstsInFull, tidyInst, tidyInsts,
14 newDictsFromOld, newDicts, newClassDicts,
15 newMethod, newMethodWithGivenTy, newOverloadedLit,
18 tyVarsOfInst, tyVarsOfInsts, tyVarsOfLIE, instLoc, getDictClassTys,
22 lookupInst, lookupSimpleInst, LookupInstResult(..),
24 isDict, isClassDict, isMethod, instMentionsIPs,
25 isTyVarDict, isStdClassTyVarDict, isMethodFor,
26 instBindingRequired, instCanBeGeneralised,
31 InstOrigin(..), InstLoc, pprInstLoc
34 #include "HsVersions.h"
36 import CmdLineOpts ( opt_NoMethodSharing )
37 import HsSyn ( HsLit(..), HsOverLit(..), HsExpr(..) )
38 import RnHsSyn ( RenamedHsOverLit )
39 import TcHsSyn ( TcExpr, TcId,
40 mkHsTyApp, mkHsDictApp, mkHsConApp, zonkId
43 import TcEnv ( TcIdSet, tcGetInstEnv, tcLookupGlobalId )
44 import InstEnv ( InstLookupResult(..), lookupInstEnv )
45 import TcType ( TcThetaType, TcClassContext,
46 TcType, TcTauType, TcTyVarSet,
47 zonkTcType, zonkTcTypes,
48 zonkTcThetaType, tcInstTyVar, tcInstType
50 import CoreFVs ( idFreeTyVars )
51 import Class ( Class )
52 import Id ( Id, idType, mkUserLocal, mkSysLocal, mkVanillaId )
53 import PrelInfo ( isStandardClass, isCcallishClass, isNoDictClass )
54 import Name ( mkDictOcc, mkMethodOcc, getOccName, mkLocalName )
55 import NameSet ( NameSet )
56 import PprType ( pprPred )
57 import Type ( Type, PredType(..),
58 isTyVarTy, mkPredTy, mkTyVarTy, mkTyVarTys,
59 splitForAllTys, splitSigmaTy, funArgTy,
60 splitMethodTy, splitRhoTy, classesOfPreds,
61 tyVarsOfType, tyVarsOfTypes, tyVarsOfPred,
62 tidyOpenType, tidyOpenTypes, predMentionsIPs
64 import Subst ( emptyInScopeSet, mkSubst,
65 substTy, substClasses, mkTyVarSubst, mkTopTyVarSubst
67 import Literal ( inIntRange )
68 import VarEnv ( TidyEnv, lookupSubstEnv, SubstResult(..) )
69 import VarSet ( elemVarSet, emptyVarSet, unionVarSet )
70 import TysWiredIn ( isIntTy,
71 floatDataCon, isFloatTy,
72 doubleDataCon, isDoubleTy,
75 import PrelNames( hasKey, fromIntName, fromIntegerClassOpKey )
76 import Util ( thenCmp, zipWithEqual, mapAccumL )
81 %************************************************************************
83 \subsection[Inst-collections]{LIE: a collection of Insts}
85 %************************************************************************
90 isEmptyLIE = isEmptyBag
92 unitLIE inst = unitBag inst
93 mkLIE insts = listToBag insts
94 plusLIE lie1 lie2 = lie1 `unionBags` lie2
95 consLIE inst lie = inst `consBag` lie
96 plusLIEs lies = unionManyBags lies
100 zonkLIE :: LIE -> NF_TcM LIE
101 zonkLIE lie = mapBagNF_Tc zonkInst lie
103 pprInsts :: [Inst] -> SDoc
104 pprInsts insts = parens (sep (punctuate comma (map pprInst insts)))
108 = vcat (map go insts)
110 go inst = quotes (ppr inst) <+> pprInstLoc (instLoc inst)
113 %************************************************************************
115 \subsection[Inst-types]{@Inst@ types}
117 %************************************************************************
119 An @Inst@ is either a dictionary, an instance of an overloaded
120 literal, or an instance of an overloaded value. We call the latter a
121 ``method'' even though it may not correspond to a class operation.
122 For example, we might have an instance of the @double@ function at
123 type Int, represented by
125 Method 34 doubleId [Int] origin
137 TcId -- The overloaded function
138 -- This function will be a global, local, or ClassOpId;
139 -- inside instance decls (only) it can also be an InstId!
140 -- The id needn't be completely polymorphic.
141 -- You'll probably find its name (for documentation purposes)
142 -- inside the InstOrigin
144 [TcType] -- The types to which its polymorphic tyvars
145 -- should be instantiated.
146 -- These types must saturate the Id's foralls.
148 TcThetaType -- The (types of the) dictionaries to which the function
149 -- must be applied to get the method
151 TcTauType -- The type of the method
155 -- INVARIANT: in (Method u f tys theta tau loc)
156 -- type of (f tys dicts(from theta)) = tau
160 RenamedHsOverLit -- The literal from the occurrence site
161 TcType -- The type at which the literal is used
167 @Insts@ are ordered by their class/type info, rather than by their
168 unique. This allows the context-reduction mechanism to use standard finite
169 maps to do their stuff.
172 instance Ord Inst where
175 instance Eq Inst where
176 (==) i1 i2 = case i1 `cmpInst` i2 of
180 cmpInst (Dict _ pred1 _) (Dict _ pred2 _) = (pred1 `compare` pred2)
181 cmpInst (Dict _ _ _) other = LT
183 cmpInst (Method _ _ _ _ _ _) (Dict _ _ _) = GT
184 cmpInst (Method _ id1 tys1 _ _ _) (Method _ id2 tys2 _ _ _) = (id1 `compare` id2) `thenCmp` (tys1 `compare` tys2)
185 cmpInst (Method _ _ _ _ _ _) other = LT
187 cmpInst (LitInst _ lit1 ty1 _) (LitInst _ lit2 ty2 _) = (lit1 `compare` lit2) `thenCmp` (ty1 `compare` ty2)
188 cmpInst (LitInst _ _ _ _) other = GT
190 -- and they can only have HsInt or HsFracs in them.
197 instToId :: Inst -> TcId
198 instToId (Dict id _ _) = id
199 instToId (Method id _ _ _ _ _) = id
200 instToId (LitInst id _ _ _) = id
202 instLoc (Dict _ _ loc) = loc
203 instLoc (Method _ _ _ _ _ loc) = loc
204 instLoc (LitInst _ _ _ loc) = loc
206 getDictClassTys (Dict _ (Class clas tys) _) = (clas, tys)
208 predsOfInsts :: [Inst] -> [PredType]
209 predsOfInsts insts = concatMap predsOfInst insts
211 predsOfInst (Dict _ pred _) = [pred]
212 predsOfInst (Method _ _ _ theta _ _) = theta
213 predsOfInst (LitInst _ _ _ _) = []
214 -- The last case is is really a big cheat
215 -- LitInsts to give rise to a (Num a) or (Fractional a) predicate
216 -- But Num and Fractional have only one parameter and no functional
217 -- dependencies, so I think no caller of predsOfInst will care.
219 ipsOfPreds theta = [(n,ty) | IParam n ty <- theta]
221 getIPs inst = ipsOfPreds (predsOfInst inst)
223 tyVarsOfInst :: Inst -> TcTyVarSet
224 tyVarsOfInst (LitInst _ _ ty _) = tyVarsOfType ty
225 tyVarsOfInst (Dict _ pred _) = tyVarsOfPred pred
226 tyVarsOfInst (Method _ id tys _ _ _) = tyVarsOfTypes tys `unionVarSet` idFreeTyVars id
227 -- The id might have free type variables; in the case of
228 -- locally-overloaded class methods, for example
230 tyVarsOfInsts insts = foldr (unionVarSet . tyVarsOfInst) emptyVarSet insts
231 tyVarsOfLIE lie = tyVarsOfInsts (lieToList lie)
237 isDict :: Inst -> Bool
238 isDict (Dict _ _ _) = True
241 isClassDict :: Inst -> Bool
242 isClassDict (Dict _ (Class _ _) _) = True
243 isClassDict other = False
245 isMethod :: Inst -> Bool
246 isMethod (Method _ _ _ _ _ _) = True
247 isMethod other = False
249 isMethodFor :: TcIdSet -> Inst -> Bool
250 isMethodFor ids (Method uniq id tys _ _ loc) = id `elemVarSet` ids
251 isMethodFor ids inst = False
253 instMentionsIPs :: Inst -> NameSet -> Bool
254 -- True if the Inst mentions any of the implicit
255 -- parameters in the supplied set of names
256 instMentionsIPs (Dict _ pred _) ip_names = pred `predMentionsIPs` ip_names
257 instMentionsIPs (Method _ _ _ theta _ _) ip_names = any (`predMentionsIPs` ip_names) theta
258 instMentionsIPs other ip_names = False
260 isTyVarDict :: Inst -> Bool
261 isTyVarDict (Dict _ (Class _ tys) _) = all isTyVarTy tys
262 isTyVarDict other = False
264 isStdClassTyVarDict (Dict _ (Class clas [ty]) _)
265 = isStandardClass clas && isTyVarTy ty
266 isStdClassTyVarDict other
270 Two predicates which deal with the case where class constraints don't
271 necessarily result in bindings. The first tells whether an @Inst@
272 must be witnessed by an actual binding; the second tells whether an
273 @Inst@ can be generalised over.
276 instBindingRequired :: Inst -> Bool
277 instBindingRequired (Dict _ (Class clas _) _) = not (isNoDictClass clas)
278 instBindingRequired (Dict _ (IParam _ _) _) = False
279 instBindingRequired other = True
281 instCanBeGeneralised :: Inst -> Bool
282 instCanBeGeneralised (Dict _ (Class clas _) _) = not (isCcallishClass clas)
283 instCanBeGeneralised other = True
287 %************************************************************************
289 \subsection{Building dictionaries}
291 %************************************************************************
294 newDicts :: InstOrigin
298 = tcGetInstLoc orig `thenNF_Tc` \ loc ->
299 newDictsAtLoc loc theta
301 newClassDicts :: InstOrigin
304 newClassDicts orig theta = newDicts orig (map (uncurry Class) theta)
306 newDictsFromOld :: Inst -> TcClassContext -> NF_TcM [Inst]
307 newDictsFromOld (Dict _ _ loc) theta = newDictsAtLoc loc (map (uncurry Class) theta)
309 -- Local function, similar to newDicts,
310 -- but with slightly different interface
311 newDictsAtLoc :: InstLoc
314 newDictsAtLoc inst_loc@(_,loc,_) theta
315 = tcGetUniques (length theta) `thenNF_Tc` \ new_uniqs ->
316 returnNF_Tc (zipWithEqual "newDictsAtLoc" mk_dict new_uniqs theta)
318 mk_dict uniq pred = Dict (mkVanillaId (mk_dict_name uniq pred) (mkPredTy pred)) pred inst_loc
320 mk_dict_name uniq (Class cls tys) = mkLocalName uniq (mkDictOcc (getOccName cls)) loc
321 mk_dict_name uniq (IParam name ty) = name
323 newIPDict orig name ty
324 = tcGetInstLoc orig `thenNF_Tc` \ inst_loc ->
325 returnNF_Tc (Dict (mkVanillaId name ty) (IParam name ty) inst_loc)
329 %************************************************************************
331 \subsection{Building methods (calls of overloaded functions)}
333 %************************************************************************
335 tcInstId instantiates an occurrence of an Id.
336 The instantiate_it loop runs round instantiating the Id.
337 It has to be a loop because we are now prepared to entertain
339 f:: forall a. Eq a => forall b. Baz b => tau
340 We want to instantiate this to
341 f2::tau {f2 = f1 b (Baz b), f1 = f a (Eq a)}
343 The -fno-method-sharing flag controls what happens so far as the LIE
344 is concerned. The default case is that for an overloaded function we
345 generate a "method" Id, and add the Method Inst to the LIE. So you get
348 f = /\a (d:Num a) -> let m = (+) a d in \ (x:a) -> m x x
349 If you specify -fno-method-sharing, the dictionary application
350 isn't shared, so we get
352 f = /\a (d:Num a) (x:a) -> (+) a d x x
353 This gets a bit less sharing, but
354 a) it's better for RULEs involving overloaded functions
355 b) perhaps fewer separated lambdas
359 tcInstId :: Id -> NF_TcM (TcExpr, LIE, TcType)
361 | opt_NoMethodSharing = loop_noshare (HsVar fun) (idType fun)
362 | otherwise = loop_share fun
364 orig = OccurrenceOf fun
365 loop_noshare fun fun_ty
366 = tcInstType fun_ty `thenNF_Tc` \ (tyvars, theta, tau) ->
368 ty_app = mkHsTyApp fun (mkTyVarTys tyvars)
370 if null theta then -- Is it overloaded?
371 returnNF_Tc (ty_app, emptyLIE, tau)
373 newDicts orig theta `thenNF_Tc` \ dicts ->
374 loop_noshare (mkHsDictApp ty_app (map instToId dicts)) tau `thenNF_Tc` \ (expr, lie, final_tau) ->
375 returnNF_Tc (expr, mkLIE dicts `plusLIE` lie, final_tau)
378 = tcInstType (idType fun) `thenNF_Tc` \ (tyvars, theta, tau) ->
380 arg_tys = mkTyVarTys tyvars
382 if null theta then -- Is it overloaded?
383 returnNF_Tc (mkHsTyApp (HsVar fun) arg_tys, emptyLIE, tau)
385 -- Yes, it's overloaded
386 newMethodWithGivenTy orig fun arg_tys theta tau `thenNF_Tc` \ meth ->
387 loop_share (instToId meth) `thenNF_Tc` \ (expr, lie, final_tau) ->
388 returnNF_Tc (expr, unitLIE meth `plusLIE` lie, final_tau)
391 newMethod :: InstOrigin
395 newMethod orig id tys
396 = -- Get the Id type and instantiate it at the specified types
398 (tyvars, rho) = splitForAllTys (idType id)
399 rho_ty = substTy (mkTyVarSubst tyvars tys) rho
400 (pred, tau) = splitMethodTy rho_ty
402 newMethodWithGivenTy orig id tys [pred] tau
404 newMethodWithGivenTy orig id tys theta tau
405 = tcGetInstLoc orig `thenNF_Tc` \ loc ->
406 newMethodWith loc id tys theta tau
408 newMethodWith inst_loc@(_,loc,_) id tys theta tau
409 = tcGetUnique `thenNF_Tc` \ new_uniq ->
411 meth_id = mkUserLocal (mkMethodOcc (getOccName id)) new_uniq tau loc
413 returnNF_Tc (Method meth_id id tys theta tau inst_loc)
415 newMethodAtLoc :: InstLoc
417 -> NF_TcM (Inst, TcId)
418 newMethodAtLoc inst_loc real_id tys
419 -- This actually builds the Inst
420 = -- Get the Id type and instantiate it at the specified types
422 (tyvars,rho) = splitForAllTys (idType real_id)
423 rho_ty = ASSERT( length tyvars == length tys )
424 substTy (mkTopTyVarSubst tyvars tys) rho
425 (theta, tau) = splitRhoTy rho_ty
427 newMethodWith inst_loc real_id tys theta tau `thenNF_Tc` \ meth_inst ->
428 returnNF_Tc (meth_inst, instToId meth_inst)
431 In newOverloadedLit we convert directly to an Int or Integer if we
432 know that's what we want. This may save some time, by not
433 temporarily generating overloaded literals, but it won't catch all
434 cases (the rest are caught in lookupInst).
437 newOverloadedLit :: InstOrigin
440 -> NF_TcM (TcExpr, LIE)
441 newOverloadedLit orig (HsIntegral i _) ty
442 | isIntTy ty && inIntRange i -- Short cut for Int
443 = returnNF_Tc (int_lit, emptyLIE)
445 | isIntegerTy ty -- Short cut for Integer
446 = returnNF_Tc (integer_lit, emptyLIE)
449 int_lit = HsLit (HsInt i)
450 integer_lit = HsLit (HsInteger i)
452 newOverloadedLit orig lit ty -- The general case
453 = tcGetInstLoc orig `thenNF_Tc` \ loc ->
454 tcGetUnique `thenNF_Tc` \ new_uniq ->
456 lit_inst = LitInst lit_id lit ty loc
457 lit_id = mkSysLocal SLIT("lit") new_uniq ty
459 returnNF_Tc (HsVar (instToId lit_inst), unitLIE lit_inst)
463 %************************************************************************
467 %************************************************************************
469 Zonking makes sure that the instance types are fully zonked,
470 but doesn't do the same for any of the Ids in an Inst. There's no
471 need, and it's a lot of extra work.
474 zonkPred :: TcPredType -> NF_TcM TcPredType
475 zonkPred (Class clas tys)
476 = zonkTcTypes tys `thenNF_Tc` \ new_tys ->
477 returnNF_Tc (Class clas new_tys)
478 zonkPred (IParam n ty)
479 = zonkTcType ty `thenNF_Tc` \ new_ty ->
480 returnNF_Tc (IParam n new_ty)
482 zonkInst :: Inst -> NF_TcM Inst
483 zonkInst (Dict id pred loc)
484 = zonkPred pred `thenNF_Tc` \ new_pred ->
485 returnNF_Tc (Dict id new_pred loc)
487 zonkInst (Method m id tys theta tau loc)
488 = zonkId id `thenNF_Tc` \ new_id ->
489 -- Essential to zonk the id in case it's a local variable
490 -- Can't use zonkIdOcc because the id might itself be
491 -- an InstId, in which case it won't be in scope
493 zonkTcTypes tys `thenNF_Tc` \ new_tys ->
494 zonkTcThetaType theta `thenNF_Tc` \ new_theta ->
495 zonkTcType tau `thenNF_Tc` \ new_tau ->
496 returnNF_Tc (Method m new_id new_tys new_theta new_tau loc)
498 zonkInst (LitInst id lit ty loc)
499 = zonkTcType ty `thenNF_Tc` \ new_ty ->
500 returnNF_Tc (LitInst id lit new_ty loc)
502 zonkInsts insts = mapNF_Tc zonkInst insts
506 %************************************************************************
508 \subsection{Printing}
510 %************************************************************************
512 ToDo: improve these pretty-printing things. The ``origin'' is really only
513 relevant in error messages.
516 instance Outputable Inst where
517 ppr inst = pprInst inst
519 pprInst (LitInst u lit ty loc)
520 = hsep [ppr lit, ptext SLIT("at"), ppr ty, show_uniq u]
522 pprInst (Dict u pred loc) = pprPred pred <+> show_uniq u
524 pprInst m@(Method u id tys theta tau loc)
525 = hsep [ppr id, ptext SLIT("at"),
526 brackets (interppSP tys) {- ,
527 ptext SLIT("theta"), ppr theta,
528 ptext SLIT("tau"), ppr tau
532 tidyPred :: TidyEnv -> TcPredType -> (TidyEnv, TcPredType)
533 tidyPred env (Class clas tys)
534 = (env', Class clas tys')
536 (env', tys') = tidyOpenTypes env tys
537 tidyPred env (IParam n ty)
538 = (env', IParam n ty')
540 (env', ty') = tidyOpenType env ty
542 tidyInst :: TidyEnv -> Inst -> (TidyEnv, Inst)
543 tidyInst env (LitInst u lit ty loc)
544 = (env', LitInst u lit ty' loc)
546 (env', ty') = tidyOpenType env ty
548 tidyInst env (Dict u pred loc)
549 = (env', Dict u pred' loc)
551 (env', pred') = tidyPred env pred
553 tidyInst env (Method u id tys theta tau loc)
554 = (env', Method u id tys' theta tau loc)
555 -- Leave theta, tau alone cos we don't print them
557 (env', tys') = tidyOpenTypes env tys
559 tidyInsts env insts = mapAccumL tidyInst env insts
561 show_uniq u = ifPprDebug (text "{-" <> ppr u <> text "-}")
565 %************************************************************************
567 \subsection{Looking up Insts}
569 %************************************************************************
572 data LookupInstResult s
574 | SimpleInst TcExpr -- Just a variable, type application, or literal
575 | GenInst [Inst] TcExpr -- The expression and its needed insts
578 -> NF_TcM (LookupInstResult s)
582 lookupInst dict@(Dict _ (Class clas tys) loc)
583 = tcGetInstEnv `thenNF_Tc` \ inst_env ->
584 case lookupInstEnv inst_env clas tys of
586 FoundInst tenv dfun_id
588 (tyvars, rho) = splitForAllTys (idType dfun_id)
589 mk_ty_arg tv = case lookupSubstEnv tenv tv of
590 Just (DoneTy ty) -> returnNF_Tc ty
591 Nothing -> tcInstTyVar tv `thenNF_Tc` \ tc_tv ->
592 returnTc (mkTyVarTy tc_tv)
594 mapNF_Tc mk_ty_arg tyvars `thenNF_Tc` \ ty_args ->
596 subst = mkTyVarSubst tyvars ty_args
597 dfun_rho = substTy subst rho
598 (theta, _) = splitRhoTy dfun_rho
599 ty_app = mkHsTyApp (HsVar dfun_id) ty_args
602 returnNF_Tc (SimpleInst ty_app)
604 newDictsAtLoc loc theta `thenNF_Tc` \ dicts ->
606 rhs = mkHsDictApp ty_app (map instToId dicts)
608 returnNF_Tc (GenInst dicts rhs)
610 other -> returnNF_Tc NoInstance
612 lookupInst dict@(Dict _ _ loc) = returnNF_Tc NoInstance
616 lookupInst inst@(Method _ id tys theta _ loc)
617 = newDictsAtLoc loc theta `thenNF_Tc` \ dicts ->
618 returnNF_Tc (GenInst dicts (mkHsDictApp (mkHsTyApp (HsVar id) tys) (map instToId dicts)))
622 lookupInst inst@(LitInst u (HsIntegral i from_integer_name) ty loc)
623 | isIntTy ty && in_int_range -- Short cut for Int
624 = returnNF_Tc (GenInst [] int_lit)
625 -- GenInst, not SimpleInst, because int_lit is actually a constructor application
627 | isIntegerTy ty -- Short cut for Integer
628 = returnNF_Tc (GenInst [] integer_lit)
630 | in_int_range -- It's overloaded but small enough to fit into an Int
631 && from_integer_name `hasKey` fromIntegerClassOpKey -- And it's the built-in prelude fromInteger
632 -- (i.e. no funny business with user-defined
633 -- packages of numeric classes)
634 = -- So we can use the Prelude fromInt
635 tcLookupGlobalId fromIntName `thenNF_Tc` \ from_int ->
636 newMethodAtLoc loc from_int [ty] `thenNF_Tc` \ (method_inst, method_id) ->
637 returnNF_Tc (GenInst [method_inst] (HsApp (HsVar method_id) int_lit))
639 | otherwise -- Alas, it is overloaded and a big literal!
640 = tcLookupGlobalId from_integer_name `thenNF_Tc` \ from_integer ->
641 newMethodAtLoc loc from_integer [ty] `thenNF_Tc` \ (method_inst, method_id) ->
642 returnNF_Tc (GenInst [method_inst] (HsApp (HsVar method_id) integer_lit))
644 in_int_range = inIntRange i
645 integer_lit = HsLit (HsInteger i)
646 int_lit = HsLit (HsInt i)
648 -- similar idea for overloaded floating point literals: if the literal is
649 -- *definitely* a float or a double, generate the real thing here.
650 -- This is essential (see nofib/spectral/nucleic).
652 lookupInst inst@(LitInst u (HsFractional f from_rat_name) ty loc)
653 | isFloatTy ty = returnNF_Tc (GenInst [] float_lit)
654 | isDoubleTy ty = returnNF_Tc (GenInst [] double_lit)
657 = tcLookupGlobalId from_rat_name `thenNF_Tc` \ from_rational ->
658 newMethodAtLoc loc from_rational [ty] `thenNF_Tc` \ (method_inst, method_id) ->
660 rational_ty = funArgTy (idType method_id)
661 rational_lit = HsLit (HsRat f rational_ty)
663 returnNF_Tc (GenInst [method_inst] (HsApp (HsVar method_id) rational_lit))
666 floatprim_lit = HsLit (HsFloatPrim f)
667 float_lit = mkHsConApp floatDataCon [] [floatprim_lit]
668 doubleprim_lit = HsLit (HsDoublePrim f)
669 double_lit = mkHsConApp doubleDataCon [] [doubleprim_lit]
672 There is a second, simpler interface, when you want an instance of a
673 class at a given nullary type constructor. It just returns the
674 appropriate dictionary if it exists. It is used only when resolving
675 ambiguous dictionaries.
678 lookupSimpleInst :: Class
679 -> [Type] -- Look up (c,t)
680 -> NF_TcM (Maybe [(Class,[Type])]) -- Here are the needed (c,t)s
682 lookupSimpleInst clas tys
683 = tcGetInstEnv `thenNF_Tc` \ inst_env ->
684 case lookupInstEnv inst_env clas tys of
686 -> returnNF_Tc (Just (substClasses (mkSubst emptyInScopeSet tenv) theta'))
688 (_, theta, _) = splitSigmaTy (idType dfun)
689 theta' = classesOfPreds theta
691 other -> returnNF_Tc Nothing