behaves in the same way for expressions typed at the
prompt.</para>
+ <para>
+ Hint: GHCi will tab-complete names that are in scope; for
+ example, if you run GHCi and type <literal>J<tab></literal>
+ then GHCi will expand it to <literal>Just </literal>.
+ </para>
+
<sect3>
<title>Qualified names</title>
qualified</literal> declaration for every module in every
package, and every module currently loaded into GHCi.</para>
</sect3>
+
+ <sect3>
+ <title>The <literal>:main</literal> command</title>
+
+ <para>
+ When a program is compiled and executed, it can use the
+ <literal>getArgs</literal> function to access the
+ command-line arguments.
+ However, we cannot simply pass the arguments to the
+ <literal>main</literal> function while we are testing in ghci,
+ as the <literal>main</literal> function doesn't take its
+ directly.
+ </para>
+
+ <para>
+ Instead, we can use the <literal>:main</literal> command.
+ This runs whatever <literal>main</literal> is in scope, with
+ any arguments being treated the same as command-line arguments,
+ e.g.:
+ </para>
+
+<screen>
+Prelude> let main = System.Environment.getArgs >>= print
+Prelude> :main foo bar
+["foo","bar"]
+</screen>
+
+ </sect3>
</sect2>
package be loaded by using the <literal>-package</literal> flag:</para>
<screen>
-$ ghci -package data
+$ ghci -package readline
___ ___ _
/ _ \ /\ /\/ __(_)
- / /_\// /_/ / / | | GHC Interactive, version 5.05, for Haskell 98.
+ / /_\// /_/ / / | | GHC Interactive, version 6.6, for Haskell 98.
/ /_\\/ __ / /___| | http://www.haskell.org/ghc/
\____/\/ /_/\____/|_| Type :? for help.
Loading package base ... linking ... done.
-Loading package haskell98 ... linking ... done.
-Loading package lang ... linking ... done.
-Loading package concurrent ... linking ... done.
-Loading package readline ... linking ... done.
-Loading package unix ... linking ... done.
-Loading package posix ... linking ... done.
-Loading package util ... linking ... done.
-Loading package data ... linking ... done.
+Loading package readline-1.0 ... linking ... done.
Prelude>
</screen>
<para>GHCi commands all begin with
‘<literal>:</literal>’ and consist of a single command
name followed by zero or more parameters. The command name may be
- abbreviated, as long as the abbreviation is not ambiguous. All of
- the builtin commands, with the exception of
- <literal>:unset</literal> and <literal>:undef</literal>, may be
- abbreviated to a single letter.</para>
+ abbreviated, with ambiguities being resolved in favour of the more
+ commonly used commands.</para>
<variablelist>
<varlistentry>
<varlistentry>
<term>
+ <literal>:main <replaceable>arg<subscript>1</subscript></replaceable> ... <replaceable>arg<subscript>n</subscript></replaceable></literal>
+ <indexterm><primary><literal>:main</literal></primary></indexterm>
+ </term>
+ <listitem>
+ <para>
+ When a program is compiled and executed, it can use the
+ <literal>getArgs</literal> function to access the
+ command-line arguments.
+ However, we cannot simply pass the arguments to the
+ <literal>main</literal> function while we are testing in ghci,
+ as the <literal>main</literal> function doesn't take its
+ directly.
+ </para>
+
+ <para>
+ Instead, we can use the <literal>:main</literal> command.
+ This runs whatever <literal>main</literal> is in scope, with
+ any arguments being treated the same as command-line arguments,
+ e.g.:
+ </para>
+
+<screen>
+Prelude> let main = System.Environment.getArgs >>= print
+Prelude> :main foo bar
+["foo","bar"]
+</screen>
+
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
<literal>:module <optional>+|-</optional> <optional>*</optional><replaceable>mod<subscript>1</subscript></replaceable> ... <optional>*</optional><replaceable>mod<subscript>n</subscript></replaceable></literal>
<indexterm><primary><literal>:module</literal></primary></indexterm>
</term>