X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=docs%2Fusers_guide%2Fglasgow_exts.xml;h=09fd3f509fd4efbab42e79ee8ffaa3e7e508f797;hb=bebf54b1fefef0c337955ec1e653b44f4ec63d10;hp=7e085836e590386c98f5f5e957e2fae01dc6be54;hpb=395f018ba53d1bc09a03aa5083032dc96c911c6c;p=ghc-hetmet.git diff --git a/docs/users_guide/glasgow_exts.xml b/docs/users_guide/glasgow_exts.xml index 7e08583..09fd3f5 100644 --- a/docs/users_guide/glasgow_exts.xml +++ b/docs/users_guide/glasgow_exts.xml @@ -3360,7 +3360,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) @@ -3640,16 +3640,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 vk+1...vn are type variables which do not occur in - t, and + The k is chosen so that ci (T v1...vk) is well-kinded. - 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 t is an arbitrary type. + + + The type variables vk+1...vn do not occur in t, + nor in the ci, and None of the ci is Read, Show, @@ -3662,13 +3665,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 @@ -3780,9 +3778,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 @@ -3803,7 +3801,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. @@ -3903,8 +3906,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