From: Jose Pedro Magalhaes Date: Mon, 9 May 2011 10:07:02 +0000 (+0200) Subject: "Representable0" -> "Generic" in the user's guide. X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=903619a6c848b509a4084c9ae60f96ccde6c84e5 "Representable0" -> "Generic" in the user's guide. --- diff --git a/docs/users_guide/flags.xml b/docs/users_guide/flags.xml index 982c681..96dfc1b 100644 --- a/docs/users_guide/flags.xml +++ b/docs/users_guide/flags.xml @@ -682,8 +682,7 @@ - Enables and . - No longer enables generic classes. + Deprecated, does nothing. No longer enables generic classes. See also GHC's support for generic programming. dynamic @@ -980,10 +979,10 @@ - - Enable deriving for the Representable0 class. + + Enable deriving for the Generic class. dynamic - + diff --git a/docs/users_guide/glasgow_exts.xml b/docs/users_guide/glasgow_exts.xml index 178f79a..93f0d3c 100644 --- a/docs/users_guide/glasgow_exts.xml +++ b/docs/users_guide/glasgow_exts.xml @@ -3212,8 +3212,8 @@ then writing the data type instance by hand. - With , you can derive -instances of the class Representable0, defined in + With , you can derive +instances of the class Generic, defined in GHC.Generics. You can use these to define generic functions, as described in . @@ -3561,8 +3561,8 @@ you can specify a default method that uses that generic implementation: class Enum a where enum :: [a] - default enum :: (Representable0 a, GEnum (Rep0 a)) => [a] - enum = map to0 genum + default enum :: (Generic a, GEnum (Rep a)) => [a] + enum = map to genum We reuse the keyword default to signal that a signature applies to the default method only; when defining instances of the @@ -3570,7 +3570,7 @@ applies to the default method only; when defining instances of the enum still applies. When giving an empty instance, however, the default implementation map to0 genum is filled-in, and type-checked with the type -(Representable0 a, GEnum (Rep0 a)) => [a]. +(Generic a, GEnum (Rep a)) => [a]. @@ -9199,10 +9199,10 @@ general support for generic programmingGeneric programming -Using a combination of +Using a combination of () and (), -or simply , you can easily do datatype-generic +you can easily do datatype-generic programming using the GHC.Generics framework. This section gives a very brief overview of how to do it. For more detail please refer to the HaskellWiki page @@ -9223,8 +9223,8 @@ Jos Note: the current support for generic programming in GHC is preliminary. In particular, we only allow deriving instances for the -Representable0 class. Support for deriving -Representable1 (and thus enabling generic functions of kind +Generic class. Support for deriving +Generic1 (and thus enabling generic functions of kind * -> * such as fmap) will come at a later stage. @@ -9260,21 +9260,21 @@ For example, a user-defined datatype of trees data UserTree a = Node a (UserTree a) (UserTree a) | Leaf gets the following representation: --- Representation type -type instance Rep0 (UserTree a) = - M1 D D1UserTree ( - M1 C C1_0UserTree ( - M1 S NoSelector (K1 P a) - :*: M1 S NoSelector (K1 R (UserTree a)) - :*: M1 S NoSelector (K1 R (UserTree a))) - :+: M1 C C1_1UserTree U1) +instance Generic (UserTree a) where + -- Representation type + type Rep (UserTree a) = + M1 D D1UserTree ( + M1 C C1_0UserTree ( + M1 S NoSelector (K1 P a) + :*: M1 S NoSelector (K1 R (UserTree a)) + :*: M1 S NoSelector (K1 R (UserTree a))) + :+: M1 C C1_1UserTree U1) --- Representable0 instance -instance Representable0 (UserTree a) where - from0 (Node x l r) = M1 (L1 (M1 (M1 (K1 x) :*: M1 (K1 l) :*: M1 (K1 r)))) - from0 Leaf = M1 (R1 (M1 U1)) - to0 (M1 (L1 (M1 (M1 (K1 x) :*: M1 (K1 l) :*: M1 (K1 r))))) = Node x l r - to0 (M1 (R1 (M1 U1))) = Leaf + -- Conversion functions + from (Node x l r) = M1 (L1 (M1 (M1 (K1 x) :*: M1 (K1 l) :*: M1 (K1 r)))) + from Leaf = M1 (R1 (M1 U1)) + to (M1 (L1 (M1 (M1 (K1 x) :*: M1 (K1 l) :*: M1 (K1 r))))) = Node x l r + to (M1 (R1 (M1 U1))) = Leaf -- Meta-information data D1UserTree @@ -9293,7 +9293,7 @@ instance Constructor C1_1UserTree where This representation is generated automatically if a -deriving Representable0 clause is attached to the datatype. +deriving Generic clause is attached to the datatype. Standalone deriving can also be used. @@ -9344,12 +9344,12 @@ exposed to the user: class Serialize a where put :: a -> [Bin] - default put :: (Representable0 a, GSerialize (Rep0 a)) => a -> [Bit] - put a = gput (from0 a) + default put :: (Generic a, GSerialize (Rep a)) => a -> [Bit] + put = gput . from Here we use a default signature to specify that the user does not have to provide an implementation for -put, as long as there is a Representable0 +put, as long as there is a Generic instance for the type to instantiate. For the UserTree type, for instance, the user can just write: