You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
--|Module containing @'PatchDMapWithMove' k v@ and associated functions, which represents a 'Patch' to a @'DMap' k v@ which can insert, update, delete, and
--| Like 'PatchMapWithMove', but for 'DMap'. Each key carries a 'NodeInfo' which describes how it will be changed by the patch and connects move sources and
44
+
-- destinations.
45
+
--
46
+
-- Invariants:
47
+
--
48
+
-- * A key should not move to itself.
49
+
-- * A move should always be represented with both the destination key (as a 'From_Move') and the source key (as a @'ComposeMaybe' ('Just' destination)@)
--|Structure which represents what changes apply to a particular key. @_nodeInfo_from@ specifies what happens to this key, and in particular what other key
56
+
-- the current key is moving from, while @_nodeInfo_to@ specifies what key the current key is moving to if involved in a move.
45
57
dataNodeInfokva=NodeInfo
46
58
{_nodeInfo_from::!(Fromkva)
59
+
--^Change applying to the current key, be it an insert, move, or delete.
47
60
, _nodeInfo_to::!(Toka)
61
+
--^Where this key is moving to, if involved in a move. Should only be @ComposeMaybe (Just k)@ when there is a corresponding 'From_Move'.
48
62
}
49
63
deriving (Show)
50
64
@@ -56,36 +70,73 @@ instance {-# INCOHERENT #-} (GEq k, EqTag k v) => EqTag k (From k v) where
56
70
eqTagToEq k _ r = eqTagToEq k (Proxy::Proxyv) (geqToEq k r)
57
71
#endif
58
72
73
+
--|Structure describing a particular change to a key, be it inserting a new key (@From_Insert@), updating an existing key (@From_Insert@ again), deleting a
74
+
-- key (@From_Delete@), or moving a key (@From_Move@).
59
75
dataFrom (k::a->*) (v::a->*) ::a->*where
60
76
From_Insert::va->Fromkva
77
+
--^Insert a new or update an existing key with the given value @v a@
61
78
From_Delete::Fromkva
79
+
--^Delete the existing key
62
80
From_Move::!(ka) ->Fromkva
81
+
--^Move the value from the given key @k a@ to this key. The source key should also have an entry in the patch giving the current key as @_nodeInfo_to@,
82
+
-- usually but not necessarily with @From_Delete@.
63
83
deriving (Show, Read, Eq, Ord)
64
84
85
+
--|Type alias for the "to" part of a 'NodeInfo'. @'ComposeMaybe' ('Just' k)@ means the key is moving to another key, @ComposeMaybe Nothing@ for any other
--|Wrap a 'DMap' representing patch changes into a 'PatchDMapWithMove' while checking invariants. If the invariants are satisfied, @Right p@ is returned
--|Traverse an effectful function @forall a. v a -> m (v ' a)@ over the given patch, transforming @'PatchDMapWithMove' k v@ into @m ('PatchDMapWithMove' k v')@.
traversePatchDMapWithMove f = traversePatchDMapWithMoveWithKey $const f
214
307
308
+
--|Map an effectful function @forall a. k a -> v a -> m (v ' a)@ over the given patch, transforming @'PatchDMapWithMove' k v@ into @m ('PatchDMapWithMove' k v')@.
nodeInfoMapFromM f ni =fmap (\result -> ni { _nodeInfo_from = result }) $ f $ _nodeInfo_from ni
228
324
325
+
--|Weaken a 'PatchDMapWithMove' to a 'PatchMapWithMove' by weakening the keys from @k a@ to @'Some' k@ and applying a given weakening function @v a -> v'@ to
--|"Weaken" a @'PatchDMapWithMove' (Const2 k a) v@ to a @'PatchMapWithMove' k v'@. Weaken is in scare quotes because the 'Const2' has already disabled any
339
+
-- dependency in the typing and all points are already @a@, hence the function to map each value to @v'@ is not higher rank.
const2PatchDMapWithMoveWith::forallkvfa. (v->fa) ->PatchMapWithMovekv->PatchDMapWithMove (Const2ka) f
351
+
--|"Strengthen" a @'PatchMapWithMove' k v@ into a @'PatchDMapWithMove ('Const2' k a)@; that is, turn a non-dependently-typed patch into a dependently typed
352
+
-- one but which always has a constant key type represented by 'Const2'. Apply the given function to each @v@ to produce a @v' a@.
353
+
-- Completemented by 'patchDMapWithMoveToPatchMapWithMoveWith'
0 commit comments