packages feed

generic-deriving 0.3 → 0.3.1

raw patch · 2 files changed

+37/−3 lines, 2 filesdep ~basedep ~template-haskellPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: base, template-haskell

API changes (from Hackage documentation)

- Generics.Deriving.Enum: instance (Enum' f) => Enum' (M1 i c f)
- Generics.Deriving.Enum: instance (GEnum a) => GEnum (Maybe a)
- Generics.Deriving.Enum: instance (GEnum a) => GEnum [a]
- Generics.Deriving.Enum: instance (GEnum c) => Enum' (K1 i c)
- Generics.Deriving.Eq: instance (GEq a) => GEq (Maybe a)
- Generics.Deriving.Eq: instance (GEq a) => GEq [a]
- Generics.Deriving.Eq: instance (GEq c) => GEq' (K1 i c)
- Generics.Deriving.Eq: instance (GEq' a) => GEq' (M1 i c a)
- Generics.Deriving.Functor: instance (GFunctor f) => GFunctor' (Rec1 f)
- Generics.Deriving.Functor: instance (GFunctor' f) => GFunctor' (M1 i c f)
- Generics.Deriving.Show: instance [incoherent] (GShow a) => GShow (Maybe a)
- Generics.Deriving.Show: instance [incoherent] (GShow a) => GShow [a]
- Generics.Deriving.Show: instance [incoherent] (GShow c) => GShow' (K1 i c)
- Generics.Deriving.Show: instance [incoherent] (GShow' a) => GShow' (M1 D d a)
- Generics.Deriving.Typeable: instance (Datatype d) => Typeable0' (M1 D d a)
- Generics.Deriving.Uniplate: instance [incoherent] (Uniplate a) => Uniplate (Maybe a)
- Generics.Deriving.Uniplate: instance [incoherent] (Uniplate' f b) => Uniplate' (M1 i c f) b
+ Generics.Deriving.Enum: instance Enum' f => Enum' (M1 i c f)
+ Generics.Deriving.Enum: instance GEnum a => GEnum (Maybe a)
+ Generics.Deriving.Enum: instance GEnum a => GEnum [a]
+ Generics.Deriving.Enum: instance GEnum c => Enum' (K1 i c)
+ Generics.Deriving.Eq: instance GEq a => GEq (Maybe a)
+ Generics.Deriving.Eq: instance GEq a => GEq [a]
+ Generics.Deriving.Eq: instance GEq c => GEq' (K1 i c)
+ Generics.Deriving.Eq: instance GEq' a => GEq' (M1 i c a)
+ Generics.Deriving.Functor: instance GFunctor f => GFunctor' (Rec1 f)
+ Generics.Deriving.Functor: instance GFunctor' f => GFunctor' (M1 i c f)
+ Generics.Deriving.Show: instance [incoherent] GShow a => GShow (Maybe a)
+ Generics.Deriving.Show: instance [incoherent] GShow a => GShow [a]
+ Generics.Deriving.Show: instance [incoherent] GShow c => GShow' (K1 i c)
+ Generics.Deriving.Show: instance [incoherent] GShow' a => GShow' (M1 D d a)
+ Generics.Deriving.Typeable: instance Datatype d => Typeable0' (M1 D d a)
+ Generics.Deriving.Uniplate: instance [incoherent] Uniplate a => Uniplate (Maybe a)
+ Generics.Deriving.Uniplate: instance [incoherent] Uniplate' f b => Uniplate' (M1 i c f) b
- Generics.Deriving.Base: conFixity :: (Constructor c) => t c (f :: * -> *) a -> Fixity
+ Generics.Deriving.Base: conFixity :: Constructor c => t c (f :: * -> *) a -> Fixity
- Generics.Deriving.Base: conIsRecord :: (Constructor c) => t c (f :: * -> *) a -> Bool
+ Generics.Deriving.Base: conIsRecord :: Constructor c => t c (f :: * -> *) a -> Bool
- Generics.Deriving.Base: conIsTuple :: (Constructor c) => t c (f :: * -> *) a -> Arity
+ Generics.Deriving.Base: conIsTuple :: Constructor c => t c (f :: * -> *) a -> Arity
- Generics.Deriving.Base: conName :: (Constructor c) => t c (f :: * -> *) a -> String
+ Generics.Deriving.Base: conName :: Constructor c => t c (f :: * -> *) a -> String
- Generics.Deriving.Base: datatypeName :: (Datatype d) => t d (f :: * -> *) a -> String
+ Generics.Deriving.Base: datatypeName :: Datatype d => t d (f :: * -> *) a -> String
- Generics.Deriving.Base: from0 :: (Representable0 a rep) => a -> rep x
+ Generics.Deriving.Base: from0 :: Representable0 a rep => a -> rep x
- Generics.Deriving.Base: from1 :: (Representable1 f rep) => f a -> rep a
+ Generics.Deriving.Base: from1 :: Representable1 f rep => f a -> rep a
- Generics.Deriving.Base: moduleName :: (Datatype d) => t d (f :: * -> *) a -> String
+ Generics.Deriving.Base: moduleName :: Datatype d => t d (f :: * -> *) a -> String
- Generics.Deriving.Base: selName :: (Selector s) => t s (f :: * -> *) a -> String
+ Generics.Deriving.Base: selName :: Selector s => t s (f :: * -> *) a -> String
- Generics.Deriving.Base: to0 :: (Representable0 a rep) => rep x -> a
+ Generics.Deriving.Base: to0 :: Representable0 a rep => rep x -> a
- Generics.Deriving.Base: to1 :: (Representable1 f rep) => rep a -> f a
+ Generics.Deriving.Base: to1 :: Representable1 f rep => rep a -> f a
- Generics.Deriving.Enum: class (Ord a) => GIx a
+ Generics.Deriving.Enum: class Ord a => GIx a
- Generics.Deriving.Enum: genum :: (GEnum a) => [a]
+ Generics.Deriving.Enum: genum :: GEnum a => [a]
- Generics.Deriving.Enum: inRange :: (GIx a) => (a, a) -> a -> Bool
+ Generics.Deriving.Enum: inRange :: GIx a => (a, a) -> a -> Bool
- Generics.Deriving.Enum: index :: (GIx a) => (a, a) -> a -> Int
+ Generics.Deriving.Enum: index :: GIx a => (a, a) -> a -> Int
- Generics.Deriving.Enum: range :: (GIx a) => (a, a) -> [a]
+ Generics.Deriving.Enum: range :: GIx a => (a, a) -> [a]
- Generics.Deriving.Eq: geq :: (GEq a) => a -> a -> Bool
+ Generics.Deriving.Eq: geq :: GEq a => a -> a -> Bool
- Generics.Deriving.Functor: gmap :: (GFunctor f) => (a -> b) -> f a -> f b
+ Generics.Deriving.Functor: gmap :: GFunctor f => (a -> b) -> f a -> f b
- Generics.Deriving.Show: gshow :: (GShow a) => a -> String
+ Generics.Deriving.Show: gshow :: GShow a => a -> String
- Generics.Deriving.Show: gshows :: (GShow a) => a -> ShowS
+ Generics.Deriving.Show: gshows :: GShow a => a -> ShowS
- Generics.Deriving.Show: gshowsPrec :: (GShow a) => Int -> a -> ShowS
+ Generics.Deriving.Show: gshowsPrec :: GShow a => Int -> a -> ShowS
- Generics.Deriving.Uniplate: children :: (Uniplate a) => a -> [a]
+ Generics.Deriving.Uniplate: children :: Uniplate a => a -> [a]

Files

examples/Examples.hs view
@@ -463,7 +463,39 @@     t :: Rep1Weird a -> (a -> b) -> Weird a -> Weird b
     t = gmapdefault
 
+--------------------------------------------------------------------------------
+-- Example: Nested datatype Bush (minimal)
+--------------------------------------------------------------------------------
 
+data Bush a = BushNil | BushCons a (Bush (Bush a))
+
+
+$(deriveAll ''Bush)
+
+type Rep1Bush = U1 :+: Par1 :*: Bush :.: Rec1 Bush
+instance Representable1 Bush Rep1Bush where
+  from1 BushNil = L1 U1
+  from1 (BushCons a b) = R1 (Par1 a :*: Comp1 (gmap Rec1 b))
+  to1 (L1 U1) = BushNil
+  to1 (R1 (Par1 a :*: Comp1 b)) = BushCons a (gmap unRec1 b)
+
+instance GFunctor Bush where
+  gmap = t undefined where
+    t :: Rep1Bush a -> (a -> b) -> Bush a -> Bush b
+    t = gmapdefault
+
+instance (GShow a) => GShow (Bush a) where
+  gshowsPrec = t undefined where
+    t :: (GShow a) => Rep0Bush_ a x -> Int -> Bush a -> ShowS
+    t = gshowsPrecdefault
+
+-- Example usage
+bush1 :: Bush Int
+bush1 = BushCons 0 (BushCons (BushCons 1 BushNil) BushNil)
+
+testsBush = [ gshow bush1
+            , gshow (gmap gshow bush1) ]
+
 --------------------------------------------------------------------------------
 -- Example: Two parameters, datatype constraint, nested on other parameter
 --------------------------------------------------------------------------------
@@ -531,3 +563,5 @@         mapM_ p testsEither
         putStrLn "\nTests for Nested:"
         mapM_ p testsNested
+        putStrLn "\nTests for Bush:"
+        mapM_ p testsBush
generic-deriving.cabal view
@@ -1,5 +1,5 @@ name:                   generic-deriving-version:                0.3+version:                0.3.1 synopsis:               Generic programming library for generalized deriving. description: @@ -19,7 +19,7 @@ stability:              experimental build-type:             Custom cabal-version:          >= 1.2.1-tested-with:            GHC == 6.10.4+tested-with:            GHC == 6.10.4, GHC == 6.12.1, GHC == 7.0.1 extra-source-files:     examples/Examples.hs  library@@ -37,6 +37,6 @@                         Generics.Deriving.Uniplate                         Generics.Deriving.TH                         -  build-depends:        base <= 4.2.0.0, template-haskell >=2.4 && <2.5+  build-depends:        base < 4.4, template-haskell >=2.4 && <2.6   extensions:           MultiParamTypeClasses, CPP   ghc-options:          -Wall