Commit ca9986a3 authored by Simon Peyton Jones's avatar Simon Peyton Jones

Improve documentation of the way that defaulting to IO happens in GHCi

Thanks to John Hughes for the suggestion.
parent 3fabf48e
......@@ -358,10 +358,10 @@ Prelude> 5+5
</screen>
</para>
<sect2><title>I/O actions at the prompt</title>
<sect2 id="actions-at-prompt"><title>I/O actions at the prompt</title>
<para>GHCi does more than simple expression evaluation at the prompt.
If you type something of type <literal>IO a</literal> for some
If you enter an expression of type <literal>IO a</literal> for some
<literal>a</literal>, then GHCi <emphasis>executes</emphasis> it
as an IO-computation.
<screen>
......@@ -370,6 +370,12 @@ Prelude> "hello"
Prelude> putStrLn "hello"
hello
</screen>
This works even if the type of the expression is more general,
provided it can be <emphasis>instantiated</emphasis> to <literal>IO a</literal>. For example
<screen>
Prelude> return True
True
</screen>
Furthermore, GHCi will print the result of the I/O action if (and only
if):
<itemizedlist>
......@@ -1088,8 +1094,12 @@ def = toEnum 0
doesn't require extensions to the class system), so if the type defaults to
<literal>Integer</literal> then ghci gives an error when running a
printf.
</para>
<para>See also <xref linkend="actions-at-prompt"/> for how the monad of a computational
expression defaults to <literal>IO</literal> if possible.
</para>
</sect2>
<sect2 id="ghci-interactive-print">
<title>Using a custom interactive printing function</title>
<para>[<emphasis role="bold">New in version 7.6.1</emphasis>]
......
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