pprLExpr (L _ e) = pprExpr e
pprExpr :: OutputableBndr id => HsExpr id -> SDoc
-pprExpr e | isAtomicHsExpr e = ppr_expr e -- Never replace 'x' by "..."
- | otherwise = pprDeeper (ppr_expr e)
+pprExpr e | isAtomicHsExpr e || isQuietHsExpr e = ppr_expr e
+ | otherwise = pprDeeper (ppr_expr e)
+
+isQuietHsExpr :: HsExpr id -> Bool
+-- Parentheses do display something, but it gives little info and
+-- if we go deeper when we go inside them then we get ugly things
+-- like (...)
+isQuietHsExpr (HsPar _) = True
+-- applications don't display anything themselves
+isQuietHsExpr (HsApp _ _) = True
+isQuietHsExpr (OpApp _ _ _ _) = True
+isQuietHsExpr _ = False
pprBinds :: OutputableBndr id => HsLocalBinds id -> SDoc
pprBinds b = pprDeeper (ppr b)
-- I think that is usually (always?) right
in
case unLoc expr of
- HsLit l -> pp_as_was
- HsOverLit l -> pp_as_was
- HsVar _ -> pp_as_was
- HsIPVar _ -> pp_as_was
- ExplicitList _ _ -> pp_as_was
- ExplicitPArr _ _ -> pp_as_was
- ExplicitTuple _ _ -> pp_as_was
- HsPar _ -> pp_as_was
- HsBracket _ -> pp_as_was
- HsBracketOut _ [] -> pp_as_was
- _ -> parens pp_as_was
+ HsLit l -> pp_as_was
+ HsOverLit l -> pp_as_was
+ HsVar _ -> pp_as_was
+ HsIPVar _ -> pp_as_was
+ ExplicitList _ _ -> pp_as_was
+ ExplicitPArr _ _ -> pp_as_was
+ ExplicitTuple _ _ -> pp_as_was
+ HsPar _ -> pp_as_was
+ HsBracket _ -> pp_as_was
+ HsBracketOut _ [] -> pp_as_was
+ HsDo sc _ _ _
+ | isListCompExpr sc -> pp_as_was
+ _ -> parens pp_as_was
isAtomicHsExpr :: HsExpr id -> Bool -- A single token
isAtomicHsExpr (HsVar {}) = True
pprGRHSs :: OutputableBndr id => HsMatchContext id -> GRHSs id -> SDoc
pprGRHSs ctxt (GRHSs grhss binds)
- = pprDeeper
- (vcat (map (pprGRHS ctxt . unLoc) grhss)
- $$
- if isEmptyLocalBinds binds then empty
- else text "where" $$ nest 4 (pprBinds binds))
+ = vcat (map (pprGRHS ctxt . unLoc) grhss)
+ $$ if isEmptyLocalBinds binds then empty
+ else text "where" $$ nest 4 (pprBinds binds)
pprGRHS :: OutputableBndr id => HsMatchContext id -> GRHS id -> SDoc
isDoExpr :: HsStmtContext id -> Bool
isDoExpr DoExpr = True
isDoExpr (MDoExpr _) = True
-isDoExpr other = False
+isDoExpr _ = False
+
+isListCompExpr :: HsStmtContext id -> Bool
+isListCompExpr ListComp = True
+isListCompExpr PArrComp = True
+isListCompExpr _ = False
\end{code}
\begin{code}