[project @ 2005-10-25 12:56:50 by simonmar]
[ghc-hetmet.git] / ghc / docs / users_guide / glasgow_exts.xml
index ff46b39..c9dfaf0 100644 (file)
@@ -825,68 +825,68 @@ This name is not supported by GHC.
             So the <option>-fno-implicit-prelude</option> flag causes
             the following pieces of built-in syntax to refer to
             <emphasis>whatever is in scope</emphasis>, not the Prelude
-            versions:</para>
+            versions:
 
            <itemizedlist>
              <listitem>
-               <para>Integer and fractional literals mean
-                "<literal>fromInteger 1</literal>" and
-                "<literal>fromRational 3.2</literal>", not the
-                Prelude-qualified versions; both in expressions and in
-                patterns. </para>
-               <para>However, the standard Prelude <literal>Eq</literal> class
-               is still used for the equality test necessary for literal patterns.</para>
-             </listitem>
+               <para>An integer literal <literal>368</literal> means
+                "<literal>fromInteger (368::Integer)</literal>", rather than
+                "<literal>Prelude.fromInteger (368::Integer)</literal>".
+</para> </listitem>        
 
-             <listitem>
-               <para>Negation (e.g. "<literal>- (f x)</literal>")
-               means "<literal>negate (f x)</literal>" (not
-               <literal>Prelude.negate</literal>).</para>
-             </listitem>
+      <listitem><para>Fractional literals are handed in just the same way,
+         except that the translation is 
+             <literal>fromRational (3.68::Rational)</literal>.
+</para> </listitem>        
+
+         <listitem><para>The equality test in an overloaded numeric pattern
+             uses whatever <literal>(==)</literal> is in scope.
+</para> </listitem>        
+
+         <listitem><para>The subtraction operation, and the
+         greater-than-or-equal test, in <literal>n+k</literal> patterns
+             use whatever <literal>(-)</literal> and <literal>(>=)</literal> are in scope.
+             </para></listitem>
 
              <listitem>
-               <para>In an n+k pattern, the standard Prelude
-                <literal>Ord</literal> class is still used for comparison,
-                but the necessary subtraction uses whatever
-                "<literal>(-)</literal>" is in scope (not
-                "<literal>Prelude.(-)</literal>").</para>
-             </listitem>
+               <para>Negation (e.g. "<literal>- (f x)</literal>")
+               means "<literal>negate (f x)</literal>", both in numeric
+               patterns, and expressions.
+             </para></listitem>
 
              <listitem>
          <para>"Do" notation is translated using whatever
              functions <literal>(>>=)</literal>,
-             <literal>(>>)</literal>, <literal>fail</literal>, and
-             <literal>return</literal>, are in scope (not the Prelude
-             versions).  List comprehensions, and parallel array
+             <literal>(>>)</literal>, and <literal>fail</literal>,
+             are in scope (not the Prelude
+             versions).  List comprehensions, mdo (<xref linkend="mdo-notation"/>), and parallel array
              comprehensions, are unaffected.  </para></listitem>
 
              <listitem>
-               <para>Similarly recursive do notation (see
-               <xref linkend="mdo-notation"/>) uses whatever
-               <literal>mfix</literal> function is in scope, and arrow
+               <para>Arrow
                notation (see <xref linkend="arrow-notation"/>)
                uses whatever <literal>arr</literal>,
                <literal>(>>>)</literal>, <literal>first</literal>,
                <literal>app</literal>, <literal>(|||)</literal> and
-               <literal>loop</literal> functions are in scope.</para>
-             </listitem>
+               <literal>loop</literal> functions are in scope. But unlike the
+               other constructs, the types of these functions must match the
+               Prelude types very closely.  Details are in flux; if you want
+               to use this, ask!
+             </para></listitem>
            </itemizedlist>
-
-            <para>The functions with these names that GHC finds in scope
-            must have types matching those of the originals, namely:
-            <screen>
-               fromInteger  :: Integer  -> N
-               fromRational :: Rational -> N
-               negate       :: N -> N
-               (-)          :: N -> N -> N
-               (>>=)        :: forall a b. M a -> (a -> M b) -> M b
-               (>>)         :: forall a b. M a -> M b -> M b
-               return       :: forall a.   a      -> M a
-               fail         :: forall a.   String -> M a
-            </screen>
-            (Here <literal>N</literal> may be any type,
-            and <literal>M</literal> any type constructor.)</para>
-
+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 
+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:
+<programlisting>
+fromInteger :: Integer -> Integer
+fromInteger :: forall a. Foo a => Integer -> a
+fromInteger :: Num a => a -> Integer
+fromInteger :: Integer -> Bool -> Bool
+</programlisting>
+</para>
+               
             <para>Be warned: this is an experimental facility, with
             fewer checks than usual.  Use <literal>-dcore-lint</literal>
             to typecheck the desugared program.  If Core Lint is happy
@@ -925,18 +925,49 @@ Nevertheless, they can be useful when defining "phantom types".</para>
 </sect3>
 
 <sect3 id="infix-tycons">
-<title>Infix type constructors</title>
+<title>Infix type constructors, classes, and type variables</title>
 
 <para>
-GHC allows type constructors to be operators, and to be written infix, very much 
-like expressions.  More specifically:
+GHC allows type constructors, classes, and type variables to be operators, and
+to be written infix, very much like expressions.  More specifically:
 <itemizedlist>
 <listitem><para>
-  A type constructor can be an operator, beginning with a colon; e.g. <literal>:*:</literal>.
+  A type constructor or class can be an operator, beginning with a colon; e.g. <literal>:*:</literal>.
   The lexical syntax is the same as that for data constructors.
   </para></listitem>
 <listitem><para>
-  Types can be written infix.  For example <literal>Int :*: Bool</literal>.  
+  Data type and type-synonym declarations can be written infix, parenthesised
+  if you want further arguments.  E.g.
+<screen>
+  data a :*: b = Foo a b
+  type a :+: b = Either a b
+  class a :=: b where ...
+
+  data (a :**: b) x = Baz a b x
+  type (a :++: b) y = Either (a,b) y
+</screen>
+  </para></listitem>
+<listitem><para>
+  Types, and class constraints, can be written infix.  For example
+  <screen>
+       x :: Int :*: Bool
+        f :: (a :=: b) => a -> b
+  </screen>
+  </para></listitem>
+<listitem><para>
+  A type variable can be an (unqualified) operator e.g. <literal>+</literal>.
+  The lexical syntax is the same as that for variable operators, excluding "(.)",
+  "(!)", and "(*)".  In a binding position, the operator must be
+  parenthesised.  For example:
+<programlisting>
+   type T (+) = Int + Int
+   f :: T Either
+   f = Left 3
+   liftA2 :: Arrow (~>)
+         => (a -> b -> c) -> (e ~> a) -> (e ~> b) -> (e ~> c)
+   liftA2 = ...
+</programlisting>
   </para></listitem>
 <listitem><para>
   Back-quotes work
@@ -944,7 +975,7 @@ like expressions.  More specifically:
   <literal>Int `a` Bool</literal>.  Similarly, parentheses work the same; e.g.  <literal>(:*:) Int Bool</literal>.
   </para></listitem>
 <listitem><para>
-  Fixities may be declared for type constructors just as for data constructors.  However,
+  Fixities may be declared for type constructors, or classes, just as for data constructors.  However,
   one cannot distinguish between the two in a fixity declaration; a fixity declaration
   sets the fixity for a data constructor and the corresponding type constructor.  For example:
 <screen>
