[project @ 2004-03-05 16:04:52 by simonmar]
[ghc-hetmet.git] / ghc / docs / users_guide / separate_compilation.sgml
index fe51108..9eef1a9 100644 (file)
       interface file will be put in <literal>src/A/B/C.hi</literal>
       and the object file in <literal>src/A/B/C.o</literal>.</para>
 
-      <para>Note that it is reasonable to have a module
+      <para>For any module that is imported, GHC requires that the
+      name of the module in the import statement exactly matches the
+      name of the module in the interface file (or source file) found
+      using the strategy specified in <xref linkend="search-path">.
+      This means that for most modules, the source file name should
+      match the module name.</para>
+
+      <para>However, note that it is reasonable to have a module
       <literal>Main</literal> in a file named
       <filename>foo.hs</filename>, but this only works because GHC
       never needs to search for the interface for module
       <literal>Main</literal> (because it is never imported).  It is
       therefore possible to have several <literal>Main</literal>
       modules in separate source files in the same directory, and GHC
-      will not get confused.  For modules other than
-      <literal>Main</literal>, it is strongly recommended that you
-      name the source file after the module name, replacing dots with
-      slashes in hierarchical module names.</para>
+      will not get confused.</para>
 
       <para>In batch compilation mode, the name of the object file can
       also be overriden using the <option>-o</option> option, and the
@@ -948,6 +952,36 @@ newtype GHC.IOBase.IO a
          <literal>instances</literal> or derive them automatically.
 </para>
        </listitem>
+
+<listitem> <para>For <literal>data</literal> or <literal>newtype</literal> declaration, you may omit all
+the constructors, by omitting the '=' and everything that follows it:
+<ProgramListing>
+module A where
+  data TA
+</ProgramListing>
+           In a <emphasis>source</emphasis> program
+         this would declare TA to have no constructors (a GHC extension: see <xref linkend="nullary-types">),
+         but in an hi-boot file it means "I don't know or care what the construtors are".
+           This is the most common form of data type declaration, because it's easy to get right.</para>
+         <para>
+         You <emphasis>can</emphasis> also write out the constructors but, if you do so, you must write
+         it out precisely as in its real definition. 
+           It is especially delicate if you use a strictness annotation "!", 
+         with or without an <literal>{-# UNPACK #-}</literal> pragma.  In a source file
+         GHC may or may not choose to unbox the argument, but in an hi-boot file it's
+         assumed that you express the <emphasis>outcome</emphasis> of this decision.  
+           (So in the cases where GHC decided not to unpack, you must not use the pragma.)
+           Tread with care.</para>
+         <para>
+           Regardless of whether you write the constructors, you must write all the type parameters, 
+           <emphasis>including their kinds</emphasis> 
+           if they are not '*'.  (You can give explicit kinds in source files too (<xref linkend="sec-kinding">), 
+           but you <emphasis>must</emphasis> do so in hi-boot files.)</para>
+       </listitem>
+
+<listitem> <para>For <literal>class</literal> declaration, you may not specify any class
+operations.  We could lift this restriction if it became tiresome.</para>
+</listitem>
       </itemizedlist>
 
       <para>Notice that we only put the declaration for the newtype
@@ -955,18 +989,6 @@ newtype GHC.IOBase.IO a
       not the signature for <Function>f</Function>, since
       <Function>f</Function> isn't used by <literal>B</literal>.</para>
 
-      <para>If you want an <literal>hi-boot</literal> file to export a
-      data type, but you don't want to give its constructors (because
-      the constructors aren't used by the SOURCE-importing module),
-      you can write simply:</para>
-
-<ProgramListing>
-module A where
-data TA
-</ProgramListing>
-
-      <para>(You must write all the type parameters, but leave out the
-      '=' and everything that follows it.)</para>
     </sect2>