From: rrt Date: Mon, 9 Oct 2000 16:51:01 +0000 (+0000) Subject: [project @ 2000-10-09 16:51:01 by rrt] X-Git-Tag: Approximately_9120_patches~3662 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=9cd3ca368ac5342202ad286885b1ac9c196ecd7c;p=ghc-hetmet.git [project @ 2000-10-09 16:51:01 by rrt] Many fixes to make it DocBook friendly. --- diff --git a/ghc/docs/users_guide/glasgow_exts.sgml b/ghc/docs/users_guide/glasgow_exts.sgml index b52adc9..09abc48 100644 --- a/ghc/docs/users_guide/glasgow_exts.sgml +++ b/ghc/docs/users_guide/glasgow_exts.sgml @@ -4277,7 +4277,7 @@ Now you can make a data type into an instance of Bin like this: That is, just leave off the "where" clasuse. Of course, you can put in the where clause and over-ride whichever methods you please. - + Using generics @@ -4285,13 +4285,17 @@ where clause and over-ride whichever methods you please. To use generics you need to + Use the flag. + + Import the module Generics from the lang package. This import brings into scope the data types Unit, :*:, and :+:. (You don't need this import if you don't mention these types explicitly; for example, if you are simply giving instance declarations.) + @@ -4316,17 +4320,27 @@ A "polymorphic default method" is a default method defined as in Haskell 98. A "generic class declaration" is a class declaration with at least one generic default method. + + Restrictions: - Alas, we do not yet implement the stuff about constructor names and + + +Alas, we do not yet implement the stuff about constructor names and field labels. + - A generic class can have only one parameter; you can't have a generic + + +A generic class can have only one parameter; you can't have a generic multi-parameter class. + - A default method must be defined entirely using type patterns, or entirely + + +A default method must be defined entirely using type patterns, or entirely without. So this is illegal: class Foo a where @@ -4336,19 +4350,25 @@ without. So this is illegal: However it is perfectly OK for some methods of a generic class to have generic default methods and others to have polymorphic default methods. + - The type variable(s) in the type pattern for a generic method declaration -scope over the right hand side. So this is legal (note the use of the type variable -"p" in a type signature on the right hand side: + + +The type variable(s) in the type pattern for a generic method declaration +scope over the right hand side. So this is legal (note the use of the type variable ``p'' in a type signature on the right hand side: class Foo a where op :: a -> Bool op {| p :*: q |} (x :*: y) = op (x :: p) ... + + - The type patterns in a generic default method must take one of the forms: + + +The type patterns in a generic default method must take one of the forms: a :+: b a :*: b @@ -4375,26 +4395,41 @@ So this too is illegal: (The reason for this restriction is that we gather all the equations for a particular type consructor into a single generic instance declaration.) + - A generic method declaration must give a case for each of the three type constructors. + + +A generic method declaration must give a case for each of the three type constructors. + - In an instance declaration for a generic class, the idea is that the compiler + + +In an instance declaration for a generic class, the idea is that the compiler will fill in the methods for you, based on the generic templates. However it can only do so if - The instance type is simple (a type constructor applied to type variables, as in Haskell 98). - - No constructor of the instance type has unboxed fields. + + + The instance type is simple (a type constructor applied to type variables, as in Haskell 98). + + + + + No constructor of the instance type has unboxed fields. + + (Of course, these things can only arise if you are already using GHC extensions.) However, you can still give an instance declarations for types which break these rules, provided you give explicit code to override any generic default methods. - + + + The option dumps incomprehensible stuff giving details of what the compiler does with generic declarations. @@ -4418,6 +4453,7 @@ Just to finish with, here's another example I rather like: tag {| a :+: b |} (Inl x) = tag x tag {| a :+: b |} (Inr y) = nCons (bot::a) + tag y + diff --git a/ghc/docs/users_guide/using.sgml b/ghc/docs/users_guide/using.sgml index 92517b0..8d6d658 100644 --- a/ghc/docs/users_guide/using.sgml +++ b/ghc/docs/users_guide/using.sgml @@ -905,17 +905,23 @@ It completely defeats that purpose if the literal "1" means "Prelude.fr which is what the Haskell Report specifies. So the flag causes the following pieces of built-in syntax to refer to whatever is in scope, not the Prelude versions: - + + Integer and fractional literals mean "fromInteger 1" and "fromRational 3.2", not the Prelude-qualified versions; both in expressions and in patterns. + + Negation (e.g. "- (f x)") means "negate (f x)" (not Prelude.negate). + -In an n+k pattern, the standard Prelude OrdK/Literal> class is used for comparison, but the + +In an n+k pattern, the standard Prelude Ord class is used for comparison, but the necessary subtraction uses whatever "(-)" is in scope (not "Prelude.(-)"). + @@ -2147,6 +2153,7 @@ apply (see ). : + Switches on an experimental "optimisation". Switching it on makes the compiler a little keener to inline a function that returns a constructor, if the context is that of a thunk.