Commit a1579a34 authored by Simon Marlow's avatar Simon Marlow

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
parent e291c4ce
......@@ -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 = [
......
......@@ -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]
......
......@@ -370,6 +370,15 @@
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>
......
......@@ -1874,6 +1874,12 @@
<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>
......
......@@ -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>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment