X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=docs%2Fusers_guide%2Fglasgow_exts.xml;h=c370ce3388308a602a0f020a8745652fed0b5d3e;hb=2ab65c00417e668f8a2a3f98fde51448dda83d6e;hp=0fb3dd17084b1d0f02ac940cbb9e9c183993af48;hpb=5d675b1a99cfa0a2a083a5e0a0c8938d99d426bf;p=ghc-hetmet.git
diff --git a/docs/users_guide/glasgow_exts.xml b/docs/users_guide/glasgow_exts.xml
index 0fb3dd1..c370ce3 100644
--- a/docs/users_guide/glasgow_exts.xml
+++ b/docs/users_guide/glasgow_exts.xml
@@ -106,9 +106,7 @@ documentation describes all the libraries that come with GHC.
This option enables the language extension defined in the
- Haskell 98 Foreign Function Interface Addendum plus deprecated
- syntax of previous versions of the FFI for backwards
- compatibility.
+ Haskell 98 Foreign Function Interface Addendum.
New reserved words: foreign.
@@ -116,7 +114,7 @@ documentation describes all the libraries that come with GHC.
- ,:
+ ,:
These two flags control how generalisation is done.
@@ -905,6 +903,38 @@ fromInteger :: Integer -> Bool -> Bool
you should be all right.
+
+
+Postfix operators
+
+
+GHC allows a small extension to the syntax of left operator sections, which
+allows you to define postfix operators. The extension is this: the left section
+
+ (e !)
+
+is equivalent (from the point of view of both type checking and execution) to the expression
+
+ ((!) e)
+
+(for any expression e and operator (!).
+The strict Haskell 98 interpretation is that the section is equivalent to
+
+ (\y -> (!) e y)
+
+That is, the operator must be a function of two arguments. GHC allows it to
+take only one argument, and that in turn allows you to write the function
+postfix.
+
+Since this extension goes beyond Haskell 98, it should really be enabled
+by a flag; but in fact it is enabled all the time. (No Haskell 98 programs
+change their behaviour, of course.)
+
+The extension does not extend to the left-hand side of function
+definitions; you must define such a function in prefix form.
+
+
+
@@ -3269,6 +3299,7 @@ changing the program.
A lexically scoped type variable can be bound by:
A declaration type signature ()
+An expression type signature ()A pattern type signature ()Class and instance declarations ()
@@ -3320,6 +3351,23 @@ quantification rules.
+
+Expression type signatures
+
+An expression type signature that has explicit
+quantification (using forall) brings into scope the
+explicitly-quantified
+type variables, in the annotated expression. For example:
+
+ f = runST ( (op >>= \(x :: STRef s Int) -> g x) :: forall s. ST s Bool )
+
+Here, the type signature forall a. ST s Bool brings the
+type variable s into scope, in the annotated expression
+(op >>= \(x :: STRef s Int) -> g x).
+
+
+
+
Pattern type signatures
@@ -3328,7 +3376,7 @@ signature.
For example:
-- f and g assume that 'a' is already in scope
- f = \(x::Int, y) -> x
+ f = \(x::Int, y::a) -> x
g (x::a) = x
h ((x,y) :: (Int,Bool)) = (y,x)
@@ -3608,16 +3656,19 @@ declaration (after expansion of any type synonyms)
where
- The type t is an arbitrary type
+ The ci are partial applications of
+ classes of the form C t1'...tj', where the arity of C
+ is exactly j+1. That is, C lacks exactly one type argument.
+
+
+ The k is chosen so that ci (T v1...vk) is well-kinded.
- The vk+1...vn are type variables which do not occur in
- t, and
+ The type t is an arbitrary type.
- The ci are partial applications of
- classes of the form C t1'...tj', where the arity of C
- is exactly j+1. That is, C lacks exactly one type argument.
+ The type variables vk+1...vn do not occur in t,
+ nor in the ci, and
None of the ci is Read, Show,
@@ -3630,13 +3681,8 @@ where
Then, for each ci, the derived instance
declaration is:
- instance ci (t vk+1...v) => ci (T v1...vp)
+ instance ci t => ci (T v1...vk)
-where p is chosen so that T v1...vp is of the
-right kind for the last parameter of class Ci.
-
-
-
As an example which does not work, consider
newtype NonMonad m s = NonMonad (State s m s) deriving Monad
@@ -3679,6 +3725,33 @@ the standard method is used or the one described here.)
+
+Stand-alone deriving declarations
+
+
+GHC now allows stand-alone deriving declarations:
+
+
+
+ data Foo = Bar Int | Baz String
+
+ deriving Eq for Foo
+
+
+Deriving instances of multi-parameter type classes for newtypes is
+also allowed:
+
+
+ newtype Foo a = MkFoo (State Int a)
+
+ deriving (MonadState Int) for Foo
+
+
+
+
+
+
+
Generalised typing of mutually recursive bindings
@@ -3748,9 +3821,9 @@ pattern binding must have the same context. For example, this is fine:
-Generalised Algebraic Data Types
+Generalised Algebraic Data Types (GADTs)
-Generalised Algebraic Data Types (GADTs) generalise ordinary algebraic data types by allowing you
+Generalised Algebraic Data Types generalise ordinary algebraic data types by allowing you
to give the type signatures of constructors explicitly. For example:
data Term a where
@@ -3771,7 +3844,12 @@ for these Terms:
eval (If b e1 e2) = if eval b then eval e1 else eval e2
eval (Pair e1 e2) = (eval e1, eval e2)
-These and many other examples are given in papers by Hongwei Xi, and Tim Sheard.
+These and many other examples are given in papers by Hongwei Xi, and
+Tim Sheard. There is a longer introduction
+on the wiki,
+and Ralf Hinze's
+Fun with phantom types also has a number of examples. Note that papers
+may use different notation to that implemented in GHC.
The rest of this section outlines the extensions to GHC that support GADTs.
@@ -3871,8 +3949,8 @@ declaration, but only if the data type could also have been declared in
Haskell-98 syntax. For example, these two declarations are equivalent
data Maybe1 a where {
- Nothing1 :: Maybe a ;
- Just1 :: a -> Maybe a
+ Nothing1 :: Maybe1 a ;
+ Just1 :: a -> Maybe1 a
} deriving( Eq, Ord )
data Maybe2 a = Nothing2 | Just2 a