@@ -11,14 +11,11 @@ module Data.Patch
11 , module X
11 , module X
14−import Data.Functor.Const (Const (..))
15−import Data.Functor.Identity
17#if !MIN_VERSION_base(4,11,0)
14#if !MIN_VERSION_base(4,11,0)
18import Data.Semigroup (Semigroup (..))
15import Data.Semigroup (Semigroup (..))
18+import Data.Semigroup.Additive as X
22import Data.Patch.Class as X
19import Data.Patch.Class as X
23import Data.Patch.DMap as X hiding (getDeletions)
20import Data.Patch.DMap as X hiding (getDeletions)
24import Data.Patch.DMapWithMove as X
21import Data.Patch.DMapWithMove as X
@@ -35,37 +32,9 @@ import Data.Patch.MapWithMove as X
35 , unsafePatchMapWithMove
32 , unsafePatchMapWithMove
38−-- | An 'Additive' 'Semigroup' is one where (<>) is commutative
39−class Semigroup q => Additive q where
41-- | The elements of an 'Additive' 'Semigroup' can be considered as patches of their own type.
35-- | The elements of an 'Additive' 'Semigroup' can be considered as patches of their own type.
42newtype AdditivePatch p = AdditivePatch { unAdditivePatch :: p }
36newtype AdditivePatch p = AdditivePatch { unAdditivePatch :: p }
44instance Additive p => Patch (AdditivePatch p) where
38instance Additive p => Patch (AdditivePatch p) where
45 type PatchTarget (AdditivePatch p) = p
39 type PatchTarget (AdditivePatch p) = p
46 apply (AdditivePatch p) q = Just $ p <> q
40 apply (AdditivePatch p) q = Just $ p <> q
51−-- | Product group. A Pair of groups gives rise to a group
52−instance (Additive a, Additive b) => Additive (a, b)
54−-- See https://gitlab.haskell.org/ghc/ghc/issues/11135#note_111802 for the reason Compose is not also provided.
55−-- Base does not define Monoid (Compose f g a) so this is the best we can
56−-- really do for functor composition.
57−instance Additive (f (g a)) => Additive ((f :.: g) a)
59−-- | Product of groups, Functor style.
60−instance (Additive (f a), Additive (g a)) => Additive ((f :*: g) a)
62−-- | Trivial group, Functor style
63−instance Additive (Proxy x)
65−-- | Const lifts groups into a functor.
66−instance Additive a => Additive (Const a x)
67−-- | Ideitnty lifts groups pointwise (at only one point)
68−instance Additive a => Additive (Identity a)
70−-- | Functions lift groups pointwise.
71−instance Additive b => Additive (a -> b)