@@ -23,6 +23,7 @@ import Data.Semigroup (Semigroup (..))
24import GHC.Generics
24import GHC.Generics
26+import Data.Semigroup.Additive as X
26import Data.Patch.Class as X
27import Data.Patch.Class as X
27import Data.Patch.DMap as X hiding (getDeletions)
28import Data.Patch.DMap as X hiding (getDeletions)
28import Data.Patch.DMapWithMove as X
29import Data.Patch.DMapWithMove as X
@@ -45,9 +46,6 @@ class (Semigroup q, Monoid q) => Group q where
45 (~~) :: q -> q -> q
46 (~~) :: q -> q -> q
46 r ~~ s = r <> negateG s
47 r ~~ s = r <> negateG s
48−-- | An 'Additive' 'Semigroup' is one where (<>) is commutative
49−class Semigroup q => Additive q where
51-- | The elements of an 'Additive' 'Semigroup' can be considered as patches of their own type.
49-- | The elements of an 'Additive' 'Semigroup' can be considered as patches of their own type.
52newtype AdditivePatch p = AdditivePatch { unAdditivePatch :: p }
50newtype AdditivePatch p = AdditivePatch { unAdditivePatch :: p }
@@ -58,19 +56,15 @@ instance Additive p => Patch (AdditivePatch p) where
58instance (Ord k, Group q) => Group (MonoidalMap k q) where
56instance (Ord k, Group q) => Group (MonoidalMap k q) where
59 negateG = fmap negateG
57 negateG = fmap negateG
61−instance (Ord k, Additive q) => Additive (MonoidalMap k q)
63-- | Trivial group.
59-- | Trivial group.
64instance Group () where
60instance Group () where
65 negateG _ = ()
61 negateG _ = ()
66 _ ~~ _ = ()
62 _ ~~ _ = ()
69-- | Product group. A Pair of groups gives rise to a group
64-- | Product group. A Pair of groups gives rise to a group
70instance (Group a, Group b) => Group (a, b) where
65instance (Group a, Group b) => Group (a, b) where
71 negateG (a, b) = (negateG a, negateG b)
66 negateG (a, b) = (negateG a, negateG b)
72 (a, b) ~~ (c, d) = (a ~~ c, b ~~ d)
67 (a, b) ~~ (c, d) = (a ~~ c, b ~~ d)
73−instance (Additive a, Additive b) => Additive (a, b)
75-- See https://gitlab.haskell.org/ghc/ghc/issues/11135#note_111802 for the reason Compose is not also provided.
69-- See https://gitlab.haskell.org/ghc/ghc/issues/11135#note_111802 for the reason Compose is not also provided.
76-- Base does not define Monoid (Compose f g a) so this is the best we can
70-- Base does not define Monoid (Compose f g a) so this is the best we can
@@ -78,29 +72,23 @@ instance (Additive a, Additive b) => Additive (a, b)
78instance Group (f (g a)) => Group ((f :.: g) a) where
72instance Group (f (g a)) => Group ((f :.: g) a) where
79 negateG (Comp1 xs) = Comp1 (negateG xs)
73 negateG (Comp1 xs) = Comp1 (negateG xs)
80 Comp1 xs ~~ Comp1 ys = Comp1 (xs ~~ ys)
74 Comp1 xs ~~ Comp1 ys = Comp1 (xs ~~ ys)
81−instance Additive (f (g a)) => Additive ((f :.: g) a)
83-- | Product of groups, Functor style.
76-- | Product of groups, Functor style.
84instance (Group (f a), Group (g a)) => Group ((f :*: g) a) where
77instance (Group (f a), Group (g a)) => Group ((f :*: g) a) where
85 negateG (a :*: b) = negateG a :*: negateG b
78 negateG (a :*: b) = negateG a :*: negateG b
86 (a :*: b) ~~ (c :*: d) = (a ~~ c) :*: (b ~~ d)
79 (a :*: b) ~~ (c :*: d) = (a ~~ c) :*: (b ~~ d)
87−instance (Additive (f a), Additive (g a)) => Additive ((f :*: g) a)
89-- | Trivial group, Functor style
81-- | Trivial group, Functor style
90instance Group (Proxy x) where
82instance Group (Proxy x) where
91 negateG _ = Proxy
83 negateG _ = Proxy
92 _ ~~ _ = Proxy
84 _ ~~ _ = Proxy
93−instance Additive (Proxy x)
95-- | Const lifts groups into a functor.
86-- | Const lifts groups into a functor.
96deriving instance Group a => Group (Const a x)
87deriving instance Group a => Group (Const a x)
97−instance Additive a => Additive (Const a x)
98-- | Ideitnty lifts groups pointwise (at only one point)
88-- | Ideitnty lifts groups pointwise (at only one point)
99deriving instance Group a => Group (Identity a)
89deriving instance Group a => Group (Identity a)
100−instance Additive a => Additive (Identity a)
102-- | Functions lift groups pointwise.
91-- | Functions lift groups pointwise.
103instance Group b => Group (a -> b) where
92instance Group b => Group (a -> b) where
104 negateG f = negateG . f
93 negateG f = negateG . f
105 (~~) = liftA2 (~~)
94 (~~) = liftA2 (~~)
106−instance Additive b => Additive (a -> b)