Ticket #7816: 0001-Change-main-function.patch

File 0001-Change-main-function.patch, 4.6 KB (added by monoidal, 2 years ago)

Compiler and documentation

  • compiler/typecheck/TcRnDriver.lhs

    From 59a291e34f8254880803c38687e11c025d2f2577 Mon Sep 17 00:00:00 2001
    From: Krzysztof Gogolewski <[email protected]>
    Date: Sat, 6 Apr 2013 19:27:34 +0200
    Subject: [PATCH] Change "main function", a misnomer, to "main IO action"
     (#7816)
    
    ---
     compiler/typecheck/TcRnDriver.lhs |    4 ++--
     docs/comm/the-beast/main.html     |    6 +++---
     docs/users_guide/phases.xml       |   10 +++++-----
     3 files changed, 10 insertions(+), 10 deletions(-)
    
    diff --git a/compiler/typecheck/TcRnDriver.lhs b/compiler/typecheck/TcRnDriver.lhs
    index 275ce07..15ccf57 100644
    a b check_main dflags tcg_env 
    11021102ppMainFn :: RdrName -> SDoc
    11031103ppMainFn main_fn
    11041104  | main_fn == main_RDR_Unqual
    1105   = ptext (sLit "function") <+> quotes (ppr main_fn)
     1105  = ptext (sLit "IO action") <+> quotes (ppr main_fn)
    11061106  | otherwise
    1107   = ptext (sLit "main function") <+> quotes (ppr main_fn)
     1107  = ptext (sLit "main IO action") <+> quotes (ppr main_fn)
    11081108
    11091109-- | Get the unqualified name of the function to use as the \"main\" for the main module.
    11101110-- Either returns the default name or the one configured on the command line with -main-is
  • docs/comm/the-beast/main.html

    diff --git a/docs/comm/the-beast/main.html b/docs/comm/the-beast/main.html
    index 332ffaa..67c6d95 100644
    a b  
    88  <body BGCOLOR="FFFFFF">
    99    <h1>Compiling and running the Main module</h1>
    1010
    11 GHC allows you to determine which module contains the "main" function, and
    12 what that function is called, via the <code>-fmain-is</code> flag.   The trouble is
     11GHC allows you to determine which module contains the "main" action, and
     12what that action is called, via the <code>-fmain-is</code> flag.   The trouble is
    1313that the runtime system is fixed, so what symbol should it link to?
    1414<p>
    15 The current solution is this.  Suppose the main function is <code>Foo.run</code>.
     15The current solution is this.  Suppose the main action is <code>Foo.run</code>.
    1616<ul>
    1717<li>
    1818Then, when compiling module <code>Foo</code>, GHC adds an extra definition:
  • docs/users_guide/phases.xml

    diff --git a/docs/users_guide/phases.xml b/docs/users_guide/phases.xml
    index f4019bd..ce28f7a 100644
    a b $ cat foo.hspp</screen> 
    850850        <term>
    851851          <option>-main-is <replaceable>thing</replaceable></option>
    852852          <indexterm><primary><option>-main-is</option></primary></indexterm>
    853           <indexterm><primary>specifying your own main function</primary></indexterm>
     853          <indexterm><primary>specifying your own main IO action</primary></indexterm>
    854854        </term>
    855855        <listitem>
    856856          <para> The normal rule in Haskell is that your program must supply a <literal>main</literal>
    $ cat foo.hspp</screen> 
    858858            to change which function is the "main" one, and the <option>-main-is</option> flag
    859859            allows you to do so.  The  <replaceable>thing</replaceable> can be one of:
    860860            <itemizedlist>
    861         <listitem><para>A lower-case identifier <literal>foo</literal>.  GHC assumes that the main function is <literal>Main.foo</literal>.</para></listitem>
    862         <listitem><para>A module name <literal>A</literal>.  GHC assumes that the main function is <literal>A.main</literal>.</para></listitem>
    863         <listitem><para>A qualified name <literal>A.foo</literal>.  GHC assumes that the main function is <literal>A.foo</literal>.</para></listitem>
     861        <listitem><para>A lower-case identifier <literal>foo</literal>.  GHC assumes that the main action is <literal>Main.foo</literal>.</para></listitem>
     862        <listitem><para>A module name <literal>A</literal>.  GHC assumes that the main action is <literal>A.main</literal>.</para></listitem>
     863        <listitem><para>A qualified name <literal>A.foo</literal>.  GHC assumes that the main action is <literal>A.foo</literal>.</para></listitem>
    864864        </itemizedlist>
    865865            Strictly speaking, <option>-main-is</option> is not a link-phase flag at all; it has no effect on the link step.
    866             The flag must be specified when compiling the module containing the specified main function (e.g. module <literal>A</literal>
     866            The flag must be specified when compiling the module containing the specified main action (e.g. module <literal>A</literal>
    867867            in the latter two items above).  It has no effect for other modules,
    868868            and hence can safely be given to <literal>ghc --make</literal>.
    869869            However, if all the modules are otherwise up to date, you may need to force