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.IntMap as X hiding (getDeletions)
35import Data.Patch.Map as X
36import Data.Patch.MapWithMove as X
37 ( PatchMapWithMove, patchMapWithMoveNewElements
38 , patchMapWithMoveNewElementsMap, unPatchMapWithMove
39 , unsafePatchMapWithMove
42-- | A 'Group' is a 'Monoid' where every element has an inverse.
43class (Semigroup q, Monoid q) => Group q where
46 r ~~ s = r <> negateG s
48-- | An 'Additive' 'Semigroup' is one where (<>) is commutative
49class Semigroup q => Additive q where
51-- | The elements of an 'Additive' 'Semigroup' can be considered as patches of their own type.
52newtype AdditivePatch p = AdditivePatch { unAdditivePatch :: p }
54instance Additive p => Patch (AdditivePatch p) where
55 type PatchTarget (AdditivePatch p) = p
56 apply (AdditivePatch p) q = Just $ p <> q
58instance (Ord k, Group q) => Group (MonoidalMap k q) where
59 negateG = fmap negateG
61instance (Ord k, Additive q) => Additive (MonoidalMap k q)
64instance Group () where
69-- | Product group. A Pair of groups gives rise to a group
70instance (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)
73instance (Additive a, Additive b) => Additive (a, b)
75-- See https://gitlab.haskell.org/ghc/ghc/issues/11135#note_111802 for the reason Compose is not also provided.
76-- Base does not define Monoid (Compose f g a) so this is the best we can
77-- really do for functor composition.
78instance Group (f (g a)) => Group ((f :.: g) a) where
79 negateG (Comp1 xs) = Comp1 (negateG xs)
80 Comp1 xs ~~ Comp1 ys = Comp1 (xs ~~ ys)
81instance Additive (f (g a)) => Additive ((f :.: g) a)
83-- | Product of groups, Functor style.
84instance (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)
87instance (Additive (f a), Additive (g a)) => Additive ((f :*: g) a)
89-- | Trivial group, Functor style
90instance Group (Proxy x) where
93instance Additive (Proxy x)
95-- | Const lifts groups into a functor.
96deriving instance Group a => Group (Const a x)
97instance Additive a => Additive (Const a x)
98-- | Identity lifts groups pointwise (at only one point)
99deriving instance Group a => Group (Identity a)
100instance Additive a => Additive (Identity a)
102-- | Functions lift groups pointwise.
103instance Group b => Group (a -> b) where
104 negateG f = negateG . f
106instance 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