X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Ftypes%2FTypeRep.lhs;h=600b731928d81d2eed856a46fbd152b07a5749fc;hb=59fa6266f00b6edcfc20c491c8de9a1b215dfa22;hp=52e12bf56b664c8a83376485230019135606d58a;hpb=125502965ee73734980b19c6cbcc5e6a43a860a8;p=ghc-hetmet.git diff --git a/compiler/types/TypeRep.lhs b/compiler/types/TypeRep.lhs index 52e12bf..600b731 100644 --- a/compiler/types/TypeRep.lhs +++ b/compiler/types/TypeRep.lhs @@ -15,7 +15,7 @@ module TypeRep ( Kind, ThetaType, -- Synonyms - funTyCon, + funTyCon, funTyConName, -- Pretty-printing pprType, pprParendType, pprTypeApp, @@ -462,7 +462,9 @@ pprKind = pprType pprParendKind = pprParendType ppr_type :: Prec -> Type -> SDoc -ppr_type _ (TyVarTy tv) = ppr tv +ppr_type _ (TyVarTy tv) -- Note [Infix type variables] + | isSymOcc (getOccName tv) = parens (ppr tv) + | otherwise = ppr tv ppr_type _ (PredTy pred) = ifPprDebug (ptext (sLit "")) <> (ppr pred) ppr_type p (TyConApp tc tys) = ppr_tc_app p tc tys @@ -553,3 +555,24 @@ pprTvBndr tv | isLiftedTypeKind kind = ppr tv kind = tyVarKind tv \end{code} +Note [Infix type variables] +~~~~~~~~~~~~~~~~~~~~~~~~~~~ +In Haskell 98 you can say + + f :: (a ~> b) -> b + +and the (~>) is considered a type variable. However, the type +pretty-printer in this module will just see (a ~> b) as + + App (App (TyVarTy "~>") (TyVarTy "a")) (TyVarTy "b") + +So it'll print the type in prefix form. To avoid confusion we must +remember to parenthesise the operator, thus + + (~>) a b -> b + +See Trac #2766. + + + +