diff options
| author | simonpj@microsoft.com <unknown> | 2008-11-26 13:22:02 +0000 |
|---|---|---|
| committer | simonpj@microsoft.com <unknown> | 2008-11-26 13:22:02 +0000 |
| commit | 3256860dc70f3a4fbd953c858ec500d70a9be820 (patch) | |
| tree | 06fbffe0bc9c1104016042b012c324fa94a7ec0d /compiler | |
| parent | ea9fe633d8eb7e986832519e3d4923a6e694ebbb (diff) | |
| download | haskell-3256860dc70f3a4fbd953c858ec500d70a9be820.tar.gz | |
Fix Trac #2766: printing operator type variables
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/types/TypeRep.lhs | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/compiler/types/TypeRep.lhs b/compiler/types/TypeRep.lhs index 52e12bf56b..f71606e39b 100644 --- a/compiler/types/TypeRep.lhs +++ b/compiler/types/TypeRep.lhs @@ -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 "<pred>")) <> (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. + + + + |
