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