typo in rules example. spotted by vixey@#haskell
[ghc-hetmet.git] / docs / users_guide / glasgow_exts.xml
index 87e2e0d..656d2db 100644 (file)
@@ -92,7 +92,7 @@ documentation</ulink> describes all the libraries that come with GHC.
           Haskell 98 described in <xref
           linkend="ghc-language-features"/>, except where otherwise
           noted. We are trying to move away from this portmanteau flag, 
-         and towards enabling features individaully.</para>
+         and towards enabling features individually.</para>
 
          <para>New reserved words: <literal>forall</literal> (only in
          types), <literal>mdo</literal>.</para>
@@ -323,17 +323,17 @@ became out of date, and wrong information is worse than none.</para>
 
 <para>The Real Truth about what primitive types there are, and what operations
 work over those types, is held in the file
-<filename>fptools/ghc/compiler/prelude/primops.txt.pp</filename>.
+<filename>compiler/prelude/primops.txt.pp</filename>.
 This file is used directly to generate GHC's primitive-operation definitions, so
 it is always correct!  It is also intended for processing into text.</para>
 
-<para> Indeed,
+<para>Indeed,
 the result of such processing is part of the description of the 
  <ulink
       url="http://www.haskell.org/ghc/docs/papers/core.ps.gz">External
         Core language</ulink>.
 So that document is a good place to look for a type-set version.
-We would be very happy if someone wanted to volunteer to produce an SGML
+We would be very happy if someone wanted to volunteer to produce an XML
 back end to the program that processes <filename>primops.txt</filename> so that
 we could include the results here in the User Guide.</para>
 
@@ -366,6 +366,20 @@ would use in C: <literal>Int&num;</literal> (long int),
 know and love&mdash;usually one instruction.
 </para>
 
+<para> For some primitive types we have special syntax for literals.
+Anything that would be an integer lexeme followed by a
+<literal>&num;</literal> is an <literal>Int&num;</literal> literal, e.g.
+<literal>32&num;</literal> and <literal>-0x3A&num;</literal>. Likewise,
+any non-negative integer literal followed by
+<literal>&num;&num;</literal> is a <literal>Word&num;</literal> literal.
+Likewise, any floating point literal followed by a
+<literal>&num;</literal> is a <literal>Float&num;</literal> literal, and
+followed by <literal>&num;&num;</literal> is a
+<literal>Double&num;</literal>. Finally, a string literal followed by a
+<literal>&num;</literal>, e.g. <literal>&quot;foo&quot;&num;</literal>,
+is a <literal>Addr&num;</literal> literal.
+</para>
+
 <para>
 Primitive (unboxed) types cannot be defined in Haskell, and are
 therefore built into the language and compiler.  Primitive types are
@@ -753,7 +767,7 @@ view :: Type -> TypeView
 </programlisting>
 
 The representation of Typ is held abstract, permitting implementations
-to use a fancy representation (e.g., hash-consing to managage sharing).
+to use a fancy representation (e.g., hash-consing to manage sharing).
 
 Without view patterns, using this signature a little inconvenient: 
 <programlisting>
@@ -1113,7 +1127,7 @@ In this example, the list <literal>output</literal> would take on
 (The function <literal>sortWith</literal> is not a keyword; it is an ordinary
 function that is exported by <literal>GHC.Exts</literal>.)</para>
 
-<para>There are five new forms of compehension qualifier,
+<para>There are five new forms of comprehension qualifier,
 all introduced by the (existing) keyword <literal>then</literal>:
     <itemizedlist>
     <listitem>
@@ -1160,7 +1174,7 @@ then group by e using f
     is a function supplied to f by the compiler which lets it compute e on every
     element of the list being transformed. However, unlike the non-grouping case,
     f additionally partitions the list into a number of sublists: this means that
-    at every point after this statement, binders occuring before it in the comprehension
+    at every point after this statement, binders occurring before it in the comprehension
     refer to <emphasis>lists</emphasis> of possible values, not single values. To help understand
     this, let's look at an example:</para>
     
