11{-# LANGUAGE CPP #-}
2- {-# LANGUAGE GeneralizedNewtypeDeriving #-}
3- {-# LANGUAGE StandaloneDeriving #-}
4- {-# LANGUAGE TypeFamilies #-}
52{-# LANGUAGE TypeOperators #-}
3+ {-# LANGUAGE TypeFamilies #-}
64-- |
75-- Module:
86-- Data.Patch
@@ -13,10 +11,8 @@ module Data.Patch
1311 , module X
1412 ) where
1513
16- import Control.Applicative
1714import Data.Functor.Const (Const (.. ))
1815import Data.Functor.Identity
19- import Data.Map.Monoidal (MonoidalMap )
2016import Data.Proxy
2117#if !MIN_VERSION_base(4,11,0)
2218import Data.Semigroup (Semigroup (.. ))
@@ -39,12 +35,6 @@ import Data.Patch.MapWithMove as X
3935 , unsafePatchMapWithMove
4036 )
4137
42- -- | A 'Group' is a 'Monoid' where every element has an inverse.
43- class (Semigroup q , Monoid q ) => Group q where
44- negateG :: q -> q
45- (~~) :: q -> q -> q
46- r ~~ s = r <> negateG s
47-
4838-- | An 'Additive' 'Semigroup' is one where (<>) is commutative
4939class Semigroup q => Additive q where
5040
@@ -55,52 +45,27 @@ instance Additive p => Patch (AdditivePatch p) where
5545 type PatchTarget (AdditivePatch p ) = p
5646 apply (AdditivePatch p) q = Just $ p <> q
5747
58- instance (Ord k , Group q ) => Group (MonoidalMap k q ) where
59- negateG = fmap negateG
60-
61- instance (Ord k , Additive q ) => Additive (MonoidalMap k q )
62-
6348-- | Trivial group.
64- instance Group () where
65- negateG _ = ()
66- _ ~~ _ = ()
6749instance Additive ()
6850
6951-- | Product group. A Pair of groups gives rise to a group
70- instance (Group a , Group b ) => Group (a , b ) where
71- negateG (a, b) = (negateG a, negateG b)
72- (a, b) ~~ (c, d) = (a ~~ c, b ~~ d)
7352instance (Additive a , Additive b ) => Additive (a , b )
7453
7554-- See https://gitlab.haskell.org/ghc/ghc/issues/11135#note_111802 for the reason Compose is not also provided.
7655-- Base does not define Monoid (Compose f g a) so this is the best we can
7756-- really do for functor composition.
78- instance Group (f (g a )) => Group ((f :.: g ) a ) where
79- negateG (Comp1 xs) = Comp1 (negateG xs)
80- Comp1 xs ~~ Comp1 ys = Comp1 (xs ~~ ys)
8157instance Additive (f (g a )) => Additive ((f :.: g ) a )
8258
8359-- | Product of groups, Functor style.
84- instance (Group (f a ), Group (g a )) => Group ((f :*: g ) a ) where
85- negateG (a :*: b) = negateG a :*: negateG b
86- (a :*: b) ~~ (c :*: d) = (a ~~ c) :*: (b ~~ d)
8760instance (Additive (f a ), Additive (g a )) => Additive ((f :*: g ) a )
8861
8962-- | Trivial group, Functor style
90- instance Group (Proxy x ) where
91- negateG _ = Proxy
92- _ ~~ _ = Proxy
9363instance Additive (Proxy x )
9464
9565-- | Const lifts groups into a functor.
96- deriving instance Group a => Group (Const a x )
9766instance Additive a => Additive (Const a x )
9867-- | Ideitnty lifts groups pointwise (at only one point)
99- deriving instance Group a => Group (Identity a )
10068instance Additive a => Additive (Identity a )
10169
10270-- | Functions lift groups pointwise.
103- instance Group b => Group (a -> b ) where
104- negateG f = negateG . f
105- (~~) = liftA2 (~~)
10671instance Additive b => Additive (a -> b )
0 commit comments