From a1579a34bba86590e3656e5c7e88a78a9fb2f584 Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Wed, 27 Sep 2006 13:25:50 +0000 Subject: [PATCH] Make printing of binding results optional in GHCi, and document it You can say :set -fno-print-bind-result in GHCi to disable this behaviour. Addresses #887 --- compiler/main/DynFlags.hs | 6 +++++- compiler/typecheck/TcRnDriver.lhs | 17 +++++++++++------ docs/users_guide/6.6-notes.xml | 9 +++++++++ docs/users_guide/flags.xml | 6 ++++++ docs/users_guide/ghci.xml | 10 ++++++++-- 5 files changed, 39 insertions(+), 9 deletions(-) diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs index 318df02..86598e9 100644 --- a/compiler/main/DynFlags.hs +++ b/compiler/main/DynFlags.hs @@ -195,6 +195,7 @@ data DynFlag | Opt_SplitObjs | Opt_StgStats | Opt_HideAllPackages + | Opt_PrintBindResult -- keeping stuff | Opt_KeepHiDiffs @@ -433,6 +434,8 @@ defaultDynFlags = Opt_IgnoreInterfacePragmas, Opt_OmitInterfacePragmas + -- on by default: + Opt_PrintBindResult ] ++ standardWarnings, log_action = \severity srcSpan style msg -> @@ -1037,7 +1040,8 @@ fFlags = [ ( "unbox-strict-fields", Opt_UnboxStrictFields ), ( "dicts-cheap", Opt_DictsCheap ), ( "excess-precision", Opt_ExcessPrecision ), - ( "asm-mangling", Opt_DoAsmMangling ) + ( "asm-mangling", Opt_DoAsmMangling ), + ( "print-bind-result", Opt_PrintBindResult ) ] glasgowExtsFlags = [ diff --git a/compiler/typecheck/TcRnDriver.lhs b/compiler/typecheck/TcRnDriver.lhs index 875d4f6..acf003f 100644 --- a/compiler/typecheck/TcRnDriver.lhs +++ b/compiler/typecheck/TcRnDriver.lhs @@ -965,15 +965,20 @@ mkPlan stmt@(L loc (BindStmt {})) | [L _ v] <- collectLStmtBinders stmt -- One binder, for a bind stmt = do { let print_v = L loc $ ExprStmt (nlHsApp (nlHsVar printName) (nlHsVar v)) (HsVar thenIOName) placeHolderType + + ; print_bind_result <- doptM Opt_PrintBindResult + ; let print_plan = do + { stuff@([v_id], _) <- tcGhciStmts [stmt, print_v] + ; v_ty <- zonkTcType (idType v_id) + ; ifM (isUnitTy v_ty || not (isTauTy v_ty)) failM + ; return stuff } + -- The plans are: -- [stmt; print v] but not if v::() -- [stmt] - ; runPlans [do { stuff@([v_id], _) <- tcGhciStmts [stmt, print_v] - ; v_ty <- zonkTcType (idType v_id) - ; ifM (isUnitTy v_ty || not (isTauTy v_ty)) failM - ; return stuff }, - tcGhciStmts [stmt] - ]} + ; runPlans ((if print_bind_result then [print_plan] else []) ++ + [tcGhciStmts [stmt]]) + } mkPlan stmt = tcGhciStmts [stmt] diff --git a/docs/users_guide/6.6-notes.xml b/docs/users_guide/6.6-notes.xml index 6b6df22..a45579b 100644 --- a/docs/users_guide/6.6-notes.xml +++ b/docs/users_guide/6.6-notes.xml @@ -370,6 +370,15 @@ See for more information. + + + GHCi now invokes print by default on the + result of IO actions and bindings at the prompt. This is + occasionally not what you want, so it can be disabled (at + least for bindings) with + :set -fno-print-bind-result. See . + diff --git a/docs/users_guide/flags.xml b/docs/users_guide/flags.xml index b5c737a..d3d91b3 100644 --- a/docs/users_guide/flags.xml +++ b/docs/users_guide/flags.xml @@ -1874,6 +1874,12 @@ dynamic - + + + Turn off printing of binding results in GHCi + dynamic + - + diff --git a/docs/users_guide/ghci.xml b/docs/users_guide/ghci.xml index 9ec07c3..ae55203 100644 --- a/docs/users_guide/ghci.xml +++ b/docs/users_guide/ghci.xml @@ -402,7 +402,7 @@ hello - + Using <literal>do-</literal>notation at the prompt do-notationin GHCi statementsin GHCi @@ -444,7 +444,13 @@ Prelude> Show - + The automatic printing of binding results can be supressed with + (this does not + supress printing the result of non-binding statements). + . + You might want to do this to prevent the result of binding + statements from being fully evaluated by the act of printing + them, for example. Of course, you can also bind normal non-IO expressions using the let-statement: -- 1.7.10.4