@@ -1,8 +1,6 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE CPP #-}
2−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
3−{-# LANGUAGE StandaloneDeriving #-}
4−{-# LANGUAGE TypeFamilies #-}
5{-# LANGUAGE TypeOperators #-}
2{-# LANGUAGE TypeOperators #-}
3+{-# LANGUAGE TypeFamilies #-}
8-- Data.Patch
6-- Data.Patch
@@ -13,15 +11,9 @@ module Data.Patch
13 , module X
11 , module X
16−import Control.Applicative
17−import Data.Functor.Const (Const (..))
18−import Data.Functor.Identity
19−import Data.Map.Monoidal (MonoidalMap)
21#if !MIN_VERSION_base(4,11,0)
14#if !MIN_VERSION_base(4,11,0)
22import Data.Semigroup (Semigroup (..))
15import Data.Semigroup (Semigroup (..))
26import Data.Semigroup.Additive as X
18import Data.Semigroup.Additive as X
27import Data.Patch.Class as X
19import Data.Patch.Class as X
@@ -40,55 +32,9 @@ import Data.Patch.MapWithMove as X
40 , unsafePatchMapWithMove
32 , unsafePatchMapWithMove
43−-- | A 'Group' is a 'Monoid' where every element has an inverse.
44−class (Semigroup q, Monoid q) => Group q where
47− r ~~ s = r <> negateG s
49-- | 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.
50newtype AdditivePatch p = AdditivePatch { unAdditivePatch :: p }
36newtype AdditivePatch p = AdditivePatch { unAdditivePatch :: p }
52instance Additive p => Patch (AdditivePatch p) where
38instance Additive p => Patch (AdditivePatch p) where
53 type PatchTarget (AdditivePatch p) = p
39 type PatchTarget (AdditivePatch p) = p
54 apply (AdditivePatch p) q = Just $ p <> q
40 apply (AdditivePatch p) q = Just $ p <> q
56−instance (Ord k, Group q) => Group (MonoidalMap k q) where
57− negateG = fmap negateG
60−instance Group () where
64−-- | Product group. A Pair of groups gives rise to a group
65−instance (Group a, Group b) => Group (a, b) where
66− negateG (a, b) = (negateG a, negateG b)
67− (a, b) ~~ (c, d) = (a ~~ c, b ~~ d)
69−-- See https://gitlab.haskell.org/ghc/ghc/issues/11135#note_111802 for the reason Compose is not also provided.
70−-- Base does not define Monoid (Compose f g a) so this is the best we can
71−-- really do for functor composition.
72−instance Group (f (g a)) => Group ((f :.: g) a) where
73− negateG (Comp1 xs) = Comp1 (negateG xs)
74− Comp1 xs ~~ Comp1 ys = Comp1 (xs ~~ ys)
76−-- | Product of groups, Functor style.
77−instance (Group (f a), Group (g a)) => Group ((f :*: g) a) where
78− negateG (a :*: b) = negateG a :*: negateG b
79− (a :*: b) ~~ (c :*: d) = (a ~~ c) :*: (b ~~ d)
81−-- | Trivial group, Functor style
82−instance Group (Proxy x) where
86−-- | Const lifts groups into a functor.
87−deriving instance Group a => Group (Const a x)
88−-- | Identity lifts groups pointwise (at only one point)
89−deriving instance Group a => Group (Identity a)
91−-- | Functions lift groups pointwise.
92−instance Group b => Group (a -> b) where
93− negateG f = negateG . f