From 41288a1d37047b4046f43bb88f8aaf6bdefd8183 Mon Sep 17 00:00:00 2001 From: Simon Peyton Jones Date: Wed, 13 Feb 2013 17:07:26 +0000 Subject: Improve pretty-printing of strict lets with -dppr-case-as-let --- compiler/coreSyn/PprCore.lhs | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'compiler/coreSyn') diff --git a/compiler/coreSyn/PprCore.lhs b/compiler/coreSyn/PprCore.lhs index fa1cde9f76..0ead297eb8 100644 --- a/compiler/coreSyn/PprCore.lhs +++ b/compiler/coreSyn/PprCore.lhs @@ -157,17 +157,13 @@ ppr_expr add_par expr@(App {}) ppr_expr add_par (Case expr var ty [(con,args,rhs)]) = sdocWithDynFlags $ \dflags -> if gopt Opt_PprCaseAsLet dflags - then add_par $ - sep [sep [ ptext (sLit "let") - <+> char '{' - <+> ppr_case_pat con args - <+> ptext (sLit "~") - <+> ppr_bndr var - , ptext (sLit "<-") - <+> ppr_expr id expr - , char '}' - <+> ptext (sLit "in") - ] + then add_par $ -- See Note [Print case as let] + sep [ sep [ ptext (sLit "let! {") + <+> ppr_case_pat con args + <+> ptext (sLit "~") + <+> ppr_bndr var + , ptext (sLit "<-") <+> ppr_expr id expr + <+> ptext (sLit "} in") ] , pprCoreExpr rhs ] else add_par $ @@ -258,6 +254,17 @@ pprArg (Coercion co) = ptext (sLit "@~") <+> pprParendCo co pprArg expr = pprParendExpr expr \end{code} +Note [Print case as let] +~~~~~~~~~~~~~~~~~~~~~~~~ +Single-branch case expressions are very common: + case x of y { I# x' -> + case p of q { I# p' -> ... } } +These are, in effect, just strict let's, with pattern matching. +With -dppr-case-as-let we print them as such: + let! { I# x' ~ y <- x } in + let! { I# p' ~ q <- p } in ... + + Other printing bits-and-bobs used with the general @pprCoreBinding@ and @pprCoreExpr@ functions. -- cgit v1.2.1