on e8029ed help sign in
patch/src/Reflex/Patch.hs
34 lines 1.5 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, patchDMapWithMoveToPatchMapWithMoveWith, mapPatchDMapWithMove, weakenPatchDMapWithMoveWith, traversePatchDMapWithMoveWithKey, unsafePatchDMapWithMove, unPatchDMapWithMove)
12import Reflex.Patch.Map as X
13import Reflex.Patch.MapWithMove as X (PatchMapWithMove, patchMapWithMoveNewElementsMap, patchMapWithMoveNewElements, unsafePatchMapWithMove, unPatchMapWithMove)
14import Reflex.Patch.IntMap as X hiding (getDeletions)
16import Data.Semigroup (Semigroup (..), (<>))
18---- Patches based on commutative groups
20-- | A 'Group' is a 'Monoid' where every element has an inverse.
21class (Semigroup q, Monoid q) => Group q where
22 negateG :: q -> q
23 (~~) :: q -> q -> q
24 r ~~ s = r <> negateG s
26-- | An 'Additive' 'Semigroup' is one where (<>) is commutative
27class Semigroup q => Additive q where
29-- | The elements of an 'Additive' 'Semigroup' can be considered as patches of their own type.
30newtype AdditivePatch p = AdditivePatch { unAdditivePatch :: p }
32instance Additive p => Patch (AdditivePatch p) where
33 type PatchTarget (AdditivePatch p) = p
34 apply (AdditivePatch p) q = Just $ p <> q