2 % (c) The University of Glasgow 2006
3 % (c) The GRASP/AQUA Project, Glasgow University, 1998
5 \section[TypeRep]{Type - friends' interface}
8 -- We expose the relevant stuff from this module via the Type module
9 {-# OPTIONS_HADDOCK hide #-}
10 {-# LANGUAGE DeriveDataTypeable, DeriveFunctor, DeriveFoldable, DeriveTraversable #-}
14 Pred(..), -- to friends
17 PredType, ThetaType, -- Synonyms
19 -- Functions over types
20 mkTyConApp, mkTyConTy, mkTyVarTy, mkTyVarTys,
21 isLiftedTypeKind, isCoercionKind,
24 pprType, pprParendType, pprTypeApp,
25 pprTyThing, pprTyThingCategory,
26 pprPredTy, pprEqPred, pprTheta, pprForAll, pprThetaArrowTy, pprClassPred,
27 pprKind, pprParendKind,
28 Prec(..), maybeParen, pprTcApp, pprTypeNameApp,
29 pprPrefixApp, pprPred, pprArrowChain, pprThetaArrow,
32 tyVarsOfType, tyVarsOfTypes,
33 tyVarsOfPred, tyVarsOfTheta,
34 varsOfPred, varsOfTheta,
38 TvSubst(..), TvSubstEnv
41 #include "HsVersions.h"
43 import {-# SOURCE #-} DataCon( DataCon, dataConName )
61 import qualified Data.Data as Data hiding ( TyCon )
62 import qualified Data.Foldable as Data
63 import qualified Data.Traversable as Data
66 ----------------------
68 ----------------------
73 Then we want N to be represented as an Int, and that's what we arrange.
74 The front end of the compiler [TcType.lhs] treats N as opaque,
75 the back end treats it as transparent [Type.lhs].
77 There's a bit of a problem with recursive newtypes
79 newtype Q = MkQ (Q->Q)
81 Here the 'implicit expansion' we get from treating P and Q as transparent
82 would give rise to infinite types, which in turn makes eqType diverge.
83 Similarly splitForAllTys and splitFunTys can get into a loop.
87 * Newtypes are always represented using TyConApp.
89 * For non-recursive newtypes, P, treat P just like a type synonym after
90 type-checking is done; i.e. it's opaque during type checking (functions
91 from TcType) but transparent afterwards (functions from Type).
92 "Treat P as a type synonym" means "all functions expand NewTcApps
95 Applications of the data constructor P simply vanish:
99 * For recursive newtypes Q, treat the Q and its representation as
100 distinct right through the compiler. Applications of the data consructor
102 Q = \(x::Q->Q). coerce Q x
103 They are rare, so who cares if they are a tiny bit less efficient.
105 The typechecker (TcTyDecls) identifies enough type construtors as 'recursive'
106 to cut all loops. The other members of the loop may be marked 'non-recursive'.
109 %************************************************************************
111 \subsection{The data type}
113 %************************************************************************
117 -- | The key representation of types within the compiler
119 = TyVarTy TyVar -- ^ Vanilla type variable (*never* a coercion variable)
123 Type -- ^ Type application to something other than a 'TyCon'. Parameters:
125 -- 1) Function: must /not/ be a 'TyConApp',
126 -- must be another 'AppTy', or 'TyVarTy'
132 [Type] -- ^ Application of a 'TyCon', including newtypes /and/ synonyms.
133 -- Invariant: saturated appliations of 'FunTyCon' must
134 -- use 'FunTy' and saturated synonyms must use their own
135 -- constructors. However, /unsaturated/ 'FunTyCon's
136 -- do appear as 'TyConApp's.
139 -- 1) Type constructor being applied to.
141 -- 2) Type arguments. Might not have enough type arguments
142 -- here to saturate the constructor.
143 -- Even type synonyms are not necessarily saturated;
144 -- for example unsaturated type synonyms
145 -- can appear as the right hand side of a type synonym.
149 Type -- ^ Special case of 'TyConApp': @TyConApp FunTyCon [t1, t2]@
152 TyCoVar -- ^ Type *or* coercion variable; see Note [Equality-constrained types]
153 Type -- ^ A polymorphic type
156 PredType -- ^ The type of evidence for a type predictate.
157 -- Note that a @PredTy (EqPred _ _)@ can appear only as the kind
158 -- of a coercion variable; never as the argument or result of a
159 -- 'FunTy' (unlike the 'PredType' constructors 'ClassP' or 'IParam')
161 -- See Note [PredTy], and Note [Equality predicates]
162 deriving (Data.Data, Data.Typeable)
164 -- | The key type representing kinds in the compiler.
165 -- Invariant: a kind is always in one of these forms:
168 -- > TyConApp PrimTyCon [...]
169 -- > TyVar kv -- (during inference only)
170 -- > ForAll ... -- (for top-level coercions)
173 -- | "Super kinds", used to help encode 'Kind's as types.
174 -- Invariant: a super kind is always of this form:
176 -- > TyConApp SuperKindTyCon ...
177 type SuperKind = Type
180 Note [Equality-constrained types]
181 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
182 The type forall ab. (a ~ [b]) => blah
183 is encoded like this:
185 ForAllTy (a:*) $ ForAllTy (b:*) $
186 ForAllTy (wild_co : a ~ [b]) $
189 That is, the "(a ~ [b]) =>" part is encode as a for-all
190 type with a coercion variable that is never mentioned.
192 We could instead have used a FunTy with an EqPred on the
195 * FunTy to mean RUN-TIME abstraction,
196 passing a real value at runtime,
198 * ForAllTy to mean COMPILE-TIME abstraction,
201 -------------------------------------
205 -- | A type of the form @PredTy p@ represents a value whose type is
206 -- the Haskell predicate @p@, where a predicate is what occurs before
207 -- the @=>@ in a Haskell type.
208 -- It can be expanded into its representation, but:
210 -- * The type checker must treat it as opaque
212 -- * The rest of the compiler treats it as transparent
214 -- Consider these examples:
216 -- > f :: (Eq a) => a -> Int
217 -- > g :: (?x :: Int -> Int) => a -> Int
218 -- > h :: (r\l) => {r} => {l::Int | r}
220 -- Here the @Eq a@ and @?x :: Int -> Int@ and @r\l@ are all called \"predicates\"
221 type PredType = Pred Type
223 data Pred a -- Typically 'a' is instantiated with Type or Coercion
224 = ClassP Class [a] -- ^ Class predicate e.g. @Eq a@
225 | IParam (IPName Name) a -- ^ Implicit parameter e.g. @?x :: Int@
226 | EqPred a a -- ^ Equality predicate e.g @ty1 ~ ty2@
227 deriving (Data.Data, Data.Typeable, Data.Foldable, Data.Traversable, Functor)
229 -- | A collection of 'PredType's
230 type ThetaType = [PredType]
233 (We don't support TREX records yet, but the setup is designed
234 to expand to allow them.)
236 A Haskell qualified type, such as that for f,g,h above, is
238 * a FunTy for the double arrow
239 * with a PredTy as the function argument
241 The predicate really does turn into a real extra argument to the
242 function. If the argument has type (PredTy p) then the predicate p is
243 represented by evidence (a dictionary, for example, of type (predRepTy p).
245 Note [Equality predicates]
246 ~~~~~~~~~~~~~~~~~~~~~~~~~~
247 forall a b. (a ~ S b) => a -> b
248 could be represented by
249 ForAllTy a (ForAllTy b (FunTy (PredTy (EqPred a (S b))) ...))
251 ForAllTy a (ForAllTy b (ForAllTy (c::PredTy (EqPred a (S b))) ...))
253 The latter is what we do. (Unlike for class and implicit parameter
254 constraints, which do use FunTy.)
257 * FunTy is always a *value* function
258 * ForAllTy is discarded at runtime
260 We often need to make a "wildcard" (c::PredTy..). We always use the same
261 name (wildCoVarName), since it's not mentioned.
264 %************************************************************************
268 %************************************************************************
270 These functions are here so that they can be used by TysPrim,
271 which in turn is imported by Type
274 mkTyVarTy :: TyVar -> Type
277 mkTyVarTys :: [TyVar] -> [Type]
278 mkTyVarTys = map mkTyVarTy -- a common use of mkTyVarTy
280 -- | A key function: builds a 'TyConApp' or 'FunTy' as apppropriate to its arguments.
281 -- Applies its arguments to the constructor from left to right
282 mkTyConApp :: TyCon -> [Type] -> Type
284 | isFunTyCon tycon, [ty1,ty2] <- tys
290 -- | Create the plain type constructor type which has been applied to no type arguments at all.
291 mkTyConTy :: TyCon -> Type
292 mkTyConTy tycon = mkTyConApp tycon []
294 isLiftedTypeKind :: Kind -> Bool
295 -- This function is here because it's used in the pretty printer
296 isLiftedTypeKind (TyConApp tc []) = tc `hasKey` liftedTypeKindTyConKey
297 isLiftedTypeKind _ = False
299 isCoercionKind :: Kind -> Bool
300 -- All coercions are of form (ty1 ~ ty2)
301 -- This function is here rather than in Coercion, because it
302 -- is used in a knot-tied way to enforce invariants in Var
303 isCoercionKind (PredTy (EqPred {})) = True
304 isCoercionKind _ = False
308 %************************************************************************
310 Free variables of types and coercions
312 %************************************************************************
315 tyVarsOfPred :: PredType -> TyCoVarSet
316 tyVarsOfPred = varsOfPred tyVarsOfType
318 tyVarsOfTheta :: ThetaType -> TyCoVarSet
319 tyVarsOfTheta = varsOfTheta tyVarsOfType
321 tyVarsOfType :: Type -> VarSet
322 -- ^ NB: for type synonyms tyVarsOfType does /not/ expand the synonym
323 tyVarsOfType (TyVarTy v) = unitVarSet v
324 tyVarsOfType (TyConApp _ tys) = tyVarsOfTypes tys
325 tyVarsOfType (PredTy sty) = varsOfPred tyVarsOfType sty
326 tyVarsOfType (FunTy arg res) = tyVarsOfType arg `unionVarSet` tyVarsOfType res
327 tyVarsOfType (AppTy fun arg) = tyVarsOfType fun `unionVarSet` tyVarsOfType arg
328 tyVarsOfType (ForAllTy tyvar ty) = delVarSet (tyVarsOfType ty) tyvar
330 tyVarsOfTypes :: [Type] -> TyVarSet
331 tyVarsOfTypes tys = foldr (unionVarSet . tyVarsOfType) emptyVarSet tys
333 varsOfPred :: (a -> VarSet) -> Pred a -> VarSet
334 varsOfPred f (IParam _ ty) = f ty
335 varsOfPred f (ClassP _ tys) = foldr (unionVarSet . f) emptyVarSet tys
336 varsOfPred f (EqPred ty1 ty2) = f ty1 `unionVarSet` f ty2
338 varsOfTheta :: (a -> VarSet) -> [Pred a] -> VarSet
339 varsOfTheta f = foldr (unionVarSet . varsOfPred f) emptyVarSet
341 predSize :: (a -> Int) -> Pred a -> Int
342 predSize size (IParam _ t) = 1 + size t
343 predSize size (ClassP _ ts) = 1 + sum (map size ts)
344 predSize size (EqPred t1 t2) = size t1 + size t2
347 %************************************************************************
351 %************************************************************************
353 Despite the fact that DataCon has to be imported via a hi-boot route,
354 this module seems the right place for TyThing, because it's needed for
355 funTyCon and all the types in TysPrim.
358 -- | A typecheckable-thing, essentially anything that has a name
359 data TyThing = AnId Id
365 instance Outputable TyThing where
368 pprTyThing :: TyThing -> SDoc
369 pprTyThing thing = pprTyThingCategory thing <+> quotes (ppr (getName thing))
371 pprTyThingCategory :: TyThing -> SDoc
372 pprTyThingCategory (ATyCon _) = ptext (sLit "Type constructor")
373 pprTyThingCategory (ACoAxiom _) = ptext (sLit "Coercion axiom")
374 pprTyThingCategory (AClass _) = ptext (sLit "Class")
375 pprTyThingCategory (AnId _) = ptext (sLit "Identifier")
376 pprTyThingCategory (ADataCon _) = ptext (sLit "Data constructor")
378 instance NamedThing TyThing where -- Can't put this with the type
379 getName (AnId id) = getName id -- decl, because the DataCon instance
380 getName (ATyCon tc) = getName tc -- isn't visible there
381 getName (ACoAxiom cc) = getName cc
382 getName (AClass cl) = getName cl
383 getName (ADataCon dc) = dataConName dc
387 %************************************************************************
390 Data type defined here to avoid unnecessary mutual recursion
392 %************************************************************************
395 -- | Type substitution
397 -- #tvsubst_invariant#
398 -- The following invariants must hold of a 'TvSubst':
400 -- 1. The in-scope set is needed /only/ to
401 -- guide the generation of fresh uniques
403 -- 2. In particular, the /kind/ of the type variables in
404 -- the in-scope set is not relevant
406 -- 3. The substition is only applied ONCE! This is because
407 -- in general such application will not reached a fixed point.
409 = TvSubst InScopeSet -- The in-scope type variables
410 TvSubstEnv -- Substitution of types
411 -- See Note [Apply Once]
412 -- and Note [Extending the TvSubstEnv]
414 -- | A substitition of 'Type's for 'TyVar's
415 type TvSubstEnv = TyVarEnv Type
416 -- A TvSubstEnv is used both inside a TvSubst (with the apply-once
417 -- invariant discussed in Note [Apply Once]), and also independently
418 -- in the middle of matching, and unification (see Types.Unify)
419 -- So you have to look at the context to know if it's idempotent or
420 -- apply-once or whatever
425 We use TvSubsts to instantiate things, and we might instantiate
429 So the substition might go [a->b, b->a]. A similar situation arises in Core
430 when we find a beta redex like
432 Then we also end up with a substition that permutes type variables. Other
433 variations happen to; for example [a -> (a, b)].
435 ***************************************************
436 *** So a TvSubst must be applied precisely once ***
437 ***************************************************
439 A TvSubst is not idempotent, but, unlike the non-idempotent substitution
440 we use during unifications, it must not be repeatedly applied.
442 Note [Extending the TvSubst]
443 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
444 See #tvsubst_invariant# for the invariants that must hold.
446 This invariant allows a short-cut when the TvSubstEnv is empty:
447 if the TvSubstEnv is empty --- i.e. (isEmptyTvSubt subst) holds ---
448 then (substTy subst ty) does nothing.
450 For example, consider:
451 (/\a. /\b:(a~Int). ...b..) Int
452 We substitute Int for 'a'. The Unique of 'b' does not change, but
453 nevertheless we add 'b' to the TvSubstEnv, because b's kind does change
455 This invariant has several crucial consequences:
457 * In substTyVarBndr, we need extend the TvSubstEnv
458 - if the unique has changed
459 - or if the kind has changed
461 * In substTyVar, we do not need to consult the in-scope set;
462 the TvSubstEnv is enough
464 * In substTy, substTheta, we can short-circuit when the TvSubstEnv is empty
469 %************************************************************************
471 Pretty-printing types
473 Defined very early because of debug printing in assertions
475 %************************************************************************
477 @pprType@ is the standard @Type@ printer; the overloaded @ppr@ function is
478 defined to use this. @pprParendType@ is the same, except it puts
479 parens around the type, except for the atomic cases. @pprParendType@
480 works just by setting the initial context precedence very high.
483 data Prec = TopPrec -- No parens
484 | FunPrec -- Function args; no parens for tycon apps
485 | TyConPrec -- Tycon args; no parens for atomic
488 maybeParen :: Prec -> Prec -> SDoc -> SDoc
489 maybeParen ctxt_prec inner_prec pretty
490 | ctxt_prec < inner_prec = pretty
491 | otherwise = parens pretty
494 pprType, pprParendType :: Type -> SDoc
495 pprType ty = ppr_type TopPrec ty
496 pprParendType ty = ppr_type TyConPrec ty
498 pprKind, pprParendKind :: Kind -> SDoc
500 pprParendKind = pprParendType
503 pprPredTy :: PredType -> SDoc
504 pprPredTy = pprPred ppr_type
506 pprPred :: (Prec -> a -> SDoc) -> Pred a -> SDoc
507 pprPred pp (ClassP cls tys) = ppr_class_pred pp cls tys
508 pprPred pp (IParam ip ty) = ppr ip <> dcolon <> pp TopPrec ty
509 pprPred pp (EqPred ty1 ty2) = ppr_eq_pred pp (Pair ty1 ty2)
512 pprEqPred :: Pair Type -> SDoc
513 pprEqPred = ppr_eq_pred ppr_type
515 ppr_eq_pred :: (Prec -> a -> SDoc) -> Pair a -> SDoc
516 ppr_eq_pred pp (Pair ty1 ty2) = sep [ pp FunPrec ty1
517 , nest 2 (ptext (sLit "~"))
519 -- Precedence looks like (->) so that we get
522 -- Note parens on the latter!
525 pprClassPred :: Class -> [Type] -> SDoc
526 pprClassPred = ppr_class_pred ppr_type
528 ppr_class_pred :: (Prec -> a -> SDoc) -> Class -> [a] -> SDoc
529 ppr_class_pred pp clas tys = pprTypeNameApp TopPrec pp (getName clas) tys
532 pprTheta :: ThetaType -> SDoc
533 -- pprTheta [pred] = pprPred pred -- I'm in two minds about this
534 pprTheta theta = parens (sep (punctuate comma (map pprPredTy theta)))
536 pprThetaArrowTy :: ThetaType -> SDoc
537 pprThetaArrowTy = pprThetaArrow ppr_type
539 pprThetaArrow :: (Prec -> a -> SDoc) -> [Pred a] -> SDoc
540 pprThetaArrow _ [] = empty
541 pprThetaArrow pp [pred]
542 | noParenPred pred = pprPred pp pred <+> darrow
543 pprThetaArrow pp preds = parens (sep (punctuate comma (map (pprPred pp) preds)))
546 noParenPred :: Pred a -> Bool
547 -- A predicate that can appear without parens before a "=>"
550 -- But (?x::Int) => Int -> Int
551 noParenPred (ClassP {}) = True
552 noParenPred (EqPred {}) = True
553 noParenPred (IParam {}) = False
556 instance Outputable Type where
559 instance Outputable (Pred Type) where
560 ppr = pprPredTy -- Not for arbitrary (Pred a), because the
561 -- (Outputable a) doesn't give precedence
563 instance Outputable name => OutputableBndr (IPName name) where
564 pprBndr _ n = ppr n -- Simple for now
567 -- OK, here's the main printer
569 ppr_type :: Prec -> Type -> SDoc
570 ppr_type _ (TyVarTy tv) = ppr_tvar tv
571 ppr_type p (PredTy pred) = maybeParen p TyConPrec $
572 ifPprDebug (ptext (sLit "<pred>")) <> (pprPredTy pred)
573 ppr_type p (TyConApp tc tys) = pprTcApp p ppr_type tc tys
575 ppr_type p (AppTy t1 t2) = maybeParen p TyConPrec $
576 pprType t1 <+> ppr_type TyConPrec t2
578 ppr_type p ty@(ForAllTy {}) = ppr_forall_type p ty
579 ppr_type p ty@(FunTy (PredTy _) _) = ppr_forall_type p ty
581 ppr_type p (FunTy ty1 ty2)
582 = pprArrowChain p (ppr_type FunPrec ty1 : ppr_fun_tail ty2)
584 -- We don't want to lose synonyms, so we mustn't use splitFunTys here.
585 ppr_fun_tail (FunTy ty1 ty2)
586 | not (is_pred ty1) = ppr_type FunPrec ty1 : ppr_fun_tail ty2
587 ppr_fun_tail other_ty = [ppr_type TopPrec other_ty]
589 is_pred (PredTy {}) = True
592 ppr_forall_type :: Prec -> Type -> SDoc
594 = maybeParen p FunPrec $
595 sep [pprForAll tvs, pprThetaArrowTy ctxt, pprType tau]
597 (tvs, rho) = split1 [] ty
598 (ctxt, tau) = split2 [] rho
600 split1 tvs (ForAllTy tv ty) = split1 (tv:tvs) ty
601 split1 tvs ty = (reverse tvs, ty)
603 split2 ps (PredTy p `FunTy` ty) = split2 (p:ps) ty
604 split2 ps ty = (reverse ps, ty)
606 ppr_tc_app :: Prec -> TyCon -> [Type] -> SDoc
610 | tc `hasKey` listTyConKey = brackets (pprType ty)
611 | tc `hasKey` parrTyConKey = ptext (sLit "[:") <> pprType ty <> ptext (sLit ":]")
612 | tc `hasKey` liftedTypeKindTyConKey = ptext (sLit "*")
613 | tc `hasKey` unliftedTypeKindTyConKey = ptext (sLit "#")
614 | tc `hasKey` openTypeKindTyConKey = ptext (sLit "(?)")
615 | tc `hasKey` ubxTupleKindTyConKey = ptext (sLit "(#)")
616 | tc `hasKey` argTypeKindTyConKey = ptext (sLit "??")
619 | isTupleTyCon tc && tyConArity tc == length tys
620 = tupleParens (tupleTyConBoxity tc) (sep (punctuate comma (map pprType tys)))
622 = ppr_type_app p (getName tc) tys
624 ppr_type_app :: Prec -> Name -> [Type] -> SDoc
625 -- Used for classes as well as types; that's why it's separate from ppr_tc_app
626 ppr_type_app p tc tys
627 | is_sym_occ -- Print infix if possible
628 , [ty1,ty2] <- tys -- We know nothing of precedence though
629 = maybeParen p FunPrec (sep [ppr_type FunPrec ty1,
630 pprInfixVar True (ppr tc) <+> ppr_type FunPrec ty2])
632 = maybeParen p TyConPrec (hang (pprPrefixVar is_sym_occ (ppr tc))
633 2 (sep (map pprParendType tys)))
635 is_sym_occ = isSymOcc (getOccName tc)
637 ppr_tc :: TyCon -> SDoc -- No brackets for SymOcc
639 = pp_nt_debug <> ppr tc
641 pp_nt_debug | isNewTyCon tc = ifPprDebug (if isRecursiveTyCon tc
642 then ptext (sLit "<recnt>")
643 else ptext (sLit "<nt>"))
646 ppr_tvar :: TyVar -> SDoc
647 ppr_tvar tv -- Note [Infix type variables]
648 | isSymOcc (getOccName tv) = parens (ppr tv)
652 pprForAll :: [TyVar] -> SDoc
654 pprForAll tvs = ptext (sLit "forall") <+> sep (map pprTvBndr tvs) <> dot
656 pprTvBndr :: TyVar -> SDoc
658 | isLiftedTypeKind kind = ppr_tvar tv
659 | otherwise = parens (ppr_tvar tv <+> dcolon <+> pprKind kind)
664 Note [Infix type variables]
665 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
666 With TypeOperators you can say
670 and the (~>) is considered a type variable. However, the type
671 pretty-printer in this module will just see (a ~> b) as
673 App (App (TyVarTy "~>") (TyVarTy "a")) (TyVarTy "b")
675 So it'll print the type in prefix form. To avoid confusion we must
676 remember to parenthesise the operator, thus
683 pprTcApp :: Prec -> (Prec -> a -> SDoc) -> TyCon -> [a] -> SDoc
684 pprTcApp _ _ tc [] -- No brackets for SymOcc
685 = pp_nt_debug <> ppr tc
687 pp_nt_debug | isNewTyCon tc = ifPprDebug (if isRecursiveTyCon tc
688 then ptext (sLit "<recnt>")
689 else ptext (sLit "<nt>"))
692 pprTcApp _ pp tc [ty]
693 | tc `hasKey` listTyConKey = brackets (pp TopPrec ty)
694 | tc `hasKey` parrTyConKey = ptext (sLit "[:") <> pp TopPrec ty <> ptext (sLit ":]")
695 | tc `hasKey` liftedTypeKindTyConKey = ptext (sLit "*")
696 | tc `hasKey` unliftedTypeKindTyConKey = ptext (sLit "#")
697 | tc `hasKey` openTypeKindTyConKey = ptext (sLit "(?)")
698 | tc `hasKey` ubxTupleKindTyConKey = ptext (sLit "(#)")
699 | tc `hasKey` argTypeKindTyConKey = ptext (sLit "??")
702 | isTupleTyCon tc && tyConArity tc == length tys
703 = tupleParens (tupleTyConBoxity tc) (sep (punctuate comma (map (pp TopPrec) tys)))
705 = pprTypeNameApp p pp (getName tc) tys
708 pprTypeApp :: NamedThing a => a -> [Type] -> SDoc
709 -- The first arg is the tycon, or sometimes class
710 -- Print infix if the tycon/class looks like an operator
711 pprTypeApp tc tys = pprTypeNameApp TopPrec ppr_type (getName tc) tys
713 pprTypeNameApp :: Prec -> (Prec -> a -> SDoc) -> Name -> [a] -> SDoc
714 -- Used for classes and coercions as well as types; that's why it's separate from pprTcApp
715 pprTypeNameApp p pp tc tys
716 | is_sym_occ -- Print infix if possible
717 , [ty1,ty2] <- tys -- We know nothing of precedence though
718 = maybeParen p FunPrec $
719 sep [pp FunPrec ty1, pprInfixVar True (ppr tc) <+> pp FunPrec ty2]
721 = pprPrefixApp p (pprPrefixVar is_sym_occ (ppr tc)) (map (pp TyConPrec) tys)
723 is_sym_occ = isSymOcc (getOccName tc)
726 pprPrefixApp :: Prec -> SDoc -> [SDoc] -> SDoc
727 pprPrefixApp p pp_fun pp_tys = maybeParen p TyConPrec $
728 hang pp_fun 2 (sep pp_tys)
731 pprArrowChain :: Prec -> [SDoc] -> SDoc
732 -- pprArrowChain p [a,b,c] generates a -> b -> c
733 pprArrowChain _ [] = empty
734 pprArrowChain p (arg:args) = maybeParen p FunPrec $
735 sep [arg, sep (map (arrow <+>) args)]