on 70f445a help sign in
patch/src/Reflex/Patch.hs
33 lines 1.4 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
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, patchMapWithMoveNewElements, unsafePatchMapWithMove, unPatchMapWithMove)
15import Data.Semigroup (Semigroup (..), (<>))
17---- Patches based on commutative groups
19-- | A 'Group' is a 'Monoid' where every element has an inverse.
20class (Semigroup q, Monoid q) => Group q where
21 negateG :: q -> q
22 (~~) :: q -> q -> q
23 r ~~ s = r <> negateG s
25-- | An 'Additive' 'Semigroup' is one where (<>) is commutative
26class Semigroup q => Additive q where
28-- | The elements of an 'Additive' 'Semigroup' can be considered as patches of their own type.
29newtype AdditivePatch p = AdditivePatch { unAdditivePatch :: p }
31instance Additive p => Patch (AdditivePatch p) where
32 type PatchTarget (AdditivePatch p) = p
33 apply (AdditivePatch p) q = Just $ p <> q