2{-# LANGUAGE GeneralizedNewtypeDeriving #-}
3{-# LANGUAGE StandaloneDeriving #-}
4{-# LANGUAGE TypeFamilies #-}
5{-# LANGUAGE TypeOperators #-}
10-- This module defines the 'Patch' class.
16import Control.Applicative
17import Data.Functor.Const (Const (..))
18import Data.Functor.Identity
19import Data.Map.Monoidal (MonoidalMap)
21#if !MIN_VERSION_base(4,11,0)
22import Data.Semigroup (Semigroup (..))
26import Data.Semigroup.Additive as X
27import Data.Patch.Class as X
28import Data.Patch.DMap as X hiding (getDeletions)
29import Data.Patch.DMapWithMove as X
30 ( PatchDMapWithMove, const2PatchDMapWithMoveWith, mapPatchDMapWithMove
31 , patchDMapWithMoveToPatchMapWithMoveWith
32 , traversePatchDMapWithMoveWithKey, unPatchDMapWithMove
33 , unsafePatchDMapWithMove, weakenPatchDMapWithMoveWith
35import Data.Patch.IntMap as X hiding (getDeletions)
36import Data.Patch.Map as X
37import Data.Patch.MapWithMove as X
38 ( PatchMapWithMove, patchMapWithMoveNewElements
39 , patchMapWithMoveNewElementsMap, unPatchMapWithMove
40 , unsafePatchMapWithMove
43-- | A 'Group' is a 'Monoid' where every element has an inverse.
44class (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.
50newtype AdditivePatch p = AdditivePatch { unAdditivePatch :: p }
52instance Additive p => Patch (AdditivePatch p) where
53 type PatchTarget (AdditivePatch p) = p
54 apply (AdditivePatch p) q = Just $ p <> q
56instance (Ord k, Group q) => Group (MonoidalMap k q) where
57 negateG = fmap negateG
60instance Group () where
64-- | Product group. A Pair of groups gives rise to a group
65instance (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.
72instance 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.
77instance (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
82instance Group (Proxy x) where
86-- | Const lifts groups into a functor.
87deriving instance Group a => Group (Const a x)
89-- | Identity lifts groups pointwise (at only one point)
90deriving instance Group a => Group (Identity a)
92-- | Functions lift groups pointwise.
93instance Group b => Group (a -> b) where
94 negateG f = negateG . f
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list