Add :main docs to ghci commands page
authorIan Lynagh <igloo@earth.li>
Sun, 3 Sep 2006 22:31:07 +0000 (22:31 +0000)
committerIan Lynagh <igloo@earth.li>
Sun, 3 Sep 2006 22:31:07 +0000 (22:31 +0000)
docs/users_guide/ghci.xml

index 26efdee..e53c7c6 100644 (file)
@@ -1072,6 +1072,38 @@ Prelude> :. cmds.ghci
 
       <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>