Commit fc7a2876 authored by simonpj@microsoft.com's avatar simonpj@microsoft.com
Browse files

Don't use unnecessary parens when printing types (Fix Trac 4107)

   f :: Eq a => a -> a
rather than
   f :: (Eq a) => a -> a
parent b562edc6
......@@ -353,8 +353,16 @@ pprHsForAll exp tvs cxt
forall_part = ptext (sLit "forall") <+> interppSP tvs <> dot
pprHsContext :: (OutputableBndr name) => HsContext name -> SDoc
pprHsContext [] = empty
pprHsContext cxt = ppr_hs_context cxt <+> ptext (sLit "=>")
pprHsContext [] = empty
pprHsContext [L _ pred]
| noParenHsPred pred = ppr pred <+> ptext (sLit "=>")
pprHsContext cxt = ppr_hs_context cxt <+> ptext (sLit "=>")
noParenHsPred :: HsPred name -> Bool
-- c.f. TypeRep.noParenPred
noParenHsPred (HsClassP {}) = True
noParenHsPred (HsEqualP {}) = True
noParenHsPred (HsIParam {}) = False
ppr_hs_context :: (OutputableBndr name) => HsContext name -> SDoc
ppr_hs_context [] = empty
......
......@@ -452,9 +452,19 @@ pprTheta :: ThetaType -> SDoc
pprTheta theta = parens (sep (punctuate comma (map pprPred theta)))
pprThetaArrow :: ThetaType -> SDoc
pprThetaArrow theta
| null theta = empty
| otherwise = parens (sep (punctuate comma (map pprPred theta))) <+> ptext (sLit "=>")
pprThetaArrow [] = empty
pprThetaArrow [pred]
| noParenPred pred = pprPred pred <+> ptext (sLit "=>")
pprThetaArrow preds = parens (sep (punctuate comma (map pprPred preds))) <+> ptext (sLit "=>")
noParenPred :: PredType -> Bool
-- A predicate that can appear without parens before a "=>"
-- C a => a -> a
-- a~b => a -> b
-- But (?x::Int) => Int -> Int
noParenPred (ClassP {}) = True
noParenPred (EqPred {}) = True
noParenPred (IParam {}) = False
------------------
instance Outputable Type where
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment