2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
4 \section[Inst]{The @Inst@ type: dictionaries or method instances}
7 #include "HsVersions.h"
10 Inst(..), -- Visible only to TcSimplify
12 InstOrigin(..), OverloadedLit(..),
13 SYN_IE(LIE), emptyLIE, unitLIE, plusLIE, consLIE, zonkLIE, plusLIEs,
16 SYN_IE(InstanceMapper),
18 newDicts, newDictsAtLoc, newMethod, newMethodWithGivenTy, newOverloadedLit,
20 instType, tyVarsOfInst, lookupInst, lookupSimpleInst,
27 instBindingRequired, instCanBeGeneralised,
33 IMPORT_1_3(Ratio(Rational))
35 import HsSyn ( HsLit(..), HsExpr(..), HsBinds, Fixity, MonoBinds(..),
36 InPat, OutPat, Stmt, DoOrListComp, Match, GRHSsAndBinds,
37 ArithSeqInfo, HsType, Fake )
38 import RnHsSyn ( SYN_IE(RenamedArithSeqInfo), SYN_IE(RenamedHsExpr) )
39 import TcHsSyn ( SYN_IE(TcExpr),
40 SYN_IE(TcDictBinds), SYN_IE(TcMonoBinds),
41 mkHsTyApp, mkHsDictApp, tcIdTyVars )
44 import TcEnv ( tcLookupGlobalValueByKey, tcLookupTyConByKey )
45 import TcType ( TcIdOcc(..), SYN_IE(TcIdBndr),
46 SYN_IE(TcType), SYN_IE(TcRhoType), TcMaybe, SYN_IE(TcTyVarSet),
47 tcInstType, zonkTcType, tcSplitForAllTy, tcSplitRhoTy )
49 import Bag ( emptyBag, unitBag, unionBags, unionManyBags, bagToList,
50 listToBag, consBag, Bag )
51 import Class ( classInstEnv,
52 SYN_IE(Class), GenClass, SYN_IE(ClassInstEnv)
54 import ErrUtils ( addErrLoc, SYN_IE(Error) )
55 import Id ( GenId, idType, mkInstId, SYN_IE(Id) )
56 import PrelInfo ( isCcallishClass, isNoDictClass )
57 import MatchEnv ( lookupMEnv, insertMEnv )
58 import Name ( OccName(..), Name, mkLocalName,
59 mkSysLocalName, occNameString, getOccName )
61 import PprType ( GenClass, TyCon, GenType, GenTyVar, pprParendGenType )
63 import SpecEnv ( SpecEnv )
64 import SrcLoc ( SrcLoc, noSrcLoc )
65 import Type ( GenType, eqSimpleTy, instantiateTy,
66 isTyVarTy, mkDictTy, splitForAllTy, splitSigmaTy,
67 splitRhoTy, matchTy, tyVarsOfType, tyVarsOfTypes,
70 import TyVar ( unionTyVarSets, GenTyVar )
71 import TysPrim ( intPrimTy )
72 import TysWiredIn ( intDataCon, integerTy, isIntTy, isIntegerTy, inIntRange )
73 import Unique ( fromRationalClassOpKey, rationalTyConKey,
74 fromIntClassOpKey, fromIntegerClassOpKey, Unique
76 import Util ( panic, zipEqual, zipWithEqual, assoc, assertPanic, pprTrace{-ToDo:rm-} )
77 #if __GLASGOW_HASKELL__ >= 202
82 %************************************************************************
84 \subsection[Inst-collections]{LIE: a collection of Insts}
86 %************************************************************************
89 type LIE s = Bag (Inst s)
92 unitLIE inst = unitBag inst
93 plusLIE lie1 lie2 = lie1 `unionBags` lie2
94 consLIE inst lie = inst `consBag` lie
95 plusLIEs lies = unionManyBags lies
97 zonkLIE :: LIE s -> NF_TcM s (LIE s)
98 zonkLIE lie = mapBagNF_Tc zonkInst lie
100 pprLIE :: PprStyle -> LIE s -> Doc
101 pprLIE sty lie = pprQuote sty $ \ sty ->
102 braces (hsep (punctuate comma (map (pprInst sty) (bagToList lie))))
105 pprLIEInFull sty insts
106 = vcat (map go (bagToList insts))
108 go inst = ppr sty inst <+> pprOrigin sty inst
111 %************************************************************************
113 \subsection[Inst-types]{@Inst@ types}
115 %************************************************************************
117 An @Inst@ is either a dictionary, an instance of an overloaded
118 literal, or an instance of an overloaded value. We call the latter a
119 ``method'' even though it may not correspond to a class operation.
120 For example, we might have an instance of the @double@ function at
121 type Int, represented by
123 Method 34 doubleId [Int] origin
129 Class -- The type of the dict is (c t), where
130 (TcType s) -- c is the class and t the type;
137 (TcIdOcc s) -- 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 s] -- The types to which its polymorphic tyvars
145 -- should be instantiated.
146 -- These types must saturate the Id's foralls.
148 (TcRhoType s) -- Cached: (type-of-id applied to inst_tys)
149 -- If this type is (theta => tau) then the type of the Method
150 -- is tau, and the method can be built by saying
152 -- where dicts are constructed from theta
160 (TcType s) -- The type at which the literal is used
161 (InstOrigin s) -- Always a literal; but more convenient to carry this around
165 = OverloadedIntegral Integer -- The number
166 | OverloadedFractional Rational -- The number
168 getInstOrigin (Dict u clas ty origin loc) = origin
169 getInstOrigin (Method u clas ty rho origin loc) = origin
170 getInstOrigin (LitInst u lit ty origin loc) = origin
177 newDicts :: InstOrigin s
178 -> [(Class, TcType s)]
179 -> NF_TcM s (LIE s, [TcIdOcc s])
181 = tcGetSrcLoc `thenNF_Tc` \ loc ->
182 newDictsAtLoc orig loc theta `thenNF_Tc` \ (dicts, ids) ->
183 returnNF_Tc (listToBag dicts, ids)
185 tcGetUniques (length theta) `thenNF_Tc` \ new_uniqs ->
187 mk_dict u (clas, ty) = Dict u clas ty orig loc
188 dicts = zipWithEqual "newDicts" mk_dict new_uniqs theta
190 returnNF_Tc (listToBag dicts, map instToId dicts)
193 -- Local function, similar to newDicts,
194 -- but with slightly different interface
195 newDictsAtLoc :: InstOrigin s
197 -> [(Class, TcType s)]
198 -> NF_TcM s ([Inst s], [TcIdOcc s])
199 newDictsAtLoc orig loc theta =
200 tcGetUniques (length theta) `thenNF_Tc` \ new_uniqs ->
202 mk_dict u (clas, ty) = Dict u clas ty orig loc
203 dicts = zipWithEqual "newDictsAtLoc" mk_dict new_uniqs theta
205 returnNF_Tc (dicts, map instToId dicts)
207 newMethod :: InstOrigin s
210 -> NF_TcM s (LIE s, TcIdOcc s)
211 newMethod orig id tys
212 = -- Get the Id type and instantiate it at the specified types
214 RealId id -> let (tyvars, rho) = splitForAllTy (idType id)
216 (if length tyvars /= length tys then pprTrace "newMethod" (ppr PprDebug (idType id)) else \x->x) $
217 tcInstType (zip{-Equal "newMethod"-} tyvars tys) rho
218 TcId id -> tcSplitForAllTy (idType id) `thenNF_Tc` \ (tyvars, rho) ->
219 returnNF_Tc (instantiateTy (zipEqual "newMethod(2)" tyvars tys) rho)
220 ) `thenNF_Tc` \ rho_ty ->
221 -- Our friend does the rest
222 newMethodWithGivenTy orig id tys rho_ty
225 newMethodWithGivenTy orig id tys rho_ty
226 = tcGetSrcLoc `thenNF_Tc` \ loc ->
227 tcGetUnique `thenNF_Tc` \ new_uniq ->
229 meth_inst = Method new_uniq id tys rho_ty orig loc
231 returnNF_Tc (unitLIE meth_inst, instToId meth_inst)
233 newMethodAtLoc :: InstOrigin s -> SrcLoc -> Id -> [TcType s] -> NF_TcM s (Inst s, TcIdOcc s)
234 newMethodAtLoc orig loc real_id tys -- Local function, similar to newMethod but with
235 -- slightly different interface
236 = -- Get the Id type and instantiate it at the specified types
238 (tyvars,rho) = splitForAllTy (idType real_id)
240 tcInstType (zipEqual "newMethodAtLoc" tyvars tys) rho `thenNF_Tc` \ rho_ty ->
241 tcGetUnique `thenNF_Tc` \ new_uniq ->
243 meth_inst = Method new_uniq (RealId real_id) tys rho_ty orig loc
245 returnNF_Tc (meth_inst, instToId meth_inst)
247 newOverloadedLit :: InstOrigin s
250 -> NF_TcM s (TcExpr s, LIE s)
251 newOverloadedLit orig (OverloadedIntegral i) ty
252 | isIntTy ty && inIntRange i -- Short cut for Int
253 = returnNF_Tc (int_lit, emptyLIE)
255 | isIntegerTy ty -- Short cut for Integer
256 = returnNF_Tc (integer_lit, emptyLIE)
259 intprim_lit = HsLitOut (HsIntPrim i) intPrimTy
260 integer_lit = HsLitOut (HsInt i) integerTy
261 int_lit = HsApp (HsVar (RealId intDataCon)) intprim_lit
263 newOverloadedLit orig lit ty -- The general case
264 = tcGetSrcLoc `thenNF_Tc` \ loc ->
265 tcGetUnique `thenNF_Tc` \ new_uniq ->
267 lit_inst = LitInst new_uniq lit ty orig loc
269 returnNF_Tc (HsVar (instToId lit_inst), unitLIE lit_inst)
274 instToId :: Inst s -> TcIdOcc s
275 instToId (Dict u clas ty orig loc)
276 = TcId (mkInstId u (mkDictTy clas ty) (mkLocalName u str loc))
278 str = VarOcc (SLIT("d.") _APPEND_ (occNameString (getOccName clas)))
280 instToId (Method u id tys rho_ty orig loc)
281 = TcId (mkInstId u tau_ty (mkLocalName u occ loc))
284 (_, tau_ty) = splitRhoTy rho_ty
285 -- I hope we don't need tcSplitRhoTy...
286 -- NB The method Id has just the tau type
288 instToId (LitInst u list ty orig loc)
289 = TcId (mkInstId u ty (mkSysLocalName u SLIT("lit") loc))
293 instType :: Inst s -> TcType s
294 instType (Dict _ clas ty _ _) = mkDictTy clas ty
295 instType (LitInst _ _ ty _ _) = ty
296 instType (Method _ id tys ty _ _) = ty
302 Zonking makes sure that the instance types are fully zonked,
303 but doesn't do the same for the Id in a Method. There's no
304 need, and it's a lot of extra work.
307 zonkInst :: Inst s -> NF_TcM s (Inst s)
308 zonkInst (Dict u clas ty orig loc)
309 = zonkTcType ty `thenNF_Tc` \ new_ty ->
310 returnNF_Tc (Dict u clas new_ty orig loc)
312 zonkInst (Method u id tys rho orig loc) -- Doesn't zonk the id!
313 = mapNF_Tc zonkTcType tys `thenNF_Tc` \ new_tys ->
314 zonkTcType rho `thenNF_Tc` \ new_rho ->
315 returnNF_Tc (Method u id new_tys new_rho orig loc)
317 zonkInst (LitInst u lit ty orig loc)
318 = zonkTcType ty `thenNF_Tc` \ new_ty ->
319 returnNF_Tc (LitInst u lit new_ty orig loc)
324 tyVarsOfInst :: Inst s -> TcTyVarSet s
325 tyVarsOfInst (Dict _ _ ty _ _) = tyVarsOfType ty
326 tyVarsOfInst (Method _ id tys rho _ _) = tyVarsOfTypes tys `unionTyVarSets` tcIdTyVars id
327 -- The id might not be a RealId; in the case of
328 -- locally-overloaded class methods, for example
329 tyVarsOfInst (LitInst _ _ ty _ _) = tyVarsOfType ty
332 @matchesInst@ checks when two @Inst@s are instances of the same
333 thing at the same type, even if their uniques differ.
336 matchesInst :: Inst s -> Inst s -> Bool
338 matchesInst (Dict _ clas1 ty1 _ _) (Dict _ clas2 ty2 _ _)
339 = clas1 == clas2 && ty1 `eqSimpleTy` ty2
341 matchesInst (Method _ id1 tys1 _ _ _) (Method _ id2 tys2 _ _ _)
343 && and (zipWith eqSimpleTy tys1 tys2)
344 && length tys1 == length tys2
346 matchesInst (LitInst _ lit1 ty1 _ _) (LitInst _ lit2 ty2 _ _)
347 = lit1 `eq` lit2 && ty1 `eqSimpleTy` ty2
349 (OverloadedIntegral i1) `eq` (OverloadedIntegral i2) = i1 == i2
350 (OverloadedFractional f1) `eq` (OverloadedFractional f2) = f1 == f2
353 matchesInst other1 other2 = False
360 isDict :: Inst s -> Bool
361 isDict (Dict _ _ _ _ _) = True
364 isTyVarDict :: Inst s -> Bool
365 isTyVarDict (Dict _ _ ty _ _) = isTyVarTy ty
366 isTyVarDict other = False
369 Two predicates which deal with the case where class constraints don't
370 necessarily result in bindings. The first tells whether an @Inst@
371 must be witnessed by an actual binding; the second tells whether an
372 @Inst@ can be generalised over.
375 instBindingRequired :: Inst s -> Bool
376 instBindingRequired (Dict _ clas _ _ _) = not (isNoDictClass clas)
377 instBindingRequired other = True
379 instCanBeGeneralised :: Inst s -> Bool
380 instCanBeGeneralised (Dict _ clas _ _ _) = not (isCcallishClass clas)
381 instCanBeGeneralised other = True
387 ToDo: improve these pretty-printing things. The ``origin'' is really only
388 relevant in error messages.
391 instance Outputable (Inst s) where
392 ppr sty inst = pprQuote sty (\ sty -> pprInst sty inst)
394 pprInst sty (LitInst u lit ty orig loc)
396 OverloadedIntegral i -> integer i
397 OverloadedFractional f -> rational f,
402 pprInst sty (Dict u clas ty orig loc)
403 = hsep [ppr sty clas, pprParendGenType sty ty, show_uniq sty u]
405 pprInst sty (Method u id tys rho orig loc)
406 = hsep [ppr sty id, ptext SLIT("at"),
410 show_uniq PprDebug u = ppr PprDebug u
411 show_uniq sty u = empty
414 Printing in error messages. These two must look the same.
417 noInstanceErr inst sty = ptext SLIT("No instance for:") <+> ppr sty inst
419 noSimpleInst clas ty sty
420 = ptext SLIT("No instance for:") <+>
421 (pprQuote sty (\ sty -> ppr sty clas <+> pprParendGenType sty ty))
424 %************************************************************************
426 \subsection[InstEnv-types]{Type declarations}
428 %************************************************************************
431 type InstanceMapper = Class -> ClassInstEnv
434 A @ClassInstEnv@ lives inside a class, and identifies all the instances
435 of that class. The @Id@ inside a ClassInstEnv mapping is the dfun for
438 There is an important consistency constraint between the @MatchEnv@s
439 in and the dfun @Id@s inside them: the free type variables of the
440 @Type@ key in the @MatchEnv@ must be a subset of the universally-quantified
441 type variables of the dfun. Thus, the @ClassInstEnv@ for @Eq@ might
442 contain the following entry:
444 [a] ===> dfun_Eq_List :: forall a. Eq a => Eq [a]
446 The "a" in the pattern must be one of the forall'd variables in
452 TcDictBinds s) -- The new binding
456 lookupInst dict@(Dict _ clas ty orig loc)
457 = case lookupMEnv matchTy (get_inst_env clas orig) ty of
458 Nothing -> tcAddSrcLoc loc $
459 tcAddErrCtxt (\sty -> pprOrigin sty dict) $
460 failTc (noInstanceErr dict)
464 (tyvars, rho) = splitForAllTy (idType dfun_id)
465 ty_args = map (assoc "lookupInst" tenv) tyvars
466 -- tenv should bind all the tyvars
468 tcInstType tenv rho `thenNF_Tc` \ dfun_rho ->
470 (theta, tau) = splitRhoTy dfun_rho
472 newDictsAtLoc orig loc theta `thenNF_Tc` \ (dicts, dict_ids) ->
474 rhs = mkHsDictApp (mkHsTyApp (HsVar (RealId dfun_id)) ty_args) dict_ids
476 returnTc (dicts, VarMonoBind (instToId dict) rhs)
481 lookupInst inst@(Method _ id tys rho orig loc)
482 = tcSplitRhoTy rho `thenNF_Tc` \ (theta, _) ->
483 newDictsAtLoc orig loc theta `thenNF_Tc` \ (dicts, dict_ids) ->
484 returnTc (dicts, VarMonoBind (instToId inst) (mkHsDictApp (mkHsTyApp (HsVar id) tys) dict_ids))
488 lookupInst inst@(LitInst u (OverloadedIntegral i) ty orig loc)
489 | isIntTy ty && in_int_range -- Short cut for Int
490 = returnTc ([], VarMonoBind inst_id int_lit)
492 | isIntegerTy ty -- Short cut for Integer
493 = returnTc ([], VarMonoBind inst_id integer_lit)
495 | in_int_range -- It's overloaded but small enough to fit into an Int
496 = tcLookupGlobalValueByKey fromIntClassOpKey `thenNF_Tc` \ from_int ->
497 newMethodAtLoc orig loc from_int [ty] `thenNF_Tc` \ (method_inst, method_id) ->
498 returnTc ([method_inst], VarMonoBind inst_id (HsApp (HsVar method_id) int_lit))
500 | otherwise -- Alas, it is overloaded and a big literal!
501 = tcLookupGlobalValueByKey fromIntegerClassOpKey `thenNF_Tc` \ from_integer ->
502 newMethodAtLoc orig loc from_integer [ty] `thenNF_Tc` \ (method_inst, method_id) ->
503 returnTc ([method_inst], VarMonoBind inst_id (HsApp (HsVar method_id) integer_lit))
505 in_int_range = inIntRange i
506 intprim_lit = HsLitOut (HsIntPrim i) intPrimTy
507 integer_lit = HsLitOut (HsInt i) integerTy
508 int_lit = HsApp (HsVar (RealId intDataCon)) intprim_lit
509 inst_id = instToId inst
511 lookupInst inst@(LitInst u (OverloadedFractional f) ty orig loc)
512 = tcLookupGlobalValueByKey fromRationalClassOpKey `thenNF_Tc` \ from_rational ->
514 -- The type Rational isn't wired in so we have to conjure it up
515 tcLookupTyConByKey rationalTyConKey `thenNF_Tc` \ rational_tycon ->
517 rational_ty = mkSynTy rational_tycon []
518 rational_lit = HsLitOut (HsFrac f) rational_ty
520 newMethodAtLoc orig loc from_rational [ty] `thenNF_Tc` \ (method_inst, method_id) ->
521 returnTc ([method_inst], VarMonoBind (instToId inst) (HsApp (HsVar method_id) rational_lit))
524 There is a second, simpler interface, when you want an instance of a
525 class at a given nullary type constructor. It just returns the
526 appropriate dictionary if it exists. It is used only when resolving
527 ambiguous dictionaries.
530 lookupSimpleInst :: ClassInstEnv
532 -> Type -- Look up (c,t)
533 -> TcM s [(Class,Type)] -- Here are the needed (c,t)s
535 lookupSimpleInst class_inst_env clas ty
536 = case (lookupMEnv matchTy class_inst_env ty) of
537 Nothing -> failTc (noSimpleInst clas ty)
538 Just (dfun,tenv) -> returnTc [(c,instantiateTy tenv t) | (c,t) <- theta]
540 (_, theta, _) = splitSigmaTy (idType dfun)
544 @mkInstSpecEnv@ is used to construct the @SpecEnv@ for a dfun.
545 It does it by filtering the class's @InstEnv@. All pretty shady stuff.
548 mkInstSpecEnv clas inst_ty inst_tvs inst_theta = panic "mkInstSpecEnv"
552 mkInstSpecEnv :: Class -- class
553 -> Type -- instance type
554 -> [TyVarTemplate] -- instance tyvars
555 -> ThetaType -- superclasses dicts
556 -> SpecEnv -- specenv for dfun of instance
558 mkInstSpecEnv clas inst_ty inst_tvs inst_theta
559 = mkSpecEnv (catMaybes (map maybe_spec_info matches))
561 matches = matchMEnv matchTy (classInstEnv clas) inst_ty
563 maybe_spec_info (_, match_info, MkInstTemplate dfun _ [])
564 = Just (SpecInfo (map (assocMaybe match_info) inst_tvs) (length inst_theta) dfun)
565 maybe_spec_info (_, match_info, _)
572 :: ClassInstEnv -- Incoming envt
573 -> Type -- The instance type: inst_ty
574 -> Id -- Dict fun id to apply. Free tyvars of inst_ty must
575 -- be the same as the forall'd tyvars of the dfun id.
577 ClassInstEnv -- Success
578 (Type, Id) -- Offending overlap
580 addClassInst inst_env inst_ty dfun_id = insertMEnv matchTy inst_env inst_ty dfun_id
585 %************************************************************************
587 \subsection[Inst-origin]{The @InstOrigin@ type}
589 %************************************************************************
591 The @InstOrigin@ type gives information about where a dictionary came from.
592 This is important for decent error message reporting because dictionaries
593 don't appear in the original source code. Doubtless this type will evolve...
597 = OccurrenceOf (TcIdOcc s) -- Occurrence of an overloaded identifier
598 | OccurrenceOfCon Id -- Occurrence of a data constructor
602 | DataDeclOrigin -- Typechecking a data declaration
604 | InstanceDeclOrigin -- Typechecking an instance decl
606 | LiteralOrigin HsLit -- Occurrence of a literal
608 | ArithSeqOrigin RenamedArithSeqInfo -- [x..], [x..y] etc
610 | SignatureOrigin -- A dict created from a type signature
611 | Rank2Origin -- A dict created when typechecking the argument
612 -- of a rank-2 typed function
614 | DoOrigin -- The monad for a do expression
616 | ClassDeclOrigin -- Manufactured during a class decl
619 -- | DerivingOrigin InstanceMapper
623 -- During "deriving" operations we have an ever changing
624 -- mapping of classes to instances, so we record it inside the
625 -- origin information. This is a bit of a hack, but it works
626 -- fine. (Simon is to blame [WDP].)
628 | InstanceSpecOrigin InstanceMapper
629 Class -- in a SPECIALIZE instance pragma
632 -- When specialising instances the instance info attached to
633 -- each class is not yet ready, so we record it inside the
634 -- origin information. This is a bit of a hack, but it works
635 -- fine. (Patrick is to blame [WDP].)
637 -- | DefaultDeclOrigin -- Related to a `default' declaration
639 | ValSpecOrigin Name -- in a SPECIALIZE pragma for a value
641 -- Argument or result of a ccall
642 -- Dictionaries with this origin aren't actually mentioned in the
643 -- translated term, and so need not be bound. Nor should they
644 -- be abstracted over.
646 | CCallOrigin String -- CCall label
647 (Maybe RenamedHsExpr) -- Nothing if it's the result
648 -- Just arg, for an argument
650 | LitLitOrigin String -- the litlit
652 | UnknownOrigin -- Help! I give up...
656 -- During deriving and instance specialisation operations
657 -- we can't get the instances of the class from inside the
658 -- class, because the latter ain't ready yet. Instead we
659 -- find a mapping from classes to envts inside the dict origin.
661 get_inst_env :: Class -> InstOrigin s -> ClassInstEnv
662 -- get_inst_env clas (DerivingOrigin inst_mapper _ _)
663 -- = fst (inst_mapper clas)
664 get_inst_env clas (InstanceSpecOrigin inst_mapper _ _)
666 get_inst_env clas other_orig = classInstEnv clas
669 pprOrigin :: PprStyle -> Inst s -> Doc
671 = hsep [text "arising from", pp_orig orig, text "at", ppr sty locn]
673 (orig, locn) = case inst of
674 Dict _ _ _ orig loc -> (orig,loc)
675 Method _ _ _ _ orig loc -> (orig,loc)
676 LitInst _ _ _ orig loc -> (orig,loc)
678 pp_orig (OccurrenceOf id)
679 = hsep [ptext SLIT("use of"), ppr sty id]
680 pp_orig (OccurrenceOfCon id)
681 = hsep [ptext SLIT("use of"), ppr sty id]
682 pp_orig (LiteralOrigin lit)
683 = hsep [ptext SLIT("the literal"), ppr sty lit]
684 pp_orig (InstanceDeclOrigin)
685 = ptext SLIT("an instance declaration")
686 pp_orig (ArithSeqOrigin seq)
687 = hsep [ptext SLIT("the arithmetic sequence:"), ppr sty seq]
688 pp_orig (SignatureOrigin)
689 = ptext SLIT("a type signature")
690 pp_orig (Rank2Origin)
691 = ptext SLIT("a function with an overloaded argument type")
693 = ptext SLIT("a do statement")
694 pp_orig (ClassDeclOrigin)
695 = ptext SLIT("a class declaration")
696 pp_orig (InstanceSpecOrigin _ clas ty)
697 = hsep [text "a SPECIALIZE instance pragma; class",
698 ppr sty clas, text "type:", ppr sty ty]
699 pp_orig (ValSpecOrigin name)
700 = hsep [ptext SLIT("a SPECIALIZE user-pragma for"), ppr sty name]
701 pp_orig (CCallOrigin clabel Nothing{-ccall result-})
702 = hsep [ptext SLIT("the result of the _ccall_ to"), text clabel]
703 pp_orig (CCallOrigin clabel (Just arg_expr))
704 = hsep [ptext SLIT("an argument in the _ccall_ to"), text clabel <> comma, text "namely", ppr sty arg_expr]
705 pp_orig (LitLitOrigin s)
706 = hsep [ptext SLIT("the ``literal-literal''"), text s]
707 pp_orig (UnknownOrigin)
708 = ptext SLIT("...oops -- I don't know where the overloading came from!")