packages feed

generic-deriving 1.2.1 → 1.2.2

raw patch · 4 files changed

+105/−66 lines, 4 filesdep ~basedep ~ghc-primdep ~template-haskellPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: base, ghc-prim, template-haskell

API changes (from Hackage documentation)

- Generics.Deriving.Instances: instance Constructor Cons__
- Generics.Deriving.Instances: instance Constructor Just_
- Generics.Deriving.Instances: instance Constructor Nil__
- Generics.Deriving.Instances: instance Constructor Nothing_
- Generics.Deriving.Instances: instance Datatype List__
- Generics.Deriving.Instances: instance Datatype Maybe_
- Generics.Deriving.Instances: instance Generic1 Maybe
- Generics.Deriving.Instances: instance Generic1 []
- Generics.Deriving.Instances: type Rep1List = D1 List__ ((C1 Nil__ U1) :+: (C1 Cons__ (Par1 :*: Rec1 [])))
- Generics.Deriving.Instances: type Rep1Maybe = D1 Maybe_ (C1 Nothing_ U1 :+: C1 Just_ Par1)
- Generics.Deriving.Base: class Generic a where type family Rep a :: * -> *
+ Generics.Deriving.Base: class Generic a where type family Rep a1 :: * -> *
- Generics.Deriving.Base: class Generic1 (f :: * -> *) where type family Rep1 (f :: * -> *) :: * -> *
+ Generics.Deriving.Base: class Generic1 (f :: * -> *) where type family Rep1 (f1 :: * -> *) :: * -> *

Files

examples/Examples.hs view
@@ -8,6 +8,8 @@ {-# LANGUAGE UndecidableInstances #-}
 {-# LANGUAGE TemplateHaskell #-}
 {-# LANGUAGE KindSignatures #-}
+{-# LANGUAGE DatatypeContexts #-}
+{-# LANGUAGE DeriveFunctor #-}
 #if __GLASGOW_HASKELL__ >= 701
 {-# LANGUAGE DeriveGeneric #-}
 #endif
@@ -105,8 +107,7 @@ data List a = Nil | Cons a (List a) 
 
 #if __GLASGOW_HASKELL__ >= 701
-  deriving Generic
---deriving instance Generic (List a)
+deriving instance Generic (List a)
 #else
 
 type Rep0List_ a = D1 List_ ((:+:) (C1 Nil_ U1) (C1 Cons_ ((:*:) (Par0 a) (Rec0 (List a)))))
@@ -119,6 +120,10 @@ 
 #endif
 
+#if __GLASGOW_HASKELL__ >= 705
+deriving instance Generic1 List
+#else
+
 data List_
 data Nil_
 data Cons_
@@ -138,6 +143,8 @@   to1 (M1 (L1 (M1 U1)))                         = Nil
   to1 (M1 (R1 (M1 (Par1 h :*: Rec1 t)))) = Cons h t
 
+#endif
+
 #if __GLASGOW_HASKELL__ < 701
 -- Instance for generic functions (should be automatically generated)
 instance GFunctor List where
@@ -174,18 +181,24 @@ --------------------------------------------------------------------------------
 
 data Nested a = Leaf | Nested { value :: a, rec :: Nested [a] }
+  deriving Functor
 
 #if __GLASGOW_HASKELL__ >= 701
-  deriving Generic
--- deriving instance Generic (Nested a)
+deriving instance Generic (Nested a)
 #endif
 
+#if __GLASGOW_HASKELL__ < 705
 $(deriveMeta ''Nested)
+#endif
 
 #if __GLASGOW_HASKELL__ < 701
 $(deriveRepresentable0 ''Nested)
 #endif
 
+#if __GLASGOW_HASKELL__ >= 705
+deriving instance Generic1 Nested
+#else
+
 type RepNested = D1 Nested_ (C1 Nested_Leaf_ U1 :+: C1 Nested_Nested_ (Par1 :*: Nested :.: Rec1 []))
 instance Generic1 Nested where
   type Rep1 Nested = RepNested
@@ -193,6 +206,7 @@   from1 (Nested a l) = M1 (R1 (M1 (Par1 a :*: Comp1 (gmap Rec1 l))))
   to1 (M1 (L1 (M1 U1))) = Leaf
   to1 (M1 (R1 (M1 (Par1 a :*: Comp1 l)))) = Nested a (gmap unRec1 l)
+#endif
 
 #if __GLASGOW_HASKELL__ < 701
 -- Instance for gshow (should be automatically generated)
@@ -225,8 +239,7 @@ data Rose a = Rose [a] [Rose a]
 
 #if __GLASGOW_HASKELL__ >= 701
-  deriving Generic
--- deriving instance Generic (Rose a)
+deriving instance Generic (Rose a)
 #else
 
 type Rep0Rose a = D1 RoseD (C1 RoseC (Rec0 [a] :*: Rec0 [Rose a]))
@@ -237,6 +250,10 @@ 
 #endif
 
+#if __GLASGOW_HASKELL__ >= 705
+deriving instance Generic1 Rose
+#else
+
 data RoseD
 data RoseC
 
@@ -253,6 +270,8 @@   from1 (Rose a x) = M1 (M1 (Rec1 a :*: Comp1 (gmap Rec1 x)))
   to1 (M1 (M1 (Rec1 a :*: Comp1 x))) = Rose a (gmap unRec1 x)
 
+#endif
+
 #if __GLASGOW_HASKELL_ >= 701
 
 instance (GShow a) => GShow (Rose a)
@@ -282,22 +301,30 @@ 
 data GRose f a = GRose (f a) (f (GRose f a))
 
+deriving instance (Functor f) => Functor (GRose f)
+
 #if __GLASGOW_HASKELL__ >= 701
-  deriving Generic
---deriving instance Generic (GRose f a)
+deriving instance Generic (GRose f a)
 #endif
 
+#if __GLASGOW_HASKELL__ < 705
 $(deriveMeta ''GRose)
+#endif
 
 #if __GLASGOW_HASKELL__ < 701
 $(deriveRepresentable0 ''GRose)
 #endif
 
+#if __GLASGOW_HASKELL__ >= 705
+deriving instance (Functor f) => Generic1 (GRose f)
+#else
+
 type Rep1GRose f = D1 GRose_ (C1 GRose_GRose_ (Rec1 f :*: f :.: (Rec1 (GRose f))))
 instance (GFunctor f) => Generic1 (GRose f) where
   type Rep1 (GRose f) = Rep1GRose f
   from1 (GRose a x) = M1 (M1 (Rec1 a :*: Comp1 (gmap Rec1 x)))
   to1 (M1 (M1 (Rec1 a :*: Comp1 x))) = GRose a (gmap unRec1 x)
+#endif
 
 #if __GLASGOW_HASKELL__ < 701
 -- Requires UndecidableInstances
@@ -310,7 +337,7 @@ #else
 
 instance (GShow (f a), GShow (f (GRose f a))) => GShow (GRose f a)
-instance (GFunctor f) => GFunctor (GRose f)
+instance (Functor f, GFunctor f) => GFunctor (GRose f)
 
 #endif
 
@@ -405,19 +432,23 @@ -- Example: Nested datatype Bush (minimal)
 --------------------------------------------------------------------------------
 
-data Bush a = BushNil | BushCons a (Bush (Bush a))
+data Bush a = BushNil | BushCons a (Bush (Bush a)) deriving Functor
 
 #if __GLASGOW_HASKELL__ >= 701
-  deriving Generic
---deriving instance Generic (Bush a)
+deriving instance Generic (Bush a)
 #endif
 
+#if __GLASGOW_HASKELL__ < 705
 $(deriveMeta ''Bush)
+#endif
 
 #if __GLASGOW_HASKELL__ < 701
 $(deriveRepresentable0 ''Bush)
 #endif
 
+#if __GLASGOW_HASKELL__ >= 705
+deriving instance Generic1 Bush
+#else
 
 type Rep1Bush = U1 :+: Par1 :*: Bush :.: Rec1 Bush
 instance Generic1 Bush where
@@ -427,6 +458,7 @@   to1 (L1 U1) = BushNil
   to1 (R1 (Par1 a :*: Comp1 b)) = BushCons a (gmap unRec1 b)
 
+#endif
 
 #if __GLASGOW_HASKELL__ < 701
 
generic-deriving.cabal view
@@ -1,5 +1,5 @@ name:                   generic-deriving
-version:                1.2.1
+version:                1.2.2
 synopsis:               Generic programming library for generalised deriving.
 description:
 
@@ -11,7 +11,7 @@      Haskell'10.
   .
   The current implementation integrates with the new GHC Generics. See
-  <http://www.haskell.org/haskellwiki/Generics> for more information.
+  <http://www.haskell.org/haskellwiki/GHC.Generics> for more information.
   Template Haskell code is provided for supporting GHC before version 7.2.
 
 category:               Generics
@@ -45,9 +45,9 @@ 
                         Generics.Deriving.TH
                         
-  build-depends:        base < 4.6, template-haskell >=2.4 && <2.8
+  build-depends:        base < 5, template-haskell >=2.4 && <2.9
   if impl(ghc > 7.0)
-    build-depends:      ghc-prim < 0.3
+    build-depends:      ghc-prim < 1
 
   extensions:           CPP
   ghc-options:          -Wall
src/Generics/Deriving/ConNames.hs view
@@ -1,49 +1,49 @@-{-# LANGUAGE TypeOperators         #-}-{-# LANGUAGE FlexibleInstances     #-}-{-# LANGUAGE ScopedTypeVariables   #-}-{-# LANGUAGE FlexibleContexts      #-}---------------------------------------------------------------------------------- |--- Module      :  Generics.Deriving.ConNames--- Copyright   :  (c) 2012 University of Oxford--- License     :  BSD3------ Maintainer  :  generics@haskell.org--- Stability   :  experimental--- Portability :  non-portable------ Summary: Return the name of all the constructors of a type.-----------------------------------------------------------------------------------module Generics.Deriving.ConNames (--    -- * Functionality for retrieving the names of all the possible contructors-    --   of a type-    ConNames(..), conNames--  ) where--import Generics.Deriving.Base---class ConNames f where -    gconNames :: f a -> [String]--instance (ConNames f, ConNames g) => ConNames (f :+: g) where-    gconNames (_ :: (f :+: g) a) = gconNames (undefined :: f a) ++-                                   gconNames (undefined :: g a)--instance (ConNames f) => ConNames (D1 c f) where-    gconNames (_ :: (D1 c f) a) = gconNames (undefined :: f a)-    -instance (Constructor c) => ConNames (C1 c f) where-    gconNames x = [conName x]---- We should never need any other instances.----- | Return the name of all the constructors of the type of the given term.-conNames :: (Generic a, ConNames (Rep a)) => a -> [String]-conNames x = gconNames (undefined `asTypeOf` (from x))+{-# LANGUAGE TypeOperators         #-}
+{-# LANGUAGE FlexibleInstances     #-}
+{-# LANGUAGE ScopedTypeVariables   #-}
+{-# LANGUAGE FlexibleContexts      #-}
+
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Generics.Deriving.ConNames
+-- Copyright   :  (c) 2012 University of Oxford
+-- License     :  BSD3
+--
+-- Maintainer  :  generics@haskell.org
+-- Stability   :  experimental
+-- Portability :  non-portable
+--
+-- Summary: Return the name of all the constructors of a type.
+--
+-----------------------------------------------------------------------------
+
+module Generics.Deriving.ConNames (
+
+    -- * Functionality for retrieving the names of all the possible contructors
+    --   of a type
+    ConNames(..), conNames
+
+  ) where
+
+import Generics.Deriving.Base
+
+
+class ConNames f where 
+    gconNames :: f a -> [String]
+
+instance (ConNames f, ConNames g) => ConNames (f :+: g) where
+    gconNames (_ :: (f :+: g) a) = gconNames (undefined :: f a) ++
+                                   gconNames (undefined :: g a)
+
+instance (ConNames f) => ConNames (D1 c f) where
+    gconNames (_ :: (D1 c f) a) = gconNames (undefined :: f a)
+    
+instance (Constructor c) => ConNames (C1 c f) where
+    gconNames x = [conName x]
+
+-- We should never need any other instances.
+
+
+-- | Return the name of all the constructors of the type of the given term.
+conNames :: (Generic a, ConNames (Rep a)) => a -> [String]
+conNames x = gconNames (undefined `asTypeOf` (from x))
src/Generics/Deriving/Instances.hs view
@@ -8,7 +8,9 @@ module Generics.Deriving.Instances (
 -- Only instances from Generics.Deriving.Base
 -- and the Generic1 instances
+#if __GLASGOW_HASKELL__ < 705
     Rep1Maybe, Rep1List
+#endif
 #if __GLASGOW_HASKELL__ < 701
   -- * Representations for base types
   , Rep0Char, Rep0Int, Rep0Float
@@ -16,7 +18,9 @@ #endif
   ) where
 
+#if __GLASGOW_HASKELL__ < 705
 import Generics.Deriving.Base
+#endif
 
 #if __GLASGOW_HASKELL__ < 701
 --------------------------------------------------------------------------------
@@ -76,7 +80,8 @@   to (M1 (R1 (M1 (K1 h :*: K1 t)))) = h : t
 #endif
 
--- GHC 7.2 still needs these instances
+#if __GLASGOW_HASKELL__ < 705
+-- GHC 7.2 and 7.4 still need these instances; 7.6 doesn't
 
 data Maybe_
 data Nothing_
@@ -125,3 +130,5 @@   to1 (M1 (R1 (M1 (Par1 h :*: Rec1 t)))) = h : t
 
 -- etc...
+
+#endif