generic-deriving 0.3.1 → 0.4
raw patch · 8 files changed
+115/−99 lines, 8 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Generics.Deriving.Base: instance Constructor Cons__
- Generics.Deriving.Base: instance Constructor Just_
- Generics.Deriving.Base: instance Constructor Nil__
- Generics.Deriving.Base: instance Constructor Nothing_
- Generics.Deriving.Base: instance Datatype Maybe_
- Generics.Deriving.Base: instance Datatype [a]
- Generics.Deriving.Base: instance Representable0 (Maybe a) (Rep0Maybe a)
- Generics.Deriving.Base: instance Representable0 Char Rep0Char
- Generics.Deriving.Base: instance Representable0 Float Rep0Float
- Generics.Deriving.Base: instance Representable0 Int Rep0Int
- Generics.Deriving.Base: instance Representable0 [a] (Rep0List a)
- Generics.Deriving.Base: instance Representable1 Maybe Rep1Maybe
- Generics.Deriving.Base: instance Representable1 [] Rep1List
- Generics.Deriving.Base: type Rep0Char = Rec0 Char
- Generics.Deriving.Base: type Rep0Float = Rec0 Float
- Generics.Deriving.Base: type Rep0Int = Rec0 Int
- Generics.Deriving.Base: type Rep0List a = D1 List__ ((C1 Nil__ U1) :+: (C1 Cons__ (Par0 a :*: Rec0 [a])))
- Generics.Deriving.Base: type Rep0Maybe a = D1 Maybe_ (C1 Nothing_ U1 :+: C1 Just_ (Par0 a))
- Generics.Deriving.Base: type Rep1List = D1 List__ ((C1 Nil__ U1) :+: (C1 Cons__ (Par1 :*: Rec1 [])))
- Generics.Deriving.Base: type Rep1Maybe = D1 Maybe_ (C1 Nothing_ U1 :+: C1 Just_ Par1)
+ 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 Maybe_
+ Generics.Deriving.Instances: instance Datatype [a]
+ Generics.Deriving.Instances: instance Representable0 (Maybe a) (Rep0Maybe a)
+ Generics.Deriving.Instances: instance Representable0 Char Rep0Char
+ Generics.Deriving.Instances: instance Representable0 Float Rep0Float
+ Generics.Deriving.Instances: instance Representable0 Int Rep0Int
+ Generics.Deriving.Instances: instance Representable0 [a] (Rep0List a)
+ Generics.Deriving.Instances: instance Representable1 Maybe Rep1Maybe
+ Generics.Deriving.Instances: instance Representable1 [] Rep1List
+ Generics.Deriving.Instances: type Rep0Char = Rec0 Char
+ Generics.Deriving.Instances: type Rep0Float = Rec0 Float
+ Generics.Deriving.Instances: type Rep0Int = Rec0 Int
+ Generics.Deriving.Instances: type Rep0List a = D1 List__ ((C1 Nil__ U1) :+: (C1 Cons__ (Par0 a :*: Rec0 [a])))
+ Generics.Deriving.Instances: type Rep0Maybe a = D1 Maybe_ (C1 Nothing_ U1 :+: C1 Just_ (Par0 a))
+ 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)
Files
- generic-deriving.cabal +2/−1
- src/Generics/Deriving/Base.hs +0/−98
- src/Generics/Deriving/Enum.hs +1/−0
- src/Generics/Deriving/Eq.hs +1/−0
- src/Generics/Deriving/Functor.hs +1/−0
- src/Generics/Deriving/Instances.hs +108/−0
- src/Generics/Deriving/Show.hs +1/−0
- src/Generics/Deriving/Uniplate.hs +1/−0
generic-deriving.cabal view
@@ -1,5 +1,5 @@ name: generic-deriving-version: 0.3.1+version: 0.4 synopsis: Generic programming library for generalized deriving. description: @@ -26,6 +26,7 @@ hs-source-dirs: src exposed-modules: Generics.Deriving Generics.Deriving.Base+ Generics.Deriving.Instances -- Generics.Deriving.Data Generics.Deriving.Enum
src/Generics/Deriving/Base.hs view
@@ -26,10 +26,6 @@ #else module UHC.Generics, #endif - -- * Representations for base types - Rep0Char, Rep0Int, Rep0Float - , Rep0Maybe, Rep1Maybe - , Rep0List, Rep1List ) where @@ -222,97 +218,3 @@ to1 :: rep a -> f a #endif --------------------------------------------------------------------------------- --- Representation for base types --------------------------------------------------------------------------------- - --- Representation types -{- -type Rep1Par1 = Par1 -instance Representable1 Par1 Rep1Par1 where - from1 = id - to1 = id - -type Rep1Rec1 f = Rec1 f -instance Representable1 (Rec1 f) (Rep1Rec1 f) where - from1 = id - to1 = id --} --- Kind * - -type Rep0Char = Rec0 Char -instance Representable0 Char Rep0Char where - from0 = K1 - to0 = unK1 - -type Rep0Int = Rec0 Int -instance Representable0 Int Rep0Int where - from0 = K1 - to0 = unK1 - -type Rep0Float = Rec0 Float -instance Representable0 Float Rep0Float where - from0 = K1 - to0 = unK1 - --- etc... - --- Kind * -> * - -data Maybe_ -data Nothing_ -data Just_ - -instance Datatype Maybe_ where - datatypeName _ = "Maybe" - moduleName _ = "Representation" - -instance Constructor Nothing_ where - conName _ = "Nothing" - -instance Constructor Just_ where - conName _ = "Just" - -type Rep0Maybe a = D1 Maybe_ (C1 Nothing_ U1 :+: C1 Just_ (Par0 a)) -instance Representable0 (Maybe a) (Rep0Maybe a) where - from0 Nothing = M1 (L1 (M1 U1)) - from0 (Just x) = M1 (R1 (M1 (K1 x))) - to0 (M1 (L1 (M1 U1))) = Nothing - to0 (M1 (R1 (M1 (K1 x)))) = Just x - -type Rep1Maybe = D1 Maybe_ (C1 Nothing_ U1 :+: C1 Just_ Par1) -instance Representable1 Maybe Rep1Maybe where - from1 Nothing = M1 (L1 (M1 U1)) - from1 (Just x) = M1 (R1 (M1 (Par1 x))) - to1 (M1 (L1 (M1 U1))) = Nothing - to1 (M1 (R1 (M1 (Par1 x)))) = Just x - - -data List__ -data Nil__ -data Cons__ - -instance Datatype [a] where - datatypeName _ = "[]" - moduleName _ = "Data.List" - -instance Constructor Nil__ where conName _ = "[]" -instance Constructor Cons__ where - conName _ = ":" - conFixity _ = Infix RightAssociative 5 - -type Rep0List a = D1 List__ ((C1 Nil__ U1) :+: (C1 Cons__ (Par0 a :*: Rec0 [a]))) -instance Representable0 [a] (Rep0List a) where - from0 [] = M1 (L1 (M1 U1)) - from0 (h:t) = M1 (R1 (M1 (K1 h :*: K1 t))) - to0 (M1 (L1 (M1 U1))) = [] - to0 (M1 (R1 (M1 (K1 h :*: K1 t)))) = h : t - -type Rep1List = D1 List__ ((C1 Nil__ U1) :+: (C1 Cons__ (Par1 :*: Rec1 []))) -instance Representable1 [] Rep1List where - from1 [] = M1 (L1 (M1 U1)) - from1 (h:t) = M1 (R1 (M1 (Par1 h :*: Rec1 t))) - to1 (M1 (L1 (M1 U1))) = [] - to1 (M1 (R1 (M1 (Par1 h :*: Rec1 t)))) = h : t - --- etc...
src/Generics/Deriving/Enum.hs view
@@ -22,6 +22,7 @@ import Generics.Deriving.Base +import Generics.Deriving.Instances import Generics.Deriving.Eq
src/Generics/Deriving/Eq.hs view
@@ -15,6 +15,7 @@ import Generics.Deriving.Base +import Generics.Deriving.Instances -------------------------------------------------------------------------------- -- Generic show
src/Generics/Deriving/Functor.hs view
@@ -12,6 +12,7 @@ ) where import Generics.Deriving.Base +import Generics.Deriving.Instances -------------------------------------------------------------------------------- -- Generic fmap
+ src/Generics/Deriving/Instances.hs view
@@ -0,0 +1,108 @@+{-# LANGUAGE EmptyDataDecls #-} +{-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE TypeSynonymInstances #-} +{-# LANGUAGE TypeOperators #-} + +module Generics.Deriving.Instances ( + -- * Representations for base types + Rep0Char, Rep0Int, Rep0Float + , Rep0Maybe, Rep1Maybe + , Rep0List, Rep1List + ) where + +import Generics.Deriving.Base + +-------------------------------------------------------------------------------- +-- Representation for base types +-------------------------------------------------------------------------------- + +-- Representation types +{- +type Rep1Par1 = Par1 +instance Representable1 Par1 Rep1Par1 where + from1 = id + to1 = id + +type Rep1Rec1 f = Rec1 f +instance Representable1 (Rec1 f) (Rep1Rec1 f) where + from1 = id + to1 = id +-} +-- Kind * + +type Rep0Char = Rec0 Char +instance Representable0 Char Rep0Char where + from0 = K1 + to0 = unK1 + +type Rep0Int = Rec0 Int +instance Representable0 Int Rep0Int where + from0 = K1 + to0 = unK1 + +type Rep0Float = Rec0 Float +instance Representable0 Float Rep0Float where + from0 = K1 + to0 = unK1 + +-- etc... + +-- Kind * -> * + +data Maybe_ +data Nothing_ +data Just_ + +instance Datatype Maybe_ where + datatypeName _ = "Maybe" + moduleName _ = "Representation" + +instance Constructor Nothing_ where + conName _ = "Nothing" + +instance Constructor Just_ where + conName _ = "Just" + +type Rep0Maybe a = D1 Maybe_ (C1 Nothing_ U1 :+: C1 Just_ (Par0 a)) +instance Representable0 (Maybe a) (Rep0Maybe a) where + from0 Nothing = M1 (L1 (M1 U1)) + from0 (Just x) = M1 (R1 (M1 (K1 x))) + to0 (M1 (L1 (M1 U1))) = Nothing + to0 (M1 (R1 (M1 (K1 x)))) = Just x + +type Rep1Maybe = D1 Maybe_ (C1 Nothing_ U1 :+: C1 Just_ Par1) +instance Representable1 Maybe Rep1Maybe where + from1 Nothing = M1 (L1 (M1 U1)) + from1 (Just x) = M1 (R1 (M1 (Par1 x))) + to1 (M1 (L1 (M1 U1))) = Nothing + to1 (M1 (R1 (M1 (Par1 x)))) = Just x + + +data List__ +data Nil__ +data Cons__ + +instance Datatype [a] where + datatypeName _ = "[]" + moduleName _ = "Data.List" + +instance Constructor Nil__ where conName _ = "[]" +instance Constructor Cons__ where + conName _ = ":" + conFixity _ = Infix RightAssociative 5 + +type Rep0List a = D1 List__ ((C1 Nil__ U1) :+: (C1 Cons__ (Par0 a :*: Rec0 [a]))) +instance Representable0 [a] (Rep0List a) where + from0 [] = M1 (L1 (M1 U1)) + from0 (h:t) = M1 (R1 (M1 (K1 h :*: K1 t))) + to0 (M1 (L1 (M1 U1))) = [] + to0 (M1 (R1 (M1 (K1 h :*: K1 t)))) = h : t + +type Rep1List = D1 List__ ((C1 Nil__ U1) :+: (C1 Cons__ (Par1 :*: Rec1 []))) +instance Representable1 [] Rep1List where + from1 [] = M1 (L1 (M1 U1)) + from1 (h:t) = M1 (R1 (M1 (Par1 h :*: Rec1 t))) + to1 (M1 (L1 (M1 U1))) = [] + to1 (M1 (R1 (M1 (Par1 h :*: Rec1 t)))) = h : t + +-- etc...
src/Generics/Deriving/Show.hs view
@@ -16,6 +16,7 @@ import Generics.Deriving.Base +import Generics.Deriving.Instances -------------------------------------------------------------------------------- -- Generic show
src/Generics/Deriving/Uniplate.hs view
@@ -15,6 +15,7 @@ import Generics.Deriving.Base +import Generics.Deriving.Instances -------------------------------------------------------------------------------- -- Generic Uniplate