diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2013-02-13 17:07:26 +0000 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2013-02-13 17:07:26 +0000 |
commit | 41288a1d37047b4046f43bb88f8aaf6bdefd8183 (patch) | |
tree | dc95f9075df665815d6fa843d67ebc7551244358 /compiler | |
parent | abb78aabe90231153d74a3030e8a8a3f5ec477e2 (diff) | |
download | haskell-41288a1d37047b4046f43bb88f8aaf6bdefd8183.tar.gz |
Improve pretty-printing of strict lets with -dppr-case-as-let
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/coreSyn/PprCore.lhs | 29 |
1 files changed, 18 insertions, 11 deletions
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. |