@@ -1296,7 +1310,7 @@ output = [ x
              </para></listitem>
            </itemizedlist>
 In all cases (apart from arrow notation), the static semantics should be that of the desugared form,
-even if that is a little unexpected. For emample, the 
+even if that is a little unexpected. For example, the 
 static semantics of the literal <literal>368</literal>
 is exactly that of <literal>fromInteger (368::Integer)</literal>; it's fine for
 <literal>fromInteger</literal> to have any of the types:
@@ -1537,11 +1551,12 @@ For example, in a <literal>let</literal>, it applies in the right-hand
 sides of other <literal>let</literal>-bindings and the body of the
 <literal>let</literal>C. Or, in recursive <literal>do</literal>
 expressions (<xref linkend="mdo-notation"/>), the local fixity
-declarations of aA <literal>let</literal> statement scope over other
+declarations of a <literal>let</literal> statement scope over other
 statements in the group, just as the bound name does.
 </para>
 
-Moreover, a local fixity declatation *must* accompany a local binding of
+<para>
+Moreover, a local fixity declaration *must* accompany a local binding of
 that name: it is not possible to revise the fixity of name bound
 elsewhere, as in
 <programlisting>
@@ -1550,6 +1565,7 @@ let infixr 9 $ in ...
 
 Because local fixity declarations are technically Haskell 98, no flag is
 necessary to enable them.
+</para>
 </sect2>
 
 </sect1>
@@ -1829,7 +1845,7 @@ apply <function>fn</function> to <literal>val</literal> to get a boolean.  For e
 </para>
 
 <para>
-What this allows us to do is to package heterogenous values
+What this allows us to do is to package heterogeneous values
 together with a bunch of functions that manipulate them, and then treat
 that collection of packages in a uniform manner.  You can express
 quite a bit of object-oriented-like programming this way.
@@ -2210,9 +2226,9 @@ like this:
    data NumInst a 
       = Num a => MkNumInst (NumInst a)
 </programlisting>
-Notice that, unlike the situation when declaring an existental, there is 
+Notice that, unlike the situation when declaring an existential, there is 
 no <literal>forall</literal>, because the <literal>Num</literal> constrains the
-data type's univerally quantified type variable <literal>a</literal>.  
+data type's universally quantified type variable <literal>a</literal>.  
 A constructor may have both universal and existential type variables: for example,
 the following two declarations are equivalent:
 <programlisting>
@@ -3648,8 +3664,8 @@ in GHC, you can give the foralls if you want.  See <xref linkend="universal-quan
  <emphasis>Each universally quantified type variable
 <literal>tvi</literal> must be reachable from <literal>type</literal></emphasis>.
 
-A type variable <literal>a</literal> is "reachable" if it it appears
-in the same constraint as either a type variable free in in
+A type variable <literal>a</literal> is "reachable" if it appears
+in the same constraint as either a type variable free in
 <literal>type</literal>, or another reachable type variable.  
 A value with a type that does not obey 
 this reachability restriction cannot be used without introducing
@@ -4252,7 +4268,7 @@ it has rank-2 types on the left of a function arrow.
 GHC has three flags to control higher-rank types:
 <itemizedlist>
 <listitem><para>
- <option>-XPolymorphicComponents</option>: data constructors (only) can have polymorphic argment types.
+ <option>-XPolymorphicComponents</option>: data constructors (only) can have polymorphic argument types.
 </para></listitem>
 <listitem><para>
  <option>-XRank2Types</option>: any function (including data constructors) can have a rank-2 type.
@@ -4592,7 +4608,7 @@ In Haskell, a programmer-written type signature is implicitly quantified over
 its free type variables (<ulink
 url="http://www.haskell.org/onlinereport/decls.html#sect4.1.2">Section
 4.1.2</ulink> 
-of the Haskel Report).
+of the Haskell Report).
 Lexically scoped type variables affect this implicit quantification rules
 as follows: any type variable that is in scope is <emphasis>not</emphasis> universally
 quantified. For example, if type variable <literal>a</literal> is in scope,
@@ -4690,8 +4706,8 @@ already in scope (i.e. bound by the enclosing context), matters are simple: the
 signature simply constrains the type of the pattern in the obvious way.
 </para>
 <para>
-Unlike expression and declaration type signatures, pattern type signatures are not implictly generalised.
-The pattern in a <emphasis>patterm binding</emphasis> may only mention type variables
+Unlike expression and declaration type signatures, pattern type signatures are not implicitly generalised.
+The pattern in a <emphasis>pattern binding</emphasis> may only mention type variables
 that are already in scope.  For example:
 <programlisting>
   f :: forall a. [a] -> (Int, [a])
@@ -5015,14 +5031,14 @@ Wiki page</ulink>.
                  That is, <literal>''</literal><replaceable>thing</replaceable> interprets <replaceable>thing</replaceable> in a type context.
                     </para></listitem> 
                  </itemizedlist>
-                 These <literal>Names</literal> can be used to construct Template Haskell expressions, patterns, delarations etc.  They
+                 These <literal>Names</literal> can be used to construct Template Haskell expressions, patterns, declarations etc.  They
                  may also be given as an argument to the <literal>reify</literal> function.
                 </para>
                </listitem>
 
                  
        </itemizedlist>
