Make printing of binding results optional in GHCi, and document it
authorSimon Marlow <simonmar@microsoft.com>
Wed, 27 Sep 2006 13:25:50 +0000 (13:25 +0000)
committerSimon Marlow <simonmar@microsoft.com>
Wed, 27 Sep 2006 13:25:50 +0000 (13:25 +0000)
You can say :set -fno-print-bind-result in GHCi to disable this behaviour.
Addresses #887

compiler/main/DynFlags.hs
compiler/typecheck/TcRnDriver.lhs
docs/users_guide/6.6-notes.xml
docs/users_guide/flags.xml
docs/users_guide/ghci.xml

index 318df02..86598e9 100644 (file)
@@ -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 = [ 
index 875d4f6..acf003f 100644 (file)
@@ -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]
index 6b6df22..a45579b 100644 (file)
           See <xref linkend="ghci-commands" /> for more information.
         </para>
       </listitem>
+      <listitem>
+        <para>
+          GHCi now invokes <literal>print</literal> 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 
+          <literal>:set -fno-print-bind-result</literal>.  See <xref
+          linkend="ghci-stmts" />.</para>
+      </listitem>
     </itemizedlist>
   </sect2>
 
index b5c737a..d3d91b3 100644 (file)
              <entry>dynamic</entry>
              <entry>-</entry>
            </row>
+           <row>
+             <entry><option>-fno-print-bind-result</option></entry>
+             <entry><link id="ghci-stmts">Turn off printing of binding results in GHCi</link></entry>
+             <entry>dynamic</entry>
+             <entry>-</entry>
+           </row>
          </tbody>
        </tgroup>
       </informaltable>
index 9ec07c3..ae55203 100644 (file)
@@ -402,7 +402,7 @@ hello
 </screen>
 </para></sect2>
 
-    <sect2>
+    <sect2 id="ghci-stmts">
       <title>Using <literal>do-</literal>notation at the prompt</title>
       <indexterm><primary>do-notation</primary><secondary>in GHCi</secondary></indexterm>
       <indexterm><primary>statements</primary><secondary>in GHCi</secondary></indexterm>
@@ -444,7 +444,13 @@ Prelude>
              <literal>Show</literal></para>
          </listitem>
        </itemizedlist>
-      </para>
+      The automatic printing of binding results can be supressed with
+      <option>:set -fno-print-bind-result</option> (this does not
+      supress printing the result of non-binding statements).
+      <indexterm><primary><option>-fno-print-bind-result</option></primary></indexterm><indexterm><primary><option>-fprint-bind-result</option></primary></indexterm>.
+      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.</para>
 
       <para>Of course, you can also bind normal non-IO expressions
       using the <literal>let</literal>-statement:</para>