@@ -957,21 +988,6 @@ like expressions.  More specifically:
 <listitem><para>
   Function arrow is <literal>infixr</literal> with fixity 0.  (This might change; I'm not sure what it should be.)
   </para></listitem>
-<listitem><para>
-  Data type and type-synonym declarations can be written infix.  E.g.
-<screen>
-  data a :*: b = Foo a b
-  type a :+: b = Either a b
-</screen>
-  </para></listitem>
-<listitem><para>
-  The only thing that differs between operators in types and operators in expressions is that
-  ordinary non-constructor operators, such as <literal>+</literal> and <literal>*</literal>
-  are not allowed in types. Reason: the uniform thing to do would be to make them type
-  variables, but that's not very useful.  A less uniform but more useful thing would be to
-  allow them to be type <emphasis>constructors</emphasis>.  But that gives trouble in export
-  lists.  So for now we just exclude them.
-  </para></listitem>
 
 </itemizedlist>
 </para>
@@ -1076,8 +1092,12 @@ because GHC does not allow  unboxed tuples on the left of a function arrow.
 
 <para>
 The idea of using existential quantification in data type declarations
-was suggested by Laufer (I believe, thought doubtless someone will
-correct me), and implemented in Hope+. It's been in Lennart
+was suggested by Perry, and implemented in Hope+ (Nigel Perry, <emphasis>The Implementation
+of Practical Functional Programming Languages</emphasis>, PhD Thesis, University of
+London, 1991). It was later formalised by Laufer and Odersky
+(<emphasis>Polymorphic type inference and abstract data types</emphasis>,
+TOPLAS, 16(5), pp1411-1430, 1994).
+It's been in Lennart
 Augustsson's <command>hbc</command> Haskell compiler for several years, and
 proved very useful.  Here's the idea.  Consider the declaration:
 </para>
@@ -1411,7 +1431,7 @@ declarations.  Define your own instances!
 <para>
 This section documents GHC's implementation of multi-parameter type
 classes.  There's lots of background in the paper <ulink
-url="http://research.microsoft.com/~simonpj/multi.ps.gz" >Type
+url="http://research.microsoft.com/~simonpj/Papers/type-class-design-space" >Type
 classes: exploring the design space</ulink > (Simon Peyton Jones, Mark
 Jones, Erik Meijer).
 </para>
@@ -1722,7 +1742,7 @@ means
 <sect2 id="instance-decls">
 <title>Instance declarations</title>
 
-<sect3>
+<sect3 id="instance-overlap">
 <title>Overlapping instances</title>
 <para>
 In general, <emphasis>GHC requires that that it be unambiguous which instance
@@ -1746,7 +1766,8 @@ these declarations:
   instance context3 => C Int [a]   where ...  -- (C)
   instance context4 => C Int [Int] where ...  -- (D)
 </programlisting>
-The instances (A) and (B) match the constraint <literal>C Int Bool</literal>, but (C) and (D) do not.  When matching, GHC takes
+The instances (A) and (B) match the constraint <literal>C Int Bool</literal>, 
+but (C) and (D) do not.  When matching, GHC takes
 no account of the context of the instance declaration
 (<literal>context1</literal> etc).
 GHC's default behaviour is that <emphasis>exactly one instance must match the
@@ -1778,6 +1799,35 @@ So GHC rejects the program.  If you add the flag <option>-fallow-incoherent-inst
 GHC will instead pick (C), without complaining about 
 the problem of subsequent instantiations.
 </para>
+<para>
+The willingness to be overlapped or incoherent is a property of 
+the <emphasis>instance declaration</emphasis> itself, controlled by the
+presence or otherwise of the <option>-fallow-overlapping-instances</option> 
+and <option>-fallow-incoherent-instances</option> flags when that mdodule is
+being defined.  Neither flag is required in a module that imports and uses the
+instance declaration.  Specifically, during the lookup process:
+<itemizedlist>
+<listitem><para>
+An instance declaration is ignored during the lookup process if (a) a more specific
+match is found, and (b) the instance declaration was compiled with 
+<option>-fallow-overlapping-instances</option>.  The flag setting for the
+more-specific instance does not matter.
+</para></listitem>
+<listitem><para>
+Suppose an instance declaration does not matche the constraint being looked up, but
+does unify with it, so that it might match when the constraint is further 
+instantiated.  Usually GHC will regard this as a reason for not committing to
+some other constraint.  But if the instance declaration was compiled with
+<option>-fallow-incoherent-instances</option>, GHC will skip the "does-it-unify?" 
+check for that declaration.
+</para></listitem>
+</itemizedlist>
+All this makes it possible for a library author to design a library that relies on 
+overlapping instances without the library client having to know.
+</para>
+<para>The <option>-fallow-incoherent-instances</option> flag implies the
+<option>-fallow-overlapping-instances</option> flag, but not vice versa.
+</para>
 </sect3>
 
 <sect3>
@@ -2094,6 +2144,68 @@ the binding for <literal>?x</literal>, so the type of <literal>f</literal> is
 </para>
 
 </sect3>
+
+<sect3><title>Implicit parameters and polymorphic recursion</title>
+
+<para>
+Consider these two definitions:
+<programlisting>
+  len1 :: [a] -> Int
+  len1 xs = let ?acc = 0 in len_acc1 xs
+
+  len_acc1 [] = ?acc
+  len_acc1 (x:xs) = let ?acc = ?acc + (1::Int) in len_acc1 xs
+
+  ------------
+
+  len2 :: [a] -> Int
+  len2 xs = let ?acc = 0 in len_acc2 xs
+
+  len_acc2 :: (?acc :: Int) => [a] -> Int
+  len_acc2 [] = ?acc
+  len_acc2 (x:xs) = let ?acc = ?acc + (1::Int) in len_acc2 xs
+</programlisting>
+The only difference between the two groups is that in the second group
+<literal>len_acc</literal> is given a type signature.
+In the former case, <literal>len_acc1</literal> is monomorphic in its own
+right-hand side, so the implicit parameter <literal>?acc</literal> is not
+passed to the recursive call.  In the latter case, because <literal>len_acc2</literal>
+has a type signature, the recursive call is made to the
+<emphasis>polymoprhic</emphasis> version, which takes <literal>?acc</literal>
+as an implicit parameter.  So we get the following results in GHCi:
+<programlisting>
+  Prog> len1 "hello"
+  0
+  Prog> len2 "hello"
+  5
+</programlisting>
+Adding a type signature dramatically changes the result!  This is a rather
+counter-intuitive phenomenon, worth watching out for.
+</para>
+</sect3>
+
+<sect3><title>Implicit parameters and monomorphism</title>
+
+<para>GHC applies the dreaded Monomorphism Restriction (section 4.5.5 of the
+Haskell Report) to implicit parameters.  For example, consider:
+<programlisting>
+ f :: Int -> Int
+  f v = let ?x = 0     in
+        let y = ?x + v in
+        let ?x = 5     in
+        y
+</programlisting>
+Since the binding for <literal>y</literal> falls under the Monomorphism
+Restriction it is not generalised, so the type of <literal>y</literal> is
+simply <literal>Int</literal>, not <literal>(?x::Int) => Int</literal>.
+Hence, <literal>(f 9)</literal> returns result <literal>9</literal>.
+If you add a type signature for <literal>y</literal>, then <literal>y</literal>
+will get type <literal>(?x::Int) => Int</literal>, so the occurrence of
+<literal>y</literal> in the body of the <literal>let</literal> will see the
+inner binding of <literal>?x</literal>, so <literal>(f 9)</literal> will return
+<literal>14</literal>.
+</para>
+</sect3>
 </sect2>
 
 <sect2 id="linear-implicit-parameters">
@@ -2664,22 +2776,19 @@ for rank-2 types.
 </title>
 
 <para>
-A <emphasis>pattern type signature</emphasis> can introduce a <emphasis>scoped type
-variable</emphasis>.  For example
-</para>
-
-<para>
-
+A <emphasis>lexically scoped type variable</emphasis> can be bound by:
+<itemizedlist>
+<listitem><para>A declaration type signature (<xref linkend="decl-type-sigs"/>)</para></listitem>
+<listitem><para>A pattern type signature (<xref linkend="pattern-type-sigs"/>)</para></listitem>
+<listitem><para>A result type signature (<xref linkend="result-type-sigs"/>)</para></listitem>
+</itemizedlist>
+For example:
 <programlisting>
 f (xs::[a]) = ys ++ ys
            where
               ys :: [a]
               ys = reverse xs
 </programlisting>
-
-</para>
-
-<para>
 The pattern <literal>(xs::[a])</literal> includes a type signature for <varname>xs</varname>.
 This brings the type variable <literal>a</literal> into scope; it scopes over
 all the patterns and right hand sides for this equation for <function>f</function>.
@@ -2687,8 +2796,6 @@ In particular, it is in scope at the type signature for <varname>y</varname>.
 </para>
 
 <para>
- Pattern type signatures are completely orthogonal to ordinary, separate
-type signatures.  The two can be used independently or together.
 At ordinary type signatures, such as that for <varname>ys</varname>, any type variables
 mentioned in the type signature <emphasis>that are not in scope</emphasis> are
 implicitly universally quantified.  (If there are no type variables in
@@ -2711,10 +2818,10 @@ So much for the basic idea.  Here are the details.
 </para>
 
 <sect3>
-<title>What a pattern type signature means</title>
+<title>What a scoped type variable means</title>
 <para>
-A type variable brought into scope by a pattern type signature is simply
-the name for a type.   The restriction they express is that all occurrences
+A lexically-scoped type variable is simply
+the name for a type.   The restriction it expresses is that all occurrences
 of the same name mean the same type.  For example:
 <programlisting>
   f :: [Int] -> Int -> Int
@@ -2884,7 +2991,33 @@ scope over the methods defined in the <literal>where</literal> part.  For exampl
 
 </sect3>
 
-<sect3>
+<sect3 id="decl-type-sigs">
+<title>Declaration type signatures</title>
+<para>A declaration type signature that has <emphasis>explicit</emphasis>
+quantification (using <literal>forall</literal>) brings into scope the
+explicitly-quantified
+type variables, in the definition of the named function(s).  For example:
+<programlisting>
+  f :: forall a. [a] -> [a]
+  f (x:xs) = xs ++ [ x :: a ]
+</programlisting>
+The "<literal>forall a</literal>" brings "<literal>a</literal>" into scope in
+the definition of "<literal>f</literal>".
+</para>
+<para>This only happens if the quantification in <literal>f</literal>'s type
+signature is explicit.  For example:
+<programlisting>
+  g :: [a] -> [a]
+  g (x:xs) = xs ++ [ x :: a ]
+</programlisting>
+This program will be rejected, because "<literal>a</literal>" does not scope
+over the definition of "<literal>f</literal>", so "<literal>x::a</literal>"
+means "<literal>x::forall a. a</literal>" by Haskell's usual implicit
+quantification rules.
+</para>
+</sect3>
+
+<sect3 id="pattern-type-sigs">
 <title>Where a pattern type signature can occur</title>
 
 <para>
@@ -3001,10 +3134,12 @@ in <literal>f4</literal>'s scope.
 </listitem>
 </itemizedlist>
 </para>
+<para>Pattern type signatures are completely orthogonal to ordinary, separate
+type signatures.  The two can be used independently or together.</para>
 
 </sect3>
 
-<sect3>
+<sect3 id="result-type-sigs">
 <title>Result type signatures</title>
 
 <para>
@@ -3074,9 +3209,23 @@ classes <literal>Eq</literal>, <literal>Ord</literal>,
 GHC extends this list with two more classes that may be automatically derived 
 (provided the <option>-fglasgow-exts</option> flag is specified):
 <literal>Typeable</literal>, and <literal>Data</literal>.  These classes are defined in the library
-modules <literal>Data.Dynamic</literal> and <literal>Data.Generics</literal> respectively, and the
+modules <literal>Data.Typeable</literal> and <literal>Data.Generics</literal> respectively, and the
 appropriate class must be in scope before it can be mentioned in the <literal>deriving</literal> clause.
 </para>
+<para>An instance of <literal>Typeable</literal> can only be derived if the
+data type has seven or fewer type parameters, all of kind <literal>*</literal>.
+The reason for this is that the <literal>Typeable</literal> class is derived using the scheme
+described in
+<ulink url="http://research.microsoft.com/%7Esimonpj/papers/hmap/gmap2.ps">
+Scrap More Boilerplate: Reflection, Zips, and Generalised Casts
+</ulink>.
+(Section 7.4 of the paper describes the multiple <literal>Typeable</literal> classes that
+are used, and only <literal>Typeable1</literal> up to
+<literal>Typeable7</literal> are provided in the library.)
+In other cases, there is nothing to stop the programmer writing a <literal>TypableX</literal>
+class, whose kind suits that of the data type constructor, and
+then writing the data type instance by hand.
+</para>
 </sect2>
 
 <sect2 id="newtype-deriving">
@@ -3189,7 +3338,7 @@ class to the new type:
 <para>
 
 As a result of this extension, all derived instances in newtype
-declarations are treated uniformly (and implemented just by reusing
+ declarations are treated uniformly (and implemented just by reusing
 the dictionary for the representation type), <emphasis>except</emphasis>
 <literal>Show</literal> and <literal>Read</literal>, which really behave differently for
 the newtype and its representation.
@@ -3270,10 +3419,80 @@ then we would not have been able to derive an instance for the
 classes usually have one "main" parameter for which deriving new
 instances is most interesting.
 </para>
+<para>Lastly, all of this applies only for classes other than
+<literal>Read</literal>, <literal>Show</literal>, <literal>Typeable</literal>, 
+and <literal>Data</literal>, for which the built-in derivation applies (section
+4.3.3. of the Haskell Report).
+(For the standard classes <literal>Eq</literal>, <literal>Ord</literal>,
+<literal>Ix</literal>, and <literal>Bounded</literal> it is immaterial whether
+the standard method is used or the one described here.)
+</para>
 </sect3>
 
 </sect2>
 
+<sect2 id="typing-binds">
+<title>Generalised typing of mutually recursive bindings</title>
+
+<para>
+The Haskell Report specifies that a group of bindings (at top level, or in a
+<literal>let</literal> or <literal>where</literal>) should be sorted into
+strongly-connected components, and then type-checked in dependency order
+(<ulink url="http://haskell.org/onlinereport/decls.html#sect4.5.1">Haskell
+Report, Section 4.5.1</ulink>).  
+As each group is type-checked, any binders of the group that
+have
+an explicit type signature are put in the type environment with the specified
+polymorphic type,
+and all others are monomorphic until the group is generalised 
+(<ulink url="http://haskell.org/onlinereport/decls.html#sect4.5.2">Haskell Report, Section 4.5.2</ulink>).
+</para>
+
+<para>Following a suggestion of Mark Jones, in his paper
+<ulink url="http://www.cse.ogi.edu/~mpj/thih/">Typing Haskell in
+Haskell</ulink>,
+GHC implements a more general scheme.  If <option>-fglasgow-exts</option> is
+specified:
+<emphasis>the dependency analysis ignores references to variables that have an explicit
+type signature</emphasis>.
+As a result of this refined dependency analysis, the dependency groups are smaller, and more bindings will
+typecheck.  For example, consider:
+<programlisting>
+  f :: Eq a =&gt; a -> Bool
+  f x = (x == x) || g True || g "Yes"
+  
+  g y = (y &lt;= y) || f True
+</programlisting>
+This is rejected by Haskell 98, but under Jones's scheme the definition for
+<literal>g</literal> is typechecked first, separately from that for
+<literal>f</literal>,
+because the reference to <literal>f</literal> in <literal>g</literal>'s right
+hand side is ingored by the dependency analysis.  Then <literal>g</literal>'s
+type is generalised, to get
+<programlisting>
+  g :: Ord a =&gt; a -> Bool
+</programlisting>
+Now, the defintion for <literal>f</literal> is typechecked, with this type for
+<literal>g</literal> in the type environment.
+</para>
+
+<para>
+The same refined dependency analysis also allows the type signatures of 
+mutually-recursive functions to have different contexts, something that is illegal in
+Haskell 98 (Section 4.5.2, last sentence).  With
+<option>-fglasgow-exts</option>
+GHC only insists that the type signatures of a <emphasis>refined</emphasis> group have identical
+type signatures; in practice this means that only variables bound by the same
+pattern binding must have the same context.  For example, this is fine:
+<programlisting>
+  f :: Eq a =&gt; a -> Bool
+  f x = (x == x) || g True
+  
+  g :: Ord a =&gt; a -> Bool
+  g y = (y &lt;= y) || f True
+</programlisting>
+</para>
+</sect2>
 
 </sect1>
 <!-- ==================== End of type system extensions =================  -->
@@ -3334,9 +3553,10 @@ type above, the type of each constructor must end with <literal> ... -> Term ...
 </para></listitem>
 
 <listitem><para>
-You cannot use a <literal>deriving</literal> clause on a GADT-style data type declaration,
-nor can you use record syntax.  (It's not clear what these constructs would mean.  For example,
-the record selectors might ill-typed.)  However, you can use strictness annotations, in the obvious places
+You cannot use record syntax on a GADT-style data type declaration.  (
+It's not clear what these it would mean.  For example,
+the record selectors might ill-typed.)
+However, you can use strictness annotations, in the obvious places
 in the constructor type:
 <programlisting>
   data Term a where
@@ -3347,6 +3567,23 @@ in the constructor type:
 </para></listitem>
 
 <listitem><para>
+You can use a <literal>deriving</literal> clause on a GADT-style data type
+declaration, but only if the data type could also have been declared in
+Haskell-98 syntax.   For example, these two declarations are equivalent
+<programlisting>
+  data Maybe1 a where {
+      Nothing1 :: Maybe a ;
+      Just1    :: a -> Maybe a
+    } deriving( Eq, Ord )
+
+  data Maybe2 a = Nothing2 | Just2 a 
+       deriving( Eq, Ord )
+</programlisting>
+This simply allows you to declare a vanilla Haskell-98 data type using the
+<literal>where</literal> form without losing the <literal>deriving</literal> clause.
+</para></listitem>
+
+<listitem><para>
 Pattern matching causes type refinement.  For example, in the right hand side of the equation
 <programlisting>
   eval :: Term a -> a
@@ -3374,7 +3611,7 @@ the result type of the <literal>case</literal> expression.  Hence the addition <
 <para>Notice that GADTs generalise existential types.  For example, these two declarations are equivalent:
 <programlisting>
   data T a = forall b. MkT b (b->a)
-  data T' a where { MKT :: b -> (b->a) -> T a }
+  data T' a where { MKT :: b -> (b->a) -> T' a }
 </programlisting>
 </para>
 </sect1>
@@ -3430,9 +3667,11 @@ Tim Sheard is going to expand it.)
                  </para>
              <para> A splice can occur in place of 
                  <itemizedlist>
-                   <listitem><para> an expression; the spliced expression must have type <literal>Expr</literal></para></listitem>
+                   <listitem><para> an expression; the spliced expression must
+                   have type <literal>Q Exp</literal></para></listitem>
                    <listitem><para> a list of top-level declarations; ; the spliced expression must have type <literal>Q [Dec]</literal></para></listitem>
-                   <listitem><para> a type; the spliced expression must have type <literal>Type</literal>.</para></listitem>
+                   <listitem><para> [Planned, but not implemented yet.] a
+                   type; the spliced expression must have type <literal>Q Typ</literal>.</para></listitem>
                    </itemizedlist>
           (Note that the syntax for a declaration splice uses "<literal>$</literal>" not "<literal>splice</literal>" as in
        the paper. Also the type of the enclosed expression must be  <literal>Q [Dec]</literal>, not  <literal>[Q Dec]</literal>
@@ -3447,7 +3686,7 @@ Tim Sheard is going to expand it.)
                              the quotation has type <literal>Expr</literal>.</para></listitem>
                    <listitem><para> <literal>[d| ... |]</literal>, where the "..." is a list of top-level declarations;
                              the quotation has type <literal>Q [Dec]</literal>.</para></listitem>
-                   <listitem><para> <literal>[t| ... |]</literal>, where the "..." is a type; 
+                   <listitem><para>  [Planned, but not implemented yet.]  <literal>[t| ... |]</literal>, where the "..." is a type; 
                              the quotation has type <literal>Type</literal>.</para></listitem>
                  </itemizedlist></para></listitem>
 
@@ -3693,7 +3932,7 @@ proc x -> f x -&lt;&lt; x+1
 </screen>
 which is equivalent to
 <screen>
-arr (\ x -> (f, x+1)) >>> app
+arr (\ x -> (f x, x+1)) >>> app
 </screen>
 so in this case the arrow must belong to the <literal>ArrowApply</literal>
 class.
@@ -4130,12 +4369,13 @@ can still define and use your own versions of
 </para>
 
 <para>
-To have the compiler ignore uses of assert, use the compiler option
-<option>-fignore-asserts</option>. <indexterm><primary>-fignore-asserts
-option</primary></indexterm> That is, expressions of the form
+GHC ignores assertions when optimisation is turned on with the
+      <option>-O</option><indexterm><primary><option>-O</option></primary></indexterm> flag.  That is, expressions of the form
 <literal>assert pred e</literal> will be rewritten to
-<literal>e</literal>.
-</para>
+<literal>e</literal>.  You can also disable assertions using the
+      <option>-fignore-asserts</option>
+      option<indexterm><primary><option>-fignore-asserts</option></primary>
+      </indexterm>.</para>
 
 <para>
 Assertion failures can be caught, see the documentation for the
@@ -4192,7 +4432,7 @@ Assertion failures can be caught, see the documentation for the
        </listitem>
 
        <listitem>
-         <para>You can deprecate a function, class, or type, with the
+         <para>You can deprecate a function, class, type, or data constructor, with the
          following top-level declaration:</para>
 <programlisting>
    {-# DEPRECATED f, C, T "Don't use these" #-}
@@ -4200,6 +4440,13 @@ Assertion failures can be caught, see the documentation for the
          <para>When you compile any module that imports and uses any
           of the specified entities, GHC will print the specified
           message.</para>
+         <para> You can only depecate entities declared at top level in the module
+         being compiled, and you can only use unqualified names in the list of
+         entities being deprecated.  A capitalised name, such as <literal>T</literal>
+         refers to <emphasis>either</emphasis> the type constructor <literal>T</literal>
+         <emphasis>or</emphasis> the data constructor <literal>T</literal>, or both if
+         both are in scope.  If both are in scope, there is currently no way to deprecate 
+         one without the other (c.f. fixities <xref linkend="infix-tycons"/>).</para>
        </listitem>
       </itemizedlist>
       Any use of the deprecated item, or of anything from a deprecated
@@ -4391,6 +4638,29 @@ key_function :: Int -> String -> (Bool, Double)
       </sect3>
     </sect2>
 
+    <sect2 id="language-pragma">
+      <title>LANGUAGE pragma</title>
+
+      <indexterm><primary>LANGUAGE</primary><secondary>pragma</secondary></indexterm>
+      <indexterm><primary>pragma</primary><secondary>LANGUAGE</secondary></indexterm>
+
+      <para>This allows language extensions to be enabled in a portable way.
+       It is the intention that all Haskell compilers support the
+       <literal>LANGUAGE</literal> pragma with the same syntax, although not
+       all extensions are supported by all compilers, of
+       course.  The <literal>LANGUAGE</literal> pragma should be used instead
+       of <literal>OPTIONS_GHC</literal>, if possible.</para>
+
+      <para>For example, to enable the FFI and preprocessing with CPP:</para>
+
+<programlisting>{-# LANGUAGE ForeignFunctionInterface, CPP #-}</programlisting>
+
+      <para>Any extension from the <literal>Extension</literal> type defined in
+       <ulink
+         url="../libraries/Cabal/Language-Haskell-Extension.html"><literal>Language.Haskell.Extension</literal></ulink> may be used.  GHC will report an error if any of the requested extensions are not supported.</para>
+    </sect2>
+
+
     <sect2 id="line-pragma">
       <title>LINE pragma</title>
 
@@ -4401,9 +4671,7 @@ key_function :: Int -> String -> (Bool, Double)
       code.  It lets you specify the line number and filename of the
       original code; for example</para>
 
-<programlisting>
-{-# LINE 42 "Foo.vhs" #-}
-</programlisting>
+<programlisting>{-# LINE 42 "Foo.vhs" #-}</programlisting>
 
       <para>if you'd generated the current file from something called
       <filename>Foo.vhs</filename> and this line corresponds to line
@@ -4448,7 +4716,7 @@ key_function :: Int -> String -> (Bool, Double)
       overloaded function:</para>
 
 <programlisting>
-hammeredLookup :: Ord key => [(key, value)] -> key -> value
+  hammeredLookup :: Ord key => [(key, value)] -> key -> value
 </programlisting>
 
       <para>If it is heavily used on lists with
@@ -4456,7 +4724,7 @@ hammeredLookup :: Ord key => [(key, value)] -> key -> value
       follows:</para>
 
 <programlisting>
-{-# SPECIALIZE hammeredLookup :: [(Widget, value)] -> Widget -> value #-}
+  {-# SPECIALIZE hammeredLookup :: [(Widget, value)] -> Widget -> value #-}
 </programlisting>
 
       <para>A <literal>SPECIALIZE</literal> pragma for a function can
@@ -4467,7 +4735,35 @@ hammeredLookup :: Ord key => [(key, value)] -> key -> value
       (see <xref linkend="rewrite-rules"/>) that rewrites a call to the
       un-specialised function into a call to the specialised one.</para>
 
-      <para>In earlier versions of GHC, it was possible to provide your own
+      <para>The type in a SPECIALIZE pragma can be any type that is less
+       polymorphic than the type of the original function.  In concrete terms,
+       if the original function is <literal>f</literal> then the pragma
+<programlisting>
+  {-# SPECIALIZE f :: &lt;type&gt; #-}
+</programlisting>
+      is valid if and only if the defintion
+<programlisting>
+  f_spec :: &lt;type&gt;
+  f_spec = f
+</programlisting>
+      is valid.  Here are some examples (where we only give the type signature
+      for the original function, not its code):
+<programlisting>
+  f :: Eq a => a -> b -> b
+  {-# SPECIALISE g :: Int -> b -> b #-}
+
+  g :: (Eq a, Ix b) => a -> b -> b
+  {-# SPECIALISE g :: (Eq a) => a -> Int -> Int #-}
+
+  h :: Eq a => a -> a -> a
+  {-# SPECIALISE h :: (Eq a) => [a] -> [a] -> [a] #-}
+</programlisting>  
+The last of these examples will generate a 
+RULE with a somewhat-complex left-hand side (try it yourself), so it might not fire very
+well.  If you use this kind of specialisation, let us know how well it works.
+</para>
+
+      <para>Note: In earlier versions of GHC, it was possible to provide your own
       specialised function for a given type:
 
 <programlisting>