cc0f0f3b94868a98e4a049971ed7c3d397777044
[ghc-hetmet.git] / ghc / compiler / rename / RnTypes.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
3 %
4 \section[RnSource]{Main pass of renamer}
5
6 \begin{code}
7 module RnTypes ( rnHsType, rnContext, 
8                  rnHsSigType, rnHsTypeFVs,
9                  rnPat, rnPatsAndThen,  -- Here because it's not part 
10                  rnOverLit, litFVs,             -- of any mutual recursion      
11                  precParseErr, sectionPrecErr, dupFieldErr, patSigErr, checkTupSize
12   ) where
13
14 import CmdLineOpts      ( DynFlag(Opt_WarnUnusedMatches, Opt_GlasgowExts) )
15
16 import HsSyn
17 import RdrHsSyn ( RdrNameContext, RdrNameHsType, RdrNamePat,
18                   extractHsRhoRdrTyVars )
19 import RnHsSyn  ( RenamedContext, RenamedHsType, RenamedPat,
20                   extractHsTyNames, 
21                   parrTyCon_name, tupleTyCon_name, listTyCon_name, charTyCon_name )
22 import RnEnv    ( lookupOccRn, lookupBndrRn, lookupSyntaxName, lookupGlobalOccRn,
23                   bindTyVarsRn, lookupFixityRn, mapFvRn, newIPNameRn,
24                   bindPatSigTyVarsFV, bindLocalsFV, warnUnusedMatches )
25 import TcRnMonad
26 import RdrName  ( elemLocalRdrEnv )
27 import PrelNames( eqStringName, eqClassName, integralClassName, 
28                   negateName, minusName, lengthPName, indexPName, plusIntegerName, fromIntegerName,
29                   timesIntegerName, ratioDataConName, fromRationalName )
30 import Constants        ( mAX_TUPLE_SIZE )
31 import TysWiredIn       ( intTyCon )
32 import TysPrim          ( charPrimTyCon, addrPrimTyCon, intPrimTyCon, 
33                           floatPrimTyCon, doublePrimTyCon )
34 import Name     ( Name, NamedThing(..) )
35 import NameSet
36
37 import Literal          ( inIntRange, inCharRange )
38 import BasicTypes       ( compareFixity )
39 import ListSetOps       ( removeDups )
40 import Outputable
41
42 #include "HsVersions.h"
43 \end{code}
44
45 These type renamers are in a separate module, rather than in (say) RnSource,
46 to break several loop.
47
48 %*********************************************************
49 %*                                                      *
50 \subsection{Renaming types}
51 %*                                                      *
52 %*********************************************************
53
54 \begin{code}
55 rnHsTypeFVs :: SDoc -> RdrNameHsType -> RnM (RenamedHsType, FreeVars)
56 rnHsTypeFVs doc_str ty 
57   = rnHsType doc_str ty         `thenM` \ ty' ->
58     returnM (ty', extractHsTyNames ty')
59
60 rnHsSigType :: SDoc -> RdrNameHsType -> RnM RenamedHsType
61         -- rnHsSigType is used for source-language type signatures,
62         -- which use *implicit* universal quantification.
63 rnHsSigType doc_str ty
64   = rnHsType (text "In the type signature for" <+> doc_str) ty
65 \end{code}
66
67 rnHsType is here because we call it from loadInstDecl, and I didn't
68 want a gratuitous knot.
69
70 \begin{code}
71 rnHsType :: SDoc -> RdrNameHsType -> RnM RenamedHsType
72
73 rnHsType doc (HsForAllTy Implicit _ ctxt ty)
74         -- Implicit quantifiction in source code (no kinds on tyvars)
75         -- Given the signature  C => T  we universally quantify 
76         -- over FV(T) \ {in-scope-tyvars} 
77   = getLocalRdrEnv              `thenM` \ name_env ->
78     let
79         mentioned = extractHsRhoRdrTyVars ctxt ty
80
81         -- Don't quantify over type variables that are in scope;
82         -- when GlasgowExts is off, there usually won't be any, except for
83         -- class signatures:
84         --      class C a where { op :: a -> a }
85         forall_tyvars = filter (not . (`elemLocalRdrEnv` name_env)) mentioned
86     in
87     rnForAll doc Implicit (map UserTyVar forall_tyvars) ctxt ty
88
89 rnHsType doc (HsForAllTy Explicit forall_tyvars ctxt tau)
90         -- Explicit quantification.
91         -- Check that the forall'd tyvars are actually 
92         -- mentioned in the type, and produce a warning if not
93   = let
94         mentioned          = extractHsRhoRdrTyVars ctxt tau
95         forall_tyvar_names = hsTyVarNames forall_tyvars
96
97         -- Explicitly quantified but not mentioned in ctxt or tau
98         warn_guys = filter (`notElem` mentioned) forall_tyvar_names
99     in
100     mappM_ (forAllWarn doc tau) warn_guys       `thenM_`
101     rnForAll doc Explicit forall_tyvars ctxt tau
102
103 rnHsType doc (HsTyVar tyvar)
104   = lookupOccRn tyvar           `thenM` \ tyvar' ->
105     returnM (HsTyVar tyvar')
106
107 rnHsType doc (HsOpTy ty1 op ty2)
108   = lookupOccRn op              `thenM` \ op' ->
109     rnHsType doc ty1            `thenM` \ ty1' ->
110     rnHsType doc ty2            `thenM` \ ty2' -> 
111     lookupTyFixityRn op'        `thenM` \ fix ->
112     mkHsOpTyRn op' fix ty1' ty2'
113
114 rnHsType doc (HsParTy ty)
115   = rnHsType doc ty             `thenM` \ ty' ->
116     returnM (HsParTy ty')
117
118 rnHsType doc (HsNumTy i)
119   | i == 1    = returnM (HsNumTy i)
120   | otherwise = addErr err_msg  `thenM_`  returnM (HsNumTy i)
121   where
122     err_msg = ptext SLIT("Only unit numeric type pattern is valid")
123                            
124
125 rnHsType doc (HsFunTy ty1 ty2)
126   = rnHsType doc ty1    `thenM` \ ty1' ->
127         -- Might find a for-all as the arg of a function type
128     rnHsType doc ty2    `thenM` \ ty2' ->
129         -- Or as the result.  This happens when reading Prelude.hi
130         -- when we find return :: forall m. Monad m -> forall a. a -> m a
131     returnM (HsFunTy ty1' ty2')
132
133 rnHsType doc (HsListTy ty)
134   = rnHsType doc ty                             `thenM` \ ty' ->
135     returnM (HsListTy ty')
136
137 rnHsType doc (HsKindSig ty k)
138   = rnHsType doc ty                             `thenM` \ ty' ->
139     returnM (HsKindSig ty' k)
140
141 rnHsType doc (HsPArrTy ty)
142   = rnHsType doc ty                             `thenM` \ ty' ->
143     returnM (HsPArrTy ty')
144
145 -- Unboxed tuples are allowed to have poly-typed arguments.  These
146 -- sometimes crop up as a result of CPR worker-wrappering dictionaries.
147 rnHsType doc (HsTupleTy tup_con tys)
148   = mappM (rnHsType doc) tys            `thenM` \ tys' ->
149     returnM (HsTupleTy tup_con tys')
150
151 rnHsType doc (HsAppTy ty1 ty2)
152   = rnHsType doc ty1            `thenM` \ ty1' ->
153     rnHsType doc ty2            `thenM` \ ty2' ->
154     returnM (HsAppTy ty1' ty2')
155
156 rnHsType doc (HsPredTy pred)
157   = rnPred doc pred     `thenM` \ pred' ->
158     returnM (HsPredTy pred')
159
160 rnHsTypes doc tys = mappM (rnHsType doc) tys
161 \end{code}
162
163
164 \begin{code}
165 rnForAll doc exp [] [] ty = rnHsType doc ty
166         -- One reason for this case is that a type like Int#
167         -- starts of as (HsForAllTy Nothing [] Int), in case
168         -- there is some quantification.  Now that we have quantified
169         -- and discovered there are no type variables, it's nicer to turn
170         -- it into plain Int.  If it were Int# instead of Int, we'd actually
171         -- get an error, because the body of a genuine for-all is
172         -- of kind *.
173
174 rnForAll doc exp forall_tyvars ctxt ty
175   = bindTyVarsRn doc forall_tyvars      $ \ new_tyvars ->
176     rnContext doc ctxt                  `thenM` \ new_ctxt ->
177     rnHsType doc ty                     `thenM` \ new_ty ->
178     returnM (HsForAllTy exp new_tyvars new_ctxt new_ty)
179         -- Retain the same implicit/explicit flag as before
180         -- so that we can later print it correctly
181 \end{code}
182
183
184 %*********************************************************
185 %*                                                      *
186 \subsection{Fixities}
187 %*                                                      *
188 %*********************************************************
189
190 Infix types are read in a *right-associative* way, so that
191         a `op` b `op` c
192 is always read in as
193         a `op` (b `op` c)
194
195 mkHsOpTyRn rearranges where necessary.  The two arguments
196 have already been renamed and rearranged.  It's made rather tiresome
197 by the presence of ->
198
199 \begin{code}
200 lookupTyFixityRn n 
201   = doptM Opt_GlasgowExts                       `thenM` \ glaExts ->
202     warnIf (not glaExts) (infixTyConWarn n)     `thenM_`
203     lookupFixityRn n
204
205 -- Building (ty1 `op1` (ty21 `op2` ty22))
206 mkHsOpTyRn :: Name -> Fixity 
207            -> RenamedHsType -> RenamedHsType 
208            -> RnM RenamedHsType
209
210 mkHsOpTyRn op1 fix1 ty1 ty2@(HsOpTy ty21 op2 ty22)
211   = lookupTyFixityRn op2                `thenM` \ fix2 ->
212     let
213         (nofix_error, associate_right) = compareFixity fix1 fix2
214     in
215     if nofix_error then
216         addErr (precParseErr (quotes (ppr op1),fix1) 
217                                (quotes (ppr op2),fix2)) `thenM_`
218         returnM (HsOpTy ty1 op1 ty2)
219     else 
220     if not associate_right then
221         -- Rearrange to ((ty1 `op1` ty21) `op2` ty22)
222         mkHsOpTyRn op1 fix1 ty1 ty21            `thenM` \ new_ty ->
223         returnM (HsOpTy new_ty op2 ty22)
224     else
225     returnM (HsOpTy ty1 op1 ty2)
226
227 mkHsOpTyRn op fix ty1 ty2                       -- Default case, no rearrangment
228   = returnM (HsOpTy ty1 op ty2)
229 \end{code}
230
231 %*********************************************************
232 %*                                                      *
233 \subsection{Contexts and predicates}
234 %*                                                      *
235 %*********************************************************
236
237 \begin{code}
238 rnContext :: SDoc -> RdrNameContext -> RnM RenamedContext
239 rnContext doc ctxt = mappM (rnPred doc) ctxt
240
241 rnPred doc (HsClassP clas tys)
242   = lookupOccRn clas            `thenM` \ clas_name ->
243     rnHsTypes doc tys           `thenM` \ tys' ->
244     returnM (HsClassP clas_name tys')
245
246 rnPred doc (HsIParam n ty)
247   = newIPNameRn n               `thenM` \ name ->
248     rnHsType doc ty             `thenM` \ ty' ->
249     returnM (HsIParam name ty')
250 \end{code}
251
252
253 *********************************************************
254 *                                                       *
255 \subsection{Patterns}
256 *                                                       *
257 *********************************************************
258
259 \begin{code}
260 rnPatsAndThen :: HsMatchContext Name
261               -> Bool
262               -> [RdrNamePat] 
263               -> ([RenamedPat] -> RnM (a, FreeVars))
264               -> RnM (a, FreeVars)
265 -- Bring into scope all the binders and type variables
266 -- bound by the patterns; then rename the patterns; then
267 -- do the thing inside.
268 --
269 -- Note that we do a single bindLocalsRn for all the
270 -- matches together, so that we spot the repeated variable in
271 --      f x x = 1
272
273 rnPatsAndThen ctxt repUnused pats thing_inside
274   = bindPatSigTyVarsFV pat_sig_tys      $
275     bindLocalsFV doc_pat bndrs          $ \ new_bndrs ->
276     rnPats pats                         `thenM` \ (pats', pat_fvs) ->
277     thing_inside pats'                  `thenM` \ (res, res_fvs) ->
278
279     let
280         unused_binders = filter (not . (`elemNameSet` res_fvs)) new_bndrs
281     in
282     (if repUnused
283      then warnUnusedMatches unused_binders
284      else returnM ())                  `thenM_`
285     returnM (res, res_fvs `plusFV` pat_fvs)
286   where
287     pat_sig_tys = collectSigTysFromPats pats
288     bndrs       = collectPatsBinders    pats
289     doc_pat     = ptext SLIT("In") <+> pprMatchContext ctxt
290
291 rnPats :: [RdrNamePat] -> RnM ([RenamedPat], FreeVars)
292 rnPats ps = mapFvRn rnPat ps
293
294 rnPat :: RdrNamePat -> RnM (RenamedPat, FreeVars)
295
296 rnPat (WildPat _) = returnM (WildPat placeHolderType, emptyFVs)
297
298 rnPat (VarPat name)
299   = lookupBndrRn  name                  `thenM` \ vname ->
300     returnM (VarPat vname, emptyFVs)
301
302 rnPat (SigPatIn pat ty)
303   = doptM Opt_GlasgowExts `thenM` \ glaExts ->
304     
305     if glaExts
306     then rnPat pat              `thenM` \ (pat', fvs1) ->
307          rnHsTypeFVs doc ty     `thenM` \ (ty',  fvs2) ->
308          returnM (SigPatIn pat' ty', fvs1 `plusFV` fvs2)
309
310     else addErr (patSigErr ty)  `thenM_`
311          rnPat pat
312   where
313     doc = text "In a pattern type-signature"
314     
315 rnPat (LitPat s@(HsString _)) 
316   = returnM (LitPat s, unitFV eqStringName)
317
318 rnPat (LitPat lit) 
319   = litFVs lit          `thenM` \ fvs ->
320     returnM (LitPat lit, fvs) 
321
322 rnPat (NPatIn lit mb_neg) 
323   = rnOverLit lit                       `thenM` \ (lit', fvs1) ->
324     (case mb_neg of
325         Nothing -> returnM (Nothing, emptyFVs)
326         Just _  -> lookupSyntaxName negateName  `thenM` \ (neg, fvs) ->
327                    returnM (Just neg, fvs)
328     )                                   `thenM` \ (mb_neg', fvs2) ->
329     returnM (NPatIn lit' mb_neg', 
330               fvs1 `plusFV` fvs2 `addOneFV` eqClassName)        
331         -- Needed to find equality on pattern
332
333 rnPat (NPlusKPatIn name lit _)
334   = rnOverLit lit                       `thenM` \ (lit', fvs1) ->
335     lookupBndrRn name                   `thenM` \ name' ->
336     lookupSyntaxName minusName          `thenM` \ (minus, fvs2) ->
337     returnM (NPlusKPatIn name' lit' minus, 
338               fvs1 `plusFV` fvs2 `addOneFV` integralClassName)
339         -- The Report says that n+k patterns must be in Integral
340
341 rnPat (LazyPat pat)
342   = rnPat pat           `thenM` \ (pat', fvs) ->
343     returnM (LazyPat pat', fvs)
344
345 rnPat (AsPat name pat)
346   = rnPat pat           `thenM` \ (pat', fvs) ->
347     lookupBndrRn name   `thenM` \ vname ->
348     returnM (AsPat vname pat', fvs)
349
350 rnPat (ConPatIn con stuff) = rnConPat con stuff
351
352
353 rnPat (ParPat pat)
354   = rnPat pat           `thenM` \ (pat', fvs) ->
355     returnM (ParPat pat', fvs)
356
357 rnPat (ListPat pats _)
358   = rnPats pats                 `thenM` \ (patslist, fvs) ->
359     returnM (ListPat patslist placeHolderType, fvs `addOneFV` listTyCon_name)
360
361 rnPat (PArrPat pats _)
362   = rnPats pats                 `thenM` \ (patslist, fvs) ->
363     returnM (PArrPat patslist placeHolderType, 
364               fvs `plusFV` implicit_fvs `addOneFV` parrTyCon_name)
365   where
366     implicit_fvs = mkFVs [lengthPName, indexPName]
367
368 rnPat (TuplePat pats boxed)
369   = checkTupSize tup_size       `thenM_`
370     rnPats pats                 `thenM` \ (patslist, fvs) ->
371     returnM (TuplePat patslist boxed, fvs `addOneFV` tycon_name)
372   where
373     tup_size   = length pats
374     tycon_name = tupleTyCon_name boxed tup_size
375
376 rnPat (TypePat name) =
377     rnHsTypeFVs (text "In a type pattern") name `thenM` \ (name', fvs) ->
378     returnM (TypePat name', fvs)
379
380 ------------------------------
381 rnConPat con (PrefixCon pats)
382   = lookupOccRn con     `thenM` \ con' ->
383     rnPats pats         `thenM` \ (pats', fvs) ->
384     returnM (ConPatIn con' (PrefixCon pats'), fvs `addOneFV` con')
385
386 rnConPat con (RecCon rpats)
387   = lookupOccRn con     `thenM` \ con' ->
388     rnRpats rpats       `thenM` \ (rpats', fvs) ->
389     returnM (ConPatIn con' (RecCon rpats'), fvs `addOneFV` con')
390
391 rnConPat con (InfixCon pat1 pat2)
392   = lookupOccRn con                             `thenM` \ con' ->
393     rnPat pat1                                  `thenM` \ (pat1', fvs1) ->
394     rnPat pat2                                  `thenM` \ (pat2', fvs2) ->
395     lookupFixityRn con'                         `thenM` \ fixity ->
396     mkConOpPatRn con' fixity pat1' pat2'        `thenM` \ pat' ->
397     returnM (pat', fvs1 `plusFV` fvs2 `addOneFV` con')
398
399 ------------------------
400 rnRpats rpats
401   = mappM_ field_dup_err dup_fields     `thenM_`
402     mapFvRn rn_rpat rpats               `thenM` \ (rpats', fvs) ->
403     returnM (rpats', fvs)
404   where
405     (_, dup_fields) = removeDups compare [ f | (f,_) <- rpats ]
406
407     field_dup_err dups = addErr (dupFieldErr "pattern" dups)
408
409     rn_rpat (field, pat)
410       = lookupGlobalOccRn field `thenM` \ fieldname ->
411         rnPat pat               `thenM` \ (pat', fvs) ->
412         returnM ((fieldname, pat'), fvs `addOneFV` fieldname)
413 \end{code}
414
415 \begin{code}
416 mkConOpPatRn :: Name -> Fixity -> RenamedPat -> RenamedPat
417              -> RnM RenamedPat
418
419 mkConOpPatRn op2 fix2 p1@(ConPatIn op1 (InfixCon p11 p12)) p2
420   = lookupFixityRn op1          `thenM` \ fix1 ->
421     let
422         (nofix_error, associate_right) = compareFixity fix1 fix2
423     in
424     if nofix_error then
425         addErr (precParseErr (ppr_op op1,fix1) (ppr_op op2,fix2))       `thenM_`
426         returnM (ConPatIn op2 (InfixCon p1 p2))
427     else 
428     if associate_right then
429         mkConOpPatRn op2 fix2 p12 p2            `thenM` \ new_p ->
430         returnM (ConPatIn op1 (InfixCon p11 new_p))
431     else
432     returnM (ConPatIn op2 (InfixCon p1 p2))
433
434 mkConOpPatRn op fix p1 p2                       -- Default case, no rearrangment
435   = ASSERT( not_op_pat p2 )
436     returnM (ConPatIn op (InfixCon p1 p2))
437
438 not_op_pat (ConPatIn _ (InfixCon _ _)) = False
439 not_op_pat other                       = True
440 \end{code}
441
442
443 %************************************************************************
444 %*                                                                      *
445 \subsubsection{Literals}
446 %*                                                                      *
447 %************************************************************************
448
449 When literals occur we have to make sure
450 that the types and classes they involve
451 are made available.
452
453 \begin{code}
454 litFVs (HsChar c)
455    = checkErr (inCharRange c) (bogusCharError c) `thenM_`
456      returnM (unitFV charTyCon_name)
457
458 litFVs (HsCharPrim c)         = returnM (unitFV (getName charPrimTyCon))
459 litFVs (HsString s)           = returnM (mkFVs [listTyCon_name, charTyCon_name])
460 litFVs (HsStringPrim s)       = returnM (unitFV (getName addrPrimTyCon))
461 litFVs (HsInt i)              = returnM (unitFV (getName intTyCon))
462 litFVs (HsIntPrim i)          = returnM (unitFV (getName intPrimTyCon))
463 litFVs (HsFloatPrim f)        = returnM (unitFV (getName floatPrimTyCon))
464 litFVs (HsDoublePrim d)       = returnM (unitFV (getName doublePrimTyCon))
465 litFVs lit                    = pprPanic "RnExpr.litFVs" (ppr lit)      -- HsInteger and HsRat only appear 
466                                                                         -- in post-typechecker translations
467 bogusCharError c
468   = ptext SLIT("character literal out of range: '\\") <> int c <> char '\''
469
470 rnOverLit (HsIntegral i _)
471   = lookupSyntaxName fromIntegerName    `thenM` \ (from_integer_name, fvs) ->
472     if inIntRange i then
473         returnM (HsIntegral i from_integer_name, fvs)
474     else let
475         extra_fvs = mkFVs [plusIntegerName, timesIntegerName]
476         -- Big integer literals are built, using + and *, 
477         -- out of small integers (DsUtils.mkIntegerLit)
478         -- [NB: plusInteger, timesInteger aren't rebindable... 
479         --      they are used to construct the argument to fromInteger, 
480         --      which is the rebindable one.]
481     in
482     returnM (HsIntegral i from_integer_name, fvs `plusFV` extra_fvs)
483
484 rnOverLit (HsFractional i _)
485   = lookupSyntaxName fromRationalName           `thenM` \ (from_rat_name, fvs) ->
486     let
487         extra_fvs = mkFVs [ratioDataConName, plusIntegerName, timesIntegerName]
488         -- We have to make sure that the Ratio type is imported with
489         -- its constructor, because literals of type Ratio t are
490         -- built with that constructor.
491         -- The Rational type is needed too, but that will come in
492         -- as part of the type for fromRational.
493         -- The plus/times integer operations may be needed to construct the numerator
494         -- and denominator (see DsUtils.mkIntegerLit)
495     in
496     returnM (HsFractional i from_rat_name, fvs `plusFV` extra_fvs)
497 \end{code}
498
499
500
501 %*********************************************************
502 %*                                                      *
503 \subsection{Errors}
504 %*                                                      *
505 %*********************************************************
506
507 \begin{code}
508 checkTupSize :: Int -> RnM ()
509 checkTupSize tup_size
510   | tup_size <= mAX_TUPLE_SIZE 
511   = returnM ()
512   | otherwise                  
513   = addErr (sep [ptext SLIT("A") <+> int tup_size <> ptext SLIT("-tuple is too large for GHC"),
514                  nest 2 (parens (ptext SLIT("max size is") <+> int mAX_TUPLE_SIZE)),
515                  nest 2 (ptext SLIT("Workaround: use nested tuples or define a data type"))])
516
517 forAllWarn doc ty tyvar
518   = ifOptM Opt_WarnUnusedMatches        $
519     addWarn (sep [ptext SLIT("The universally quantified type variable") <+> quotes (ppr tyvar),
520                    nest 4 (ptext SLIT("does not appear in the type") <+> quotes (ppr ty))]
521                    $$
522                    doc
523                 )
524
525 precParseErr op1 op2 
526   = hang (ptext SLIT("precedence parsing error"))
527       4 (hsep [ptext SLIT("cannot mix"), ppr_opfix op1, ptext SLIT("and"), 
528                ppr_opfix op2,
529                ptext SLIT("in the same infix expression")])
530
531 sectionPrecErr op arg_op section
532  = vcat [ptext SLIT("The operator") <+> ppr_opfix op <+> ptext SLIT("of a section"),
533          nest 4 (ptext SLIT("must have lower precedence than the operand") <+> ppr_opfix arg_op),
534          nest 4 (ptext SLIT("in the section:") <+> quotes (ppr section))]
535
536 infixTyConWarn op
537   = ftext FSLIT("Accepting non-standard infix type constructor") <+> quotes (ppr op)
538
539 patSigErr ty
540   =  (ptext SLIT("Illegal signature in pattern:") <+> ppr ty)
541         $$ nest 4 (ptext SLIT("Use -fglasgow-exts to permit it"))
542
543 dupFieldErr str (dup:rest)
544   = hsep [ptext SLIT("duplicate field name"), 
545           quotes (ppr dup),
546           ptext SLIT("in record"), text str]
547
548 ppr_op op = quotes (ppr op)     -- Here, op can be a Name or a (Var n), where n is a Name
549 ppr_opfix (pp_op, fixity) = pp_op <+> brackets (ppr fixity)
550 \end{code}