-(Compared to the original paper, there are many differnces of detail.
+(Compared to the original paper, there are many differences of detail.
 The syntax for a declaration splice uses "<literal>$</literal>" not "<literal>splice</literal>".
 The type of the enclosed expression must be  <literal>Q [Dec]</literal>, not  <literal>[Q Dec]</literal>.
 Type splices are not implemented, and neither are pattern splices or quotations.
@@ -6044,7 +6060,8 @@ Assertion failures can be caught, see the documentation for the
     <replaceable>word</replaceable> that GHC understands are described
     in the following sections; any pragma encountered with an
     unrecognised <replaceable>word</replaceable> is (silently)
-    ignored.</para>
+    ignored. The layout rule applies in pragmas, so the closing <literal>#-}</literal>
+    should start in a column to the right of the opening <literal>{-#</literal>. </para> 
 
     <para>Certain pragmas are <emphasis>file-header pragmas</emphasis>.  A file-header
       pragma must precede the <literal>module</literal> keyword in the file.  
@@ -6220,7 +6237,7 @@ key_function :: Int -> String -> (Bool, Double)
        function "<literal>f</literal>" has a number of other effects:
 <itemizedlist>
 <listitem><para>
-No funtions are inlined into <literal>f</literal>.  Otherwise
+No functions are inlined into <literal>f</literal>.  Otherwise
 GHC might inline a big function into <literal>f</literal>'s right hand side, 
 making <literal>f</literal> big; and then inline <literal>f</literal> blindly.
 </para></listitem>
@@ -6596,10 +6613,9 @@ Here is an example:
 
 <programlisting>
   {-# RULES
-        "map/map"       forall f g xs. map f (map g xs) = map (f.g) xs
-  #-}
+  "map/map"    forall f g xs.  map f (map g xs) = map (f.g) xs
+    #-}
 </programlisting>
-
 </para>
 
 <sect2>
@@ -6609,15 +6625,32 @@ Here is an example:
 From a syntactic point of view:
 
 <itemizedlist>
-<listitem>
 
+<listitem>
 <para>
- There may be zero or more rules in a <literal>RULES</literal> pragma.
+ There may be zero or more rules in a <literal>RULES</literal> pragma, separated by semicolons (which
+ may be generated by the layout rule).
 </para>
 </listitem>
 
 <listitem>
+<para>
+The layout rule applies in a pragma.
+Currently no new indentation level
+is set, so if you put several rules in single RULES pragma and wish to use layout to separate them,
+you must lay out the starting in the same column as the enclosing definitions.
+<programlisting>
+  {-# RULES
+  "map/map"    forall f g xs.  map f (map g xs) = map (f.g) xs
+  "map/append" forall f xs ys. map f (xs ++ ys) = map f xs ++ map f ys
+    #-}
+</programlisting>
+Furthermore, the closing <literal>#-}</literal>
+should start in a column to the right of the opening <literal>{-#</literal>.
+</para>
+</listitem>
 
+<listitem>
 <para>
  Each rule has a name, enclosed in double quotes.  The name itself has
 no significance at all.  It is only used when reporting how many times the rule fired.
@@ -6631,7 +6664,7 @@ immediately after the name of the rule.  Thus:
 <programlisting>
   {-# RULES
         "map/map" [2]  forall f g xs. map f (map g xs) = map (f.g) xs
-  #-}
+    #-}
 </programlisting>
 The "[2]" means that the rule is active in Phase 2 and subsequent phases.  The inverse
 notation "[~2]" is also accepted, meaning that the rule is active up to, but not including,
@@ -6640,17 +6673,8 @@ Phase 2.
 </listitem>
 
 
-<listitem>
-
-<para>
- Layout applies in a <literal>RULES</literal> pragma.  Currently no new indentation level
-is set, so you must lay out your rules starting in the same column as the
-enclosing definitions.
-</para>
-</listitem>
 
 <listitem>
-
 <para>
  Each variable mentioned in a rule must either be in scope (e.g. <function>map</function>),
 or bound by the <literal>forall</literal> (e.g. <function>f</function>, <function>g</function>, <function>xs</function>).  The variables bound by
@@ -6757,7 +6781,7 @@ infeasible in most interesting cases.  The responsibility is entirely the progra
 terminating.  For example:
 
 <programlisting>
-  "loop"        forall x,y.  f x y = f y x
+  "loop"        forall x y.  f x y = f y x
 </programlisting>
 
 This rule will cause the compiler to go into an infinite loop.
@@ -7194,7 +7218,7 @@ g x = show x
 </para>
 
 <para>
-  However, when external for is generated (via
+  However, when external core is generated (via
   <option>-fext-core</option>), there will be Notes attached to the
   expressions <function>show</function> and <varname>x</varname>.
   The core function declaration for <function>f</function> is:
@@ -7545,6 +7569,7 @@ standard behaviour.
      ;;; Local Variables: ***
      ;;; mode: xml ***
      ;;; sgml-parent-document: ("users_guide.xml" "book" "chapter" "sect1") ***
+     ;;; ispell-local-dictionary: "british" ***
      ;;; End: ***
  -->