on patch-dmap-reset help sign in
patch/src/Data/Patch.hs
45 lines 1.8 kB history raw
1{-# LANGUAGE TypeFamilies #-}
2-- |
3-- Module:
4-- Data.Patch
5-- Description:
6-- This module defines the 'Patch' class.
7module Data.Patch
8 ( module Data.Patch
9 , module X
10 ) where
12import Data.Patch.Class as X
13import Data.Patch.DMap as X hiding (getDeletions)
14import Data.Patch.DMapWithMove as X (PatchDMapWithMove, const2PatchDMapWithMoveWith, mapPatchDMapWithMove,
15 patchDMapWithMoveToPatchMapWithMoveWith,
16 traversePatchDMapWithMoveWithKey, unPatchDMapWithMove,
17 unsafePatchDMapWithMove, weakenPatchDMapWithMoveWith)
18import Data.Patch.IntMap as X hiding (getDeletions)
19import Data.Patch.Map as X
20import Data.Patch.MapWithMove as X (PatchMapWithMove, patchMapWithMoveNewElements,
21 patchMapWithMoveNewElementsMap, unPatchMapWithMove,
22 unsafePatchMapWithMove)
23import Data.Map.Monoidal (MonoidalMap)
24import Data.Semigroup (Semigroup (..), (<>))
26-- | A 'Group' is a 'Monoid' where every element has an inverse.
27class (Semigroup q, Monoid q) => Group q where
28 negateG :: q -> q
29 (~~) :: q -> q -> q
30 r ~~ s = r <> negateG s
32-- | An 'Additive' 'Semigroup' is one where (<>) is commutative
33class Semigroup q => Additive q where
35-- | The elements of an 'Additive' 'Semigroup' can be considered as patches of their own type.
36newtype AdditivePatch p = AdditivePatch { unAdditivePatch :: p }
38instance Additive p => Patch (AdditivePatch p) where
39 type PatchTarget (AdditivePatch p) = p
40 apply (AdditivePatch p) q = Just $ p <> q
42instance (Ord k, Group q) => Group (MonoidalMap k q) where
43 negateG = fmap negateG
45instance (Ord k, Additive q) => Additive (MonoidalMap k q)