on 28ca47b help sign in
patch/src/Reflex/Patch.hs
39 lines 1.7 kB history raw
1-- | This module defines the 'Patch' class, which is used by Reflex to manage
2-- changes to 'Reflex.Class.Incremental' values.
3{-# LANGUAGE TypeFamilies #-}
4module Reflex.Patch
5 ( module Reflex.Patch
6 , module X
7 ) where
9import Reflex.Patch.Class as X
10import Reflex.Patch.DMap as X hiding (getDeletions)
11import Reflex.Patch.DMapWithMove as X (PatchDMapWithMove, const2PatchDMapWithMoveWith, mapPatchDMapWithMove,
12 patchDMapWithMoveToPatchMapWithMoveWith,
13 traversePatchDMapWithMoveWithKey, unPatchDMapWithMove,
14 unsafePatchDMapWithMove, weakenPatchDMapWithMoveWith)
15import Reflex.Patch.IntMap as X hiding (getDeletions)
16import Reflex.Patch.Map as X
17import Reflex.Patch.MapWithMove as X (PatchMapWithMove, patchMapWithMoveNewElements,
18 patchMapWithMoveNewElementsMap, unPatchMapWithMove,
19 unsafePatchMapWithMove)
21import Data.Semigroup (Semigroup (..), (<>))
23---- Patches based on commutative groups
25-- | A 'Group' is a 'Monoid' where every element has an inverse.
26class (Semigroup q, Monoid q) => Group q where
27 negateG :: q -> q
28 (~~) :: q -> q -> q
29 r ~~ s = r <> negateG s
31-- | An 'Additive' 'Semigroup' is one where (<>) is commutative
32class Semigroup q => Additive q where
34-- | The elements of an 'Additive' 'Semigroup' can be considered as patches of their own type.
35newtype AdditivePatch p = AdditivePatch { unAdditivePatch :: p }
37instance Additive p => Patch (AdditivePatch p) where
38 type PatchTarget (AdditivePatch p) = p
39 apply (AdditivePatch p) q = Just $ p <> q