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.Patch.Class as X
27import Data.Patch.DMap as X hiding (getDeletions)
28import Data.Patch.DMapWithMove as X
29 ( PatchDMapWithMove, const2PatchDMapWithMoveWith, mapPatchDMapWithMove
30 , patchDMapWithMoveToPatchMapWithMoveWith
31 , traversePatchDMapWithMoveWithKey, unPatchDMapWithMove
32 , unsafePatchDMapWithMove, weakenPatchDMapWithMoveWith
34import Data.Patch.DMapWithPatchingMove as X
35 ( PatchDMapWithPatchingMove, const2PatchDMapWithPatchingMoveWith, mapPatchDMapWithPatchingMove
36 , patchDMapWithPatchingMoveToPatchMapWithPatchingMoveWith
37 , traversePatchDMapWithPatchingMoveWithKey, unPatchDMapWithPatchingMove
38 , unsafePatchDMapWithPatchingMove, weakenPatchDMapWithPatchingMoveWith
40import Data.Patch.IntMap as X hiding (getDeletions)
41import Data.Patch.Map as X
42import Data.Patch.MapWithMove as X
43 ( PatchMapWithMove, patchMapWithMoveNewElements
44 , patchMapWithMoveNewElementsMap, unPatchMapWithMove
45 , unsafePatchMapWithMove
48-- | A 'Group' is a 'Monoid' where every element has an inverse.
49class (Semigroup q, Monoid q) => Group q where
52 r ~~ s = r <> negateG s
54-- | An 'Additive' 'Semigroup' is one where (<>) is commutative
55class Semigroup q => Additive q where
57-- | The elements of an 'Additive' 'Semigroup' can be considered as patches of their own type.
58newtype AdditivePatch p = AdditivePatch { unAdditivePatch :: p }
60instance Additive p => PatchHet (AdditivePatch p) where
61 type PatchSource (AdditivePatch p) = p
62 type PatchTarget (AdditivePatch p) = p
63instance Additive p => Patch (AdditivePatch p) where
64 apply (AdditivePatch p) q = Just $ p <> q
66instance (Ord k, Group q) => Group (MonoidalMap k q) where
67 negateG = fmap negateG
69instance (Ord k, Additive q) => Additive (MonoidalMap k q)
72instance Group () where
77-- | Product group. A Pair of groups gives rise to a group
78instance (Group a, Group b) => Group (a, b) where
79 negateG (a, b) = (negateG a, negateG b)
80 (a, b) ~~ (c, d) = (a ~~ c, b ~~ d)
81instance (Additive a, Additive b) => Additive (a, b)
83-- See https://gitlab.haskell.org/ghc/ghc/issues/11135#note_111802 for the reason Compose is not also provided.
84-- Base does not define Monoid (Compose f g a) so this is the best we can
85-- really do for functor composition.
86instance Group (f (g a)) => Group ((f :.: g) a) where
87 negateG (Comp1 xs) = Comp1 (negateG xs)
88 Comp1 xs ~~ Comp1 ys = Comp1 (xs ~~ ys)
89instance Additive (f (g a)) => Additive ((f :.: g) a)
91-- | Product of groups, Functor style.
92instance (Group (f a), Group (g a)) => Group ((f :*: g) a) where
93 negateG (a :*: b) = negateG a :*: negateG b
94 (a :*: b) ~~ (c :*: d) = (a ~~ c) :*: (b ~~ d)
95instance (Additive (f a), Additive (g a)) => Additive ((f :*: g) a)
97-- | Trivial group, Functor style
98instance Group (Proxy x) where
99 negateG ~Proxy = Proxy
100 ~Proxy ~~ ~Proxy = Proxy
101instance Additive (Proxy x)
103-- | Const lifts groups into a functor.
104deriving instance Group a => Group (Const a x)
105instance Additive a => Additive (Const a x)
106-- | Ideitnty lifts groups pointwise (at only one point)
107deriving instance Group a => Group (Identity a)
108instance Additive a => Additive (Identity a)
110-- | Functions lift groups pointwise.
111instance Group b => Group (a -> b) where
112 negateG f = negateG . f
114instance Additive b => Additive (a -> b)
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