@@ -1,101 +1,223 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE CPP #-}
2+{-# LANGUAGE ConstraintKinds #-}
2{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE GADTs #-}
5{-# LANGUAGE GADTs #-}
6+{-# LANGUAGE InstanceSigs #-}
5{-# LANGUAGE LambdaCase #-}
7{-# LANGUAGE LambdaCase #-}
6{-# LANGUAGE MultiParamTypeClasses #-}
8{-# LANGUAGE MultiParamTypeClasses #-}
7{-# LANGUAGE PatternGuards #-}
9{-# LANGUAGE PatternGuards #-}
8{-# LANGUAGE PolyKinds #-}
10{-# LANGUAGE PolyKinds #-}
9{-# LANGUAGE Rank2Types #-}
11{-# LANGUAGE Rank2Types #-}
10{-# LANGUAGE ScopedTypeVariables #-}
12{-# LANGUAGE ScopedTypeVariables #-}
13+{-# LANGUAGE StandaloneDeriving #-}
14+{-# LANGUAGE TypeApplications #-}
11{-# LANGUAGE TypeFamilies #-}
15{-# LANGUAGE TypeFamilies #-}
12{-# LANGUAGE UndecidableInstances #-}
16{-# LANGUAGE UndecidableInstances #-}
17+{-# LANGUAGE UndecidableSuperClasses #-}
14-- |Module containing @'PatchDMapWithMove' k v@ and associated functions, which represents a 'Patch' to a @'DMap' k v@ which can insert, update, delete, and
19-- |Module containing @'PatchDMapWithMove' k v@ and associated functions, which represents a 'Patch' to a @'DMap' k v@ which can insert, update, delete, and
15-- move values between keys.
20-- move values between keys.
16module Data.Patch.DMapWithMove where
21module Data.Patch.DMapWithMove where
18−import Data.Patch.Class
23+import qualified Control.Category as Cat
19−import Data.Patch.MapWithMove (PatchMapWithMove (..))
24+--import qualified Control.Category.DecidablyEmpty as Cat
20−import qualified Data.Patch.MapWithMove as MapWithMove
22−import Data.Constraint.Extras
25+import Data.Constraint.Extras (Has')
23−import Data.Dependent.Map (DMap, DSum (..), GCompare (..))
26+import Data.Dependent.Map (DMap)
27+import Data.Dependent.Sum (DSum (..))
24import qualified Data.Dependent.Map as DMap
28import qualified Data.Dependent.Map as DMap
25−import Data.Functor.Constant
29+import Data.Functor.Constant (Constant (..))
26import Data.Functor.Misc
30import Data.Functor.Misc
31+ ( Const2 (..), Proxy3 (..)
27−import Data.Functor.Product
35+import Data.Functor.Product (Product (..))
28−import Data.GADT.Compare (GEq (..))
36+import Data.GADT.Compare (GEq (..), GCompare (..))
29−import Data.GADT.Show (GShow, gshow)
37+import Data.GADT.Show (GRead, GShow, gshow)
30import qualified Data.Map as Map
38import qualified Data.Map as Map
31import Data.Maybe
39import Data.Maybe
32import Data.Semigroup (Semigroup (..), (<>))
40import Data.Semigroup (Semigroup (..), (<>))
41+import Data.Semigroupoid as Cat
33import Data.Some (Some(Some))
42import Data.Some (Some(Some))
34−import Data.Proxy
43+import Data.Proxy (Proxy (..))
35−import Data.These
44+import Data.These (These (..))
46+import Data.Patch.Class
47+ ( Patch (..), PatchHet (..)
48+ , PatchHet2 (..), PatchSource1, PatchTarget1
51+import Data.Patch.MapWithMove (PatchMapWithMove (..))
52+import qualified Data.Patch.MapWithMove as MapWithMove
54+-- | Like 'PatchMapWithMove', but for 'DMap'. Each key carries a 'NodeInfo'
37−-- | 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
55+-- which describes how it will be changed by the patch and connects move sources
38−-- destinations.
56+-- and destinations.
40-- Invariants:
58-- Invariants:
42−-- * A key should not move to itself.
60+-- * A key should not move to itself.
43−-- * A move should always be represented with both the destination key (as a 'From_Move') and the source key (as a @'ComposeMaybe' ('Just' destination)@)
62+-- * A move should always be represented with both the destination key (as a
63+-- 'From_Move') and the source key (as a @'ComposeMaybe' ('Just'
44newtype PatchDMapWithMove k v = PatchDMapWithMove (DMap k (NodeInfo k v))
65newtype PatchDMapWithMove k v = PatchDMapWithMove (DMap k (NodeInfo k v))
67+--deriving instance ( GShow k
69+-- , Has' Show k (PatchTarget1 p)
70+-- ) => Show (PatchDMapWithMove k p)
71+--deriving instance ( GRead k
73+-- , Has' Read k (PatchTarget1 p)
74+-- ) => Read (PatchDMapWithMove k p)
75+--deriving instance ( GEq k
77+-- , Has' Eq k (PatchTarget1 p)
78+-- ) => Eq (PatchDMapWithMove k p)
79+--deriving instance ( GCompare k
81+-- , Has' Ord k (PatchTarget1 p)
82+-- ) => Ord (PatchDMapWithMove k p)
84+-- | Structure which represents what changes apply to a particular key.
46−-- |Structure which represents what changes apply to a particular key. @_nodeInfo_from@ specifies what happens to this key, and in particular what other key
85+-- @_nodeInfo_from@ specifies what happens to this key, and in particular what
47−-- the current key is moving from, while @_nodeInfo_to@ specifies what key the current key is moving to if involved in a move.
86+-- other key the current key is moving from, while @_nodeInfo_to@ specifies what
87+-- key the current key is moving to if involved in a move.
48−data NodeInfo k v a = NodeInfo
88+data NodeInfo k p a = NodeInfo
49− { _nodeInfo_from :: !(From k v a)
89+ { _nodeInfo_from :: !(From k p a)
50− -- ^Change applying to the current key, be it an insert, move, or delete.
90+ -- ^ Change applying to the current key, be it an insert, move, or delete.
51− , _nodeInfo_to :: !(To k a)
91+ , _nodeInfo_to :: !(To k p a)
52− -- ^Where this key is moving to, if involved in a move. Should only be @ComposeMaybe (Just k)@ when there is a corresponding 'From_Move'.
92+ -- ^ Where this key is moving to, if involved in a move. Should only be
93+ -- @ComposeMaybe (Just k)@ when there is a corresponding 'From_Move'.
54− deriving (Show)
96+--deriving instance ( Show (k a)
98+-- , Show (PatchTarget1 p a)
99+-- ) => Show (NodeInfo k p a)
100+--deriving instance ( Read (k a)
102+-- , Read (PatchTarget1 p a)
103+-- ) => Read (NodeInfo k p a)
104+--deriving instance ( Eq (k a)
106+-- , Eq (PatchTarget1 p a)
107+-- ) => Eq (NodeInfo k p a)
108+--deriving instance ( Ord (k a)
110+-- , Ord (PatchTarget1 p a)
111+-- ) => Ord (NodeInfo k p a)
56−-- |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
113+-- | Structure describing a particular change to a key, be it inserting a new
114+-- key (@From_Insert@), updating an existing key (@From_Insert@ again), deleting
57−-- key (@From_Delete@), or moving a key (@From_Move@).
115+-- a key (@From_Delete@), or moving a key (@From_Move@).
117+-- This type isn't used directly as the from field patch, but is instead wrapped
118+-- in an existential. However, it is nice to be able to reason about this in
119+-- isolation as it is itself a @Semigroupoid@ when the underlying patch is.
58−data From (k :: a -> *) (v :: a -> *) :: a -> * where
120+data From (k :: a -> *) (p :: a -> a -> *) :: a -> * where
59− -- |Insert a new or update an existing key with the given value @v a@
121+ -- | Insert a new or update an existing key with the given value @PatchTarget1
60− From_Insert :: v a -> From k v a
123+ From_Insert :: PatchTarget1 p to -> From k p to
61− -- |Delete the existing key
124+ -- | Delete the existing key
62− From_Delete :: From k v a
125+ From_Delete :: From k p to
126+ -- | Move the value from the given key @k a@ to this key. The source key
63− -- |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@,
127+ -- should also have an entry in the patch giving the current key as
64− -- usually but not necessarily with @From_Delete@.
128+ -- @_nodeInfo_to@, usually but not necessarily with @From_Delete@.
65− From_Move :: !(k a) -> From k v a
129+ From_Move :: !(DSum k (Flip p to)) -> From k p to
66− deriving (Show, Read, Eq, Ord)
130+
67−
131+deriving instance ( Show (k a), GShow k
68−-- |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
132+ , Has' Show k (Flip p a)
69−-- operation.
133+ , Show (PatchTarget1 p a)
70−type To = ComposeMaybe
134+ ) => Show (From k p a)
135+deriving instance ( Read (k a), GRead k
136+ , Has' Read k (Flip p a)
137+ , Read (PatchTarget1 p a)
138+ ) => Read (From k p a)
139+deriving instance ( GEq k
140+ , Has' Eq k (Flip p a)
141+ , Eq (PatchTarget1 p a)
142+ ) => Eq (From k p a)
143+deriving instance ( GCompare k
144+ , Has' Eq k (Flip p a) -- superclass bug
145+ , Has' Ord k (Flip p a)
146+ , Ord (PatchTarget1 p a)
147+ ) => Ord (From k p a)
149+newtype Flip p to from = Flip (p from to)
151+instance Cat.Category p => Cat.Category (Flip (p :: k -> k -> *)) where
153+ Flip y . Flip x = Flip $ x Cat.. y
155+-- | The "to" part of a 'NodeInfo'. Rather than be built out of @From@ like @From@
156+-- is, we store just the information necessary to compose a @To@ and @From@ like
157+-- @oLocal@ composes two @From@s.
158+data To (k :: a -> *) (p :: a -> a -> *) :: a -> * where
159+ -- | Delete or leave in place
160+ To_NonMove :: To k p from
161+ -- | Move the value from the given key @k a@ to this key. The target key
162+ -- should also have an entry in the patch giving the current key in
163+ -- @_nodeInfo_from@, usually but not necessarily with @To_Delete@.
164+ To_Move :: !(DSum k (p from)) -> To k p from
166+deriving instance ( Show (k a), GShow k
168+ , Show (PatchTarget1 p a)
169+ ) => Show (To k p a)
170+deriving instance ( Read (k a), GRead k
172+ , Read (PatchTarget1 p a)
173+ ) => Read (To k p a)
174+deriving instance ( GEq k
176+ , Eq (PatchTarget1 p a)
178+deriving instance ( GCompare k
179+ , Has' Eq k (p a) -- superclass bug
181+ , Ord (PatchTarget1 p a)
72-- |Test whether a 'PatchDMapWithMove' satisfies its invariants.
184-- |Test whether a 'PatchDMapWithMove' satisfies its invariants.
73−validPatchDMapWithMove :: forall k v. (GCompare k, GShow k) => DMap k (NodeInfo k v) -> Bool
185+validPatchDMapWithMove
187+ . (GCompare k, GShow k)
188+ => DMap k (NodeInfo k v)
74validPatchDMapWithMove = not . null . validationErrorsForPatchDMapWithMove
190validPatchDMapWithMove = not . null . validationErrorsForPatchDMapWithMove
76-- |Enumerate what reasons a 'PatchDMapWithMove' doesn't satisfy its invariants, returning @[]@ if it's valid.
192-- |Enumerate what reasons a 'PatchDMapWithMove' doesn't satisfy its invariants, returning @[]@ if it's valid.
77−validationErrorsForPatchDMapWithMove :: forall k v. (GCompare k, GShow k) => DMap k (NodeInfo k v) -> [String]
193+validationErrorsForPatchDMapWithMove
195+ . (GCompare k, GShow k)
196+ => DMap k (NodeInfo k v)
78validationErrorsForPatchDMapWithMove m =
198validationErrorsForPatchDMapWithMove m =
79 noSelfMoves <> movesBalanced
199 noSelfMoves <> movesBalanced
81 noSelfMoves = mapMaybe selfMove . DMap.toAscList $ m
201 noSelfMoves = mapMaybe selfMove . DMap.toAscList $ m
202+ selfMove (dst :=> NodeInfo (From_Move (src :=> _)) _)
82− selfMove (dst :=> NodeInfo (From_Move src) _) | Just _ <- dst `geq` src = Just $ "self move of key " <> gshow src <> " at destination side"
203+ | Just _ <- dst `geq` src = Just $ "self move of key " <> gshow src <> " at destination side"
204+ selfMove (src :=> NodeInfo _ (To_Move (dst :=> _)))
83− selfMove (src :=> NodeInfo _ (ComposeMaybe (Just dst))) | Just _ <- src `geq` dst = Just $ "self move of key " <> gshow dst <> " at source side"
205+ | Just _ <- src `geq` dst = Just $ "self move of key " <> gshow dst <> " at source side"
84 selfMove _ = Nothing
206 selfMove _ = Nothing
85 movesBalanced = mapMaybe unbalancedMove . DMap.toAscList $ m
207 movesBalanced = mapMaybe unbalancedMove . DMap.toAscList $ m
86− unbalancedMove (dst :=> NodeInfo (From_Move src) _) =
208+ unbalancedMove (dst :=> NodeInfo (From_Move (src :=> _)) _) =
87 case DMap.lookup src m of
209 case DMap.lookup src m of
88 Nothing -> Just $ "unbalanced move at destination key " <> gshow dst <> " supposedly from " <> gshow src <> " but source key is not in the patch"
210 Nothing -> Just $ "unbalanced move at destination key " <> gshow dst <> " supposedly from " <> gshow src <> " but source key is not in the patch"
89− Just (NodeInfo _ (ComposeMaybe (Just dst'))) ->
211+ Just (NodeInfo _ (To_Move (dst' :=> _))) ->
90 if isNothing (dst' `geq` dst)
212 if isNothing (dst' `geq` dst)
91 then Just $ "unbalanced move at destination key " <> gshow dst <> " from " <> gshow src <> " is going to " <> gshow dst' <> " instead"
213 then Just $ "unbalanced move at destination key " <> gshow dst <> " from " <> gshow src <> " is going to " <> gshow dst' <> " instead"
92 else Nothing
214 else Nothing
94 Just $ "unbalanced move at destination key " <> gshow dst <> " supposedly from " <> gshow src <> " but source key has no move to key"
216 Just $ "unbalanced move at destination key " <> gshow dst <> " supposedly from " <> gshow src <> " but source key has no move to key"
95− unbalancedMove (src :=> NodeInfo _ (ComposeMaybe (Just dst))) =
217+ unbalancedMove (src :=> NodeInfo _ (To_Move (dst :=> _))) =
96 case DMap.lookup dst m of
218 case DMap.lookup dst m of
97 Nothing -> Just $ " unbalanced move at source key " <> gshow src <> " supposedly going to " <> gshow dst <> " but destination key is not in the patch"
219 Nothing -> Just $ " unbalanced move at source key " <> gshow src <> " supposedly going to " <> gshow dst <> " but destination key is not in the patch"
98− Just (NodeInfo (From_Move src') _) ->
220+ Just (NodeInfo (From_Move (src' :=> _)) _) ->
99 if isNothing (src' `geq` src)
221 if isNothing (src' `geq` src)
100 then Just $ "unbalanced move at source key " <> gshow src <> " to " <> gshow dst <> " is coming from " <> gshow src' <> " instead"
222 then Just $ "unbalanced move at source key " <> gshow src <> " to " <> gshow dst <> " is coming from " <> gshow src' <> " instead"
101 else Nothing
223 else Nothing
@@ -104,35 +226,49 @@ validationErrorsForPatchDMapWithMove m =
104 Just $ "unbalanced move at source key " <> gshow src <> " supposedly going to " <> gshow dst <> " but destination key is not moving"
226 Just $ "unbalanced move at source key " <> gshow src <> " supposedly going to " <> gshow dst <> " but destination key is not moving"
105 unbalancedMove _ = Nothing
227 unbalancedMove _ = Nothing
107−-- |Test whether two @'PatchDMapWithMove' k v@ contain the same patch operations.
108−instance (GEq k, Has' Eq k (NodeInfo k v)) => Eq (PatchDMapWithMove k v) where
109− PatchDMapWithMove a == PatchDMapWithMove b = a == b
111-- |Higher kinded 2-tuple, identical to @Data.Functor.Product@ from base ≥ 4.9
229-- |Higher kinded 2-tuple, identical to @Data.Functor.Product@ from base ≥ 4.9
112data Pair1 f g a = Pair1 (f a) (g a)
230data Pair1 f g a = Pair1 (f a) (g a)
114-- |Helper data structure used for composing patches using the monoid instance.
232-- |Helper data structure used for composing patches using the monoid instance.
115−data Fixup k v a
233+data Fixup k p a
116 = Fixup_Delete
234 = Fixup_Delete
117− | Fixup_Update (These (From k v a) (To k a))
235+ | Fixup_Update (These (From k p a) (To k p a))
119−-- |Compose patches having the same effect as applying the patches in turn: @'applyAlways' (p <> q) == 'applyAlways' p . 'applyAlways' q@
237+-- | Compose patches having the same effect as applying the patches in turn:
238+-- @'applyAlways' (p <> q) == 'applyAlways' p . 'applyAlways' q@
239+instance ( GCompare k
240+ , Cat.Semigroupoid p
241+ -- , Cat.DecidablyEmpty p
243+ , PatchSource1 p ~ PatchTarget1 p
120−instance GCompare k => Semigroup (PatchDMapWithMove k v) where
244+ ) => Semigroup (PatchDMapWithMove k p) where
121 PatchDMapWithMove ma <> PatchDMapWithMove mb = PatchDMapWithMove m
245 PatchDMapWithMove ma <> PatchDMapWithMove mb = PatchDMapWithMove m
247+ connections :: [DSum k (Pair1 (To k p) (From k p))]
248+ connections = DMap.toList $ DMap.intersectionWithKey
123− connections = DMap.toList $ DMap.intersectionWithKey (\_ a b -> Pair1 (_nodeInfo_to a) (_nodeInfo_from b)) ma mb
249+ (\_ a b -> Pair1 (_nodeInfo_to a) (_nodeInfo_from b))
124− h :: DSum k (Pair1 (ComposeMaybe k) (From k v)) -> [DSum k (Fixup k v)]
252+ h :: DSum k (Pair1 (To k p) (From k p)) -> [DSum k (Fixup k p)]
125− h (_ :=> Pair1 (ComposeMaybe mToAfter) editBefore) = case (mToAfter, editBefore) of
253+ h ((_ :: k between) :=> Pair1 editAfter editBefore) = case (editAfter, editBefore) of
126− (Just toAfter, From_Move fromBefore)
254+ (To_Move ((toAfter :: k after) :=> p1), From_Move ((fromBefore :: k before) :=> Flip p0)) ->
127− | isJust $ fromBefore `geq` toAfter
255+ --case toAfter `geq` fromBefore of
256+ -- Just Refl | Just Refl <- Cat.isId p0 ->
128− -> [toAfter :=> Fixup_Delete]
257+ -- [ toAfter :=> Fixup_Delete ]
129− | otherwise
258+ -- _ ->
130− -> [ toAfter :=> Fixup_Update (This editBefore)
259+ [ toAfter :=> Fixup_Update (This $ From_Move $ fromBefore :=> (Flip $ p1 `o` p0))
131− , fromBefore :=> Fixup_Update (That (ComposeMaybe mToAfter))
260+ , fromBefore :=> Fixup_Update (That $ To_Move $ toAfter :=> (p1 `o` p0))
262+ (To_NonMove, From_Move (fromBefore :=> _)) ->
133− (Nothing, From_Move fromBefore) -> [fromBefore :=> Fixup_Update (That (ComposeMaybe mToAfter))] -- The item is destroyed in the second patch, so indicate that it is destroyed in the source map
263+ -- The item is destroyed in the second patch, so indicate that it is
264+ -- destroyed in the source map
265+ [fromBefore :=> Fixup_Update (That To_NonMove)]
266+ (To_Move (toAfter :=> p), From_Insert val) ->
267+ [toAfter :=> Fixup_Update (This $ From_Insert $ applyAlwaysHet2 p val)]
268+ (To_Move (toAfter :=> _), From_Delete) ->
134− (Just toAfter, _) -> [toAfter :=> Fixup_Update (This editBefore)]
269+ [toAfter :=> Fixup_Update (This From_Delete)]
135− (Nothing, _) -> []
270+ (To_NonMove, _) ->
136 mergeFixups _ Fixup_Delete Fixup_Delete = Fixup_Delete
272 mergeFixups _ Fixup_Delete Fixup_Delete = Fixup_Delete
137 mergeFixups _ (Fixup_Update a) (Fixup_Update b)
273 mergeFixups _ (Fixup_Update a) (Fixup_Update b)
138 | This x <- a, That y <- b
274 | This x <- a, That y <- b
@@ -163,13 +299,19 @@ instance GCompare k => Semigroup (PatchDMapWithMove k v) where
163 These _ b -> Just b
299 These _ b -> Just b
164 That b -> Just b
300 That b -> Just b
166−-- |Compose patches having the same effect as applying the patches in turn: @'applyAlways' (p <> q) == 'applyAlways' p . 'applyAlways' q@
302+-- | Compose patches having the same effect as applying the patches in turn:
303+-- @'applyAlways' (p <> q) == 'applyAlways' p . 'applyAlways' q@
304+instance ( GCompare k
305+ , Cat.Semigroupoid p
306+ -- , DecidablyEmpty p
308+ , PatchSource1 p ~ PatchTarget1 p
167−instance GCompare k => Monoid (PatchDMapWithMove k v) where
309+ ) => Monoid (PatchDMapWithMove k p) where
168 mempty = PatchDMapWithMove mempty
310 mempty = PatchDMapWithMove mempty
169 mappend = (<>)
311 mappend = (<>)
172−mappendPatchDMapWithMoveSlow :: forall k v. (ShowTag k v, GCompare k) => PatchDMapWithMove k v -> PatchDMapWithMove k v -> PatchDMapWithMove k v
314+mappendPatchDMapWithMoveSlow :: forall k v. (ShowTag k v, GCompare k) => PatchDMapWithMove k v -> PatchDMapWithMove k v -> PatchDMapWithMove k v
173PatchDMapWithMove dstAfter srcAfter `mappendPatchDMapWithMoveSlow` PatchDMapWithMove dstBefore srcBefore = PatchDMapWithMove dst src
315PatchDMapWithMove dstAfter srcAfter `mappendPatchDMapWithMoveSlow` PatchDMapWithMove dstBefore srcBefore = PatchDMapWithMove dst src
175 getDstAction k m = fromMaybe (From_Move k) $ DMap.lookup k m -- Any key that isn't present is treated as that key moving to itself
317 getDstAction k m = fromMaybe (From_Move k) $ DMap.lookup k m -- Any key that isn't present is treated as that key moving to itself
@@ -190,25 +332,31 @@ PatchDMapWithMove dstAfter srcAfter `mappendPatchDMapWithMoveSlow` PatchDMapWith
190 src = DMap.mapMaybeWithKey g $ DMap.union srcAfter srcBefore
332 src = DMap.mapMaybeWithKey g $ DMap.union srcAfter srcBefore
193−-- |Make a @'PatchDMapWithMove' k v@ which has the effect of inserting or updating a value @v a@ to the given key @k a@, like 'DMap.insert'.
335+-- | Make a @'PatchDMapWithMove' k v@ which has the effect of inserting or
336+-- updating a value @PatchTarget1 p a@ to the given key @k a@, like
194−insertDMapKey :: k a -> v a -> PatchDMapWithMove k v
338+insertDMapKey :: k a -> PatchTarget1 p a -> PatchDMapWithMove k p
195insertDMapKey k v =
339insertDMapKey k v =
196− PatchDMapWithMove . DMap.singleton k $ NodeInfo (From_Insert v) (ComposeMaybe Nothing)
340+ PatchDMapWithMove . DMap.singleton k $ NodeInfo (From_Insert v) To_NonMove
198−-- |Make a @'PatchDMapWithMove' k v@ which has the effect of moving the value from the first key @k a@ to the second key @k a@, equivalent to:
342+-- | Make a @'PatchDMapWithMove' k v@ which has the effect of moving the value
343+-- from the first key @k a@ to the second key @k a@, equivalent to:
201-- 'DMap.delete' src (maybe dmap ('DMap.insert' dst) (DMap.lookup src dmap))
346-- 'DMap.delete' src (maybe dmap ('DMap.insert' dst) (DMap.lookup src dmap))
203−moveDMapKey :: GCompare k => k a -> k a -> PatchDMapWithMove k v
350+ => k a -> k a -> PatchDMapWithMove k (Proxy3 v)
204moveDMapKey src dst = case src `geq` dst of
351moveDMapKey src dst = case src `geq` dst of
205 Nothing -> PatchDMapWithMove $ DMap.fromList
352 Nothing -> PatchDMapWithMove $ DMap.fromList
206− [ dst :=> NodeInfo (From_Move src) (ComposeMaybe Nothing)
353+ [ dst :=> NodeInfo (From_Move (src :=> Flip Proxy3)) To_NonMove
207− , src :=> NodeInfo From_Delete (ComposeMaybe $ Just dst)
354+ , src :=> NodeInfo From_Delete (To_Move $ dst :=> Proxy3)
209− Just _ -> mempty
356+ Just _ -> PatchDMapWithMove DMap.empty
211−-- |Make a @'PatchDMapWithMove' k v@ which has the effect of swapping two keys in the mapping, equivalent to:
358+-- | Make a @'PatchDMapWithMove' k v@ which has the effect of swapping two keys
359+-- in the mapping, equivalent to:
214-- let aMay = DMap.lookup a dmap
362-- let aMay = DMap.lookup a dmap
@@ -217,17 +365,18 @@ moveDMapKey src dst = case src `geq` dst of
217-- . maybe id (DMap.insert b) (aMay `mplus` bMay)
365-- . maybe id (DMap.insert b) (aMay `mplus` bMay)
218-- . DMap.delete a . DMap.delete b $ dmap
366-- . DMap.delete a . DMap.delete b $ dmap
220−swapDMapKey :: GCompare k => k a -> k a -> PatchDMapWithMove k v
368+swapDMapKey :: GCompare k => k a -> k a -> PatchDMapWithMove k (Proxy3 v)
221swapDMapKey src dst = case src `geq` dst of
369swapDMapKey src dst = case src `geq` dst of
222 Nothing -> PatchDMapWithMove $ DMap.fromList
370 Nothing -> PatchDMapWithMove $ DMap.fromList
223− [ dst :=> NodeInfo (From_Move src) (ComposeMaybe $ Just src)
371+ [ dst :=> NodeInfo (From_Move (src :=> Flip Proxy3)) (To_Move $ src :=> Proxy3)
224− , src :=> NodeInfo (From_Move dst) (ComposeMaybe $ Just dst)
372+ , src :=> NodeInfo (From_Move (dst :=> Flip Proxy3)) (To_Move $ dst :=> Proxy3)
226− Just _ -> mempty
374+ Just _ -> PatchDMapWithMove DMap.empty
228−-- |Make a @'PatchDMapWithMove' k v@ which has the effect of deleting a key in the mapping, equivalent to 'DMap.delete'.
376+-- | Make a @'PatchDMapWithMove' k v@ which has the effect of deleting a key in
377+-- the mapping, equivalent to 'DMap.delete'.
229deleteDMapKey :: k a -> PatchDMapWithMove k v
378deleteDMapKey :: k a -> PatchDMapWithMove k v
230−deleteDMapKey k = PatchDMapWithMove $ DMap.singleton k $ NodeInfo From_Delete $ ComposeMaybe Nothing
379+deleteDMapKey k = PatchDMapWithMove $ DMap.singleton k $ NodeInfo From_Delete To_NonMove
233k1, k2 :: Const2 Int () ()
382k1, k2 :: Const2 Int () ()
@@ -253,17 +402,20 @@ dst (PatchDMapWithMove x _) = x
253src (PatchDMapWithMove _ x) = x
402src (PatchDMapWithMove _ x) = x
256−-- |Extract the 'DMap' representing the patch changes from the 'PatchDMapWithMove'.
405+-- | Extract the 'DMap' representing the patch changes from the
406+-- 'PatchDMapWithMove'.
257unPatchDMapWithMove :: PatchDMapWithMove k v -> DMap k (NodeInfo k v)
407unPatchDMapWithMove :: PatchDMapWithMove k v -> DMap k (NodeInfo k v)
258unPatchDMapWithMove (PatchDMapWithMove p) = p
408unPatchDMapWithMove (PatchDMapWithMove p) = p
260−-- |Wrap a 'DMap' representing patch changes into a 'PatchDMapWithMove', without checking any invariants.
410+-- | Wrap a 'DMap' representing patch changes into a 'PatchDMapWithMove',
411+-- without checking any invariants.
262-- __Warning:__ when using this function, you must ensure that the invariants of 'PatchDMapWithMove' are preserved; they will not be checked.
413-- __Warning:__ when using this function, you must ensure that the invariants of 'PatchDMapWithMove' are preserved; they will not be checked.
263unsafePatchDMapWithMove :: DMap k (NodeInfo k v) -> PatchDMapWithMove k v
414unsafePatchDMapWithMove :: DMap k (NodeInfo k v) -> PatchDMapWithMove k v
264unsafePatchDMapWithMove = PatchDMapWithMove
415unsafePatchDMapWithMove = PatchDMapWithMove
417+-- | Wrap a 'DMap' representing patch changes into a 'PatchDMapWithMove' while
266−-- |Wrap a 'DMap' representing patch changes into a 'PatchDMapWithMove' while checking invariants. If the invariants are satisfied, @Right p@ is returned
418+-- checking invariants. If the invariants are satisfied, @Right p@ is returned
267-- otherwise @Left errors@.
419-- otherwise @Left errors@.
268patchDMapWithMove :: (GCompare k, GShow k) => DMap k (NodeInfo k v) -> Either [String] (PatchDMapWithMove k v)
420patchDMapWithMove :: (GCompare k, GShow k) => DMap k (NodeInfo k v) -> Either [String] (PatchDMapWithMove k v)
269patchDMapWithMove dm =
421patchDMapWithMove dm =
@@ -271,94 +423,196 @@ patchDMapWithMove dm =
271 [] -> Right $ unsafePatchDMapWithMove dm
423 [] -> Right $ unsafePatchDMapWithMove dm
272 errs -> Left errs
424 errs -> Left errs
274−-- |Map a natural transform @v -> v'@ over the given patch, transforming @'PatchDMapWithMove' k v@ into @'PatchDMapWithMove' k v'@.
426+-- | Map a natural transform @v -> v'@ over the given patch, transforming
427+-- @'PatchDMapWithMove' k v@ into @'PatchDMapWithMove' k v'@.
275−mapPatchDMapWithMove :: forall k v v'. (forall a. v a -> v' a) -> PatchDMapWithMove k v -> PatchDMapWithMove k v'
428+mapPatchDMapWithMove
430+ . (forall a. PatchTarget1 p a -> PatchTarget1 p' a)
431+ -> (forall from to. p from to -> p' from to)
432+ -> PatchDMapWithMove k p
433+ -> PatchDMapWithMove k p'
276−mapPatchDMapWithMove f (PatchDMapWithMove p) = PatchDMapWithMove $
434+mapPatchDMapWithMove f g (PatchDMapWithMove m) =
435+ PatchDMapWithMove $ DMap.map (\ni -> NodeInfo
277− DMap.map (\ni -> ni { _nodeInfo_from = g $ _nodeInfo_from ni }) p
436+ { _nodeInfo_from = h $ _nodeInfo_from ni
437+ , _nodeInfo_to = j $ _nodeInfo_to ni
278− where g :: forall a. From k v a -> From k v' a
439+ where h :: forall a. From k p a -> From k p' a
279− g = \case
440+ h = \case
280 From_Insert v -> From_Insert $ f v
441 From_Insert v -> From_Insert $ f v
281 From_Delete -> From_Delete
442 From_Delete -> From_Delete
282− From_Move k -> From_Move k
443+ From_Move (k :=> (Flip p)) -> From_Move $ k :=> Flip (g p)
283−
444+ j :: forall a. To k p a -> To k p' a
446+ To_NonMove -> To_NonMove
447+ To_Move (k :=> p) -> To_Move $ k :=> g p
449+-- | Traverse an effectful function @forall a. PatchTarget1 p a -> m (v ' a)@
284−-- |Traverse an effectful function @forall a. v a -> m (v ' a)@ over the given patch, transforming @'PatchDMapWithMove' k v@ into @m ('PatchDMapWithMove' k v')@.
450+-- over the given patch, transforming @'PatchDMapWithMove' k v@ into @m
451+-- ('PatchDMapWithMove' k v')@.
285−traversePatchDMapWithMove :: forall m k v v'. Applicative m => (forall a. v a -> m (v' a)) -> PatchDMapWithMove k v -> m (PatchDMapWithMove k v')
452+traversePatchDMapWithMove
455+ => (forall a. PatchTarget1 p a -> m (PatchTarget1 p' a))
456+ -> (forall from to. p from to -> m (p' from to))
457+ -> PatchDMapWithMove k p
458+ -> m (PatchDMapWithMove k p')
286−traversePatchDMapWithMove f = traversePatchDMapWithMoveWithKey $ const f
459+traversePatchDMapWithMove f g = traversePatchDMapWithMoveWithKey
463+-- | Map an effectful function @forall a. k a -> PatchTarget1 p a -> m (v ' a)@
288−-- |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')@.
464+-- over the given patch, transforming @'PatchDMapWithMove' k v@ into @m
465+-- ('PatchDMapWithMove' k v')@.
289−traversePatchDMapWithMoveWithKey :: forall m k v v'. Applicative m => (forall a. k a -> v a -> m (v' a)) -> PatchDMapWithMove k v -> m (PatchDMapWithMove k v')
466+traversePatchDMapWithMoveWithKey
469+ => (forall a. k a -> PatchTarget1 p a -> m (PatchTarget1 p' a))
470+ -> (forall from to. k from -> k to -> p from to -> m (p' from to))
471+ -> PatchDMapWithMove k p
472+ -> m (PatchDMapWithMove k p')
290−traversePatchDMapWithMoveWithKey f (PatchDMapWithMove p) = PatchDMapWithMove <$> DMap.traverseWithKey (nodeInfoMapFromM . g) p
473+traversePatchDMapWithMoveWithKey f g (PatchDMapWithMove m) =
474+ fmap PatchDMapWithMove $ DMap.traverseWithKey (\k ni -> NodeInfo
475+ <$> (h k $ _nodeInfo_from ni)
476+ <*> (j k $ _nodeInfo_to ni)) m
291− where g :: forall a. k a -> From k v a -> m (From k v' a)
477+ where h :: forall a. k a -> From k p a -> m (From k p' a)
292− g k = \case
478+ h k = \case
293 From_Insert v -> From_Insert <$> f k v
479 From_Insert v -> From_Insert <$> f k v
294 From_Delete -> pure From_Delete
480 From_Delete -> pure From_Delete
295− From_Move fromKey -> pure $ From_Move fromKey
481+ From_Move (fromKey :=> Flip p) -> From_Move . (fromKey :=>) . Flip <$> g fromKey k p
296−
482+ j :: forall a. k a -> To k p a -> m (To k p' a)
484+ To_NonMove -> pure To_NonMove
485+ To_Move (toKey :=> p) -> To_Move . (toKey :=>) <$> g k toKey p
297−-- |Map a function which transforms @'From' k v a@ into a @'From' k v' a@ over a @'NodeInfo' k v a@.
487+-- | Map a function which transforms @'From k PatchTarget1 p a@ into a @'From k
488+-- PatchTarget1 p' a@ over a @'NodeInfo' k PatchTarget1 p a@.
298−nodeInfoMapFrom :: (From k v a -> From k v' a) -> NodeInfo k v a -> NodeInfo k v' a
489+nodeInfoMapFrom
490+ :: (From k p a -> From k p' a)
491+ -> (To k p a -> To k p' a)
494+nodeInfoMapFrom f g ni = NodeInfo
299−nodeInfoMapFrom f ni = ni { _nodeInfo_from = f $ _nodeInfo_from ni }
495+ { _nodeInfo_from = f $ _nodeInfo_from ni
300−
496+ , _nodeInfo_to = g $ _nodeInfo_to ni
301−-- |Map an effectful function which transforms @'From' k v a@ into a @f ('From' k v' a)@ over a @'NodeInfo' k v a@.
499+-- | Map an effectful function which transforms @'From k PatchTarget1 p a@ into
500+-- a @f ('From k PatchTarget1 p' a)@ over a @'NodeInfo' k PatchTarget1 p a@.
302−nodeInfoMapFromM :: Functor f => (From k v a -> f (From k v' a)) -> NodeInfo k v a -> f (NodeInfo k v' a)
501+nodeInfoMapFromM
303−nodeInfoMapFromM f ni = fmap (\result -> ni { _nodeInfo_from = result }) $ f $ _nodeInfo_from ni
502+ :: Applicative f
304−
503+ => (From k p a -> f (From k p' a))
504+ -> (To k p a -> f (To k p' a))
506+ -> f (NodeInfo k p' a)
507+nodeInfoMapFromM f g ni = NodeInfo
508+ <$> (f $ _nodeInfo_from ni)
509+ <*> (g $ _nodeInfo_to ni)
305−-- |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
511+-- | Weaken a 'PatchDMapWithMove' to a 'PatchMapWithMove' by weakening the keys
512+-- from @k a@ to @'Some' k@ and applying a given weakening function
306−-- values.
513+-- @PatchTarget1 p a -> v'@ to values.
307−weakenPatchDMapWithMoveWith :: forall k v v'. (forall a. v a -> v') -> PatchDMapWithMove k v -> PatchMapWithMove (Some k) (Proxy v')
514+weakenPatchDMapWithMoveWith
516+ . (forall a. PatchTarget1 p a -> PatchTarget p')
517+ -> (forall from to. p from to -> p')
518+ -> PatchDMapWithMove k p
519+ -> PatchMapWithMove (Some k) p'
308−weakenPatchDMapWithMoveWith f (PatchDMapWithMove p) = PatchMapWithMove $ weakenDMapWith g p
520+weakenPatchDMapWithMoveWith f g (PatchDMapWithMove m) =
521+ PatchMapWithMove $ weakenDMapWith h m
309− where g :: forall a. NodeInfo k v a -> MapWithMove.NodeInfo (Some k) (Proxy v')
522+ where h :: forall a. NodeInfo k p a -> MapWithMove.NodeInfo (Some k) p'
310− g ni = MapWithMove.NodeInfo
523+ h ni = MapWithMove.NodeInfo
311 { MapWithMove._nodeInfo_from = case _nodeInfo_from ni of
524 { MapWithMove._nodeInfo_from = case _nodeInfo_from ni of
312 From_Insert v -> MapWithMove.From_Insert $ f v
525 From_Insert v -> MapWithMove.From_Insert $ f v
313 From_Delete -> MapWithMove.From_Delete
526 From_Delete -> MapWithMove.From_Delete
314− From_Move k -> MapWithMove.From_Move (Some k) Proxy
527+ From_Move (k :=> Flip p) -> MapWithMove.From_Move (Some k) $ g p
315− , MapWithMove._nodeInfo_to = Some <$> getComposeMaybe (_nodeInfo_to ni)
528+ , MapWithMove._nodeInfo_to = case _nodeInfo_to ni of
529+ To_NonMove -> MapWithMove.To_NonMove
530+ To_Move (k :=> p) -> MapWithMove.To_Move (Some k) $ g p
533+-- | "Weaken" a @'PatchDMapWithMove' (Const2 k a) v@ to a @'PatchMapWithMove' k
318−-- |"Weaken" a @'PatchDMapWithMove' (Const2 k a) v@ to a @'PatchMapWithMove' k v'@. Weaken is in scare quotes because the 'Const2' has already disabled any
534+-- v'@. Weaken is in scare quotes because the 'Const2' has already disabled any
319−-- dependency in the typing and all points are already @a@, hence the function to map each value to @v'@ is not higher rank.
535+-- dependency in the typing and all points are already @a@, hence the function
536+-- to map each value to @v'@ is not higher rank.
320−patchDMapWithMoveToPatchMapWithMoveWith :: forall k v v' a. (v a -> v') -> PatchDMapWithMove (Const2 k a) v -> PatchMapWithMove k (Proxy v')
537+patchDMapWithMoveToPatchMapWithMoveWith
539+ . (PatchTarget1 p a -> PatchTarget p')
541+ -> PatchDMapWithMove (Const2 k a) p
542+ -> PatchMapWithMove k p'
321−patchDMapWithMoveToPatchMapWithMoveWith f (PatchDMapWithMove p) = PatchMapWithMove $ dmapToMapWith g p
543+patchDMapWithMoveToPatchMapWithMoveWith f g (PatchDMapWithMove m) =
544+ PatchMapWithMove $ dmapToMapWith h m
322− where g :: NodeInfo (Const2 k a) v a -> MapWithMove.NodeInfo k (Proxy v')
545+ where h :: NodeInfo (Const2 k a) p a -> MapWithMove.NodeInfo k p'
323− g ni = MapWithMove.NodeInfo
546+ h ni = MapWithMove.NodeInfo
324 { MapWithMove._nodeInfo_from = case _nodeInfo_from ni of
547 { MapWithMove._nodeInfo_from = case _nodeInfo_from ni of
325 From_Insert v -> MapWithMove.From_Insert $ f v
548 From_Insert v -> MapWithMove.From_Insert $ f v
326 From_Delete -> MapWithMove.From_Delete
549 From_Delete -> MapWithMove.From_Delete
327− From_Move (Const2 k) -> MapWithMove.From_Move k Proxy
550+ From_Move (Const2 k :=> Flip p) -> MapWithMove.From_Move k $ g p
328− , MapWithMove._nodeInfo_to = unConst2 <$> getComposeMaybe (_nodeInfo_to ni)
551+ , MapWithMove._nodeInfo_to = case _nodeInfo_to ni of
552+ To_NonMove -> MapWithMove.To_NonMove
553+ To_Move (Const2 k :=> p) -> MapWithMove.To_Move k $ g p
331−-- |"Strengthen" a @'PatchMapWithMove' k v@ into a @'PatchDMapWithMove ('Const2' k a)@; that is, turn a non-dependently-typed patch into a dependently typed
556+-- | "Strengthen" a @'PatchMapWithMove' k v@ into a @'PatchDMapWithMove
557+-- ('Const2' k a)@; that is, turn a non-dependently-typed patch into a
332−-- one but which always has a constant key type represented by 'Const2'. Apply the given function to each @v@ to produce a @v' a@.
558+-- dependently typed one but which always has a constant key type represented by
559+-- 'Const2'. Apply the given function to each @v@ to produce a @PatchTarget1 p'
333−-- Completemented by 'patchDMapWithMoveToPatchMapWithMoveWith'
560+-- a@. Completemented by 'patchDMapWithMoveToPatchMapWithMoveWith'
334−const2PatchDMapWithMoveWith :: forall k v v' a. (v -> v' a) -> PatchMapWithMove k (Proxy v) -> PatchDMapWithMove (Const2 k a) v'
561+const2PatchDMapWithMoveWith
564+ -> PatchMapWithMove k (Proxy v)
565+ -> PatchDMapWithMove (Const2 k a) (Proxy3 v')
566+const2PatchDMapWithMoveWith f (PatchMapWithMove p) =
335−const2PatchDMapWithMoveWith f (PatchMapWithMove p) = PatchDMapWithMove $ DMap.fromDistinctAscList $ g <$> Map.toAscList p
567+ PatchDMapWithMove $ DMap.fromDistinctAscList $ g <$> Map.toAscList p
336− where g :: (k, MapWithMove.NodeInfo k (Proxy v)) -> DSum (Const2 k a) (NodeInfo (Const2 k a) v')
568+ where g :: (k, MapWithMove.NodeInfo k (Proxy v))
569+ -> DSum (Const2 k a) (NodeInfo (Const2 k a) (Proxy3 v'))
337 g (k, ni) = Const2 k :=> NodeInfo
570 g (k, ni) = Const2 k :=> NodeInfo
338 { _nodeInfo_from = case MapWithMove._nodeInfo_from ni of
571 { _nodeInfo_from = case MapWithMove._nodeInfo_from ni of
339 MapWithMove.From_Insert v -> From_Insert $ f v
572 MapWithMove.From_Insert v -> From_Insert $ f v
340 MapWithMove.From_Delete -> From_Delete
573 MapWithMove.From_Delete -> From_Delete
341− MapWithMove.From_Move fromKey Proxy -> From_Move $ Const2 fromKey
574+ MapWithMove.From_Move fromKey Proxy -> From_Move $ Const2 fromKey :=> Flip Proxy3
342− , _nodeInfo_to = ComposeMaybe $ Const2 <$> MapWithMove._nodeInfo_to ni
575+ , _nodeInfo_to = case MapWithMove._nodeInfo_to ni of
576+ MapWithMove.To_NonMove -> To_NonMove
577+ MapWithMove.To_Move toKey Proxy -> To_Move $ Const2 toKey :=> Proxy3
345-- | Apply the insertions, deletions, and moves to a given 'DMap'.
580-- | Apply the insertions, deletions, and moves to a given 'DMap'.
581+instance ( GCompare k
583+ , PatchSource1 p ~ PatchTarget1 p
346−instance GCompare k => Patch (PatchDMapWithMove k v) where
584+ ) => PatchHet (PatchDMapWithMove k p) where
585+ type PatchSource (PatchDMapWithMove k p) = DMap k (PatchSource1 p)
347− type PatchTarget (PatchDMapWithMove k v) = DMap k v
586+ type PatchTarget (PatchDMapWithMove k p) = DMap k (PatchTarget1 p)
588+instance ( GCompare k
590+ , PatchSource1 p ~ PatchTarget1 p
591+ ) => Patch (PatchDMapWithMove k p) where
348− apply (PatchDMapWithMove p) old = Just $! insertions `DMap.union` (old `DMap.difference` deletions) --TODO: return Nothing sometimes --Note: the strict application here is critical to ensuring that incremental merges don't hold onto all their prerequisite events forever; can we make this more robust?
592+ apply (PatchDMapWithMove m) old = Just $! insertions `DMap.union` (old `DMap.difference` deletions)
593+ -- TODO: return Nothing sometimes --Note: the strict application here is
594+ -- critical to ensuring that incremental merges don't hold onto all their
595+ -- prerequisite events forever; can we make this more robust?
349− where insertions = DMap.mapMaybeWithKey insertFunc p
596+ where insertions = DMap.mapMaybeWithKey insertFunc m
350− insertFunc :: forall a. k a -> NodeInfo k v a -> Maybe (v a)
597+ insertFunc :: forall a. k a -> NodeInfo k p a -> Maybe (PatchTarget1 p a)
351 insertFunc _ ni = case _nodeInfo_from ni of
598 insertFunc _ ni = case _nodeInfo_from ni of
352 From_Insert v -> Just v
599 From_Insert v -> Just v
353− From_Move k -> DMap.lookup k old
600+ From_Move (k :=> Flip p) -> applyAlwaysHet2 p <$> DMap.lookup k old
354 From_Delete -> Nothing
601 From_Delete -> Nothing
355− deletions = DMap.mapMaybeWithKey deleteFunc p
602+ deletions = DMap.mapMaybeWithKey deleteFunc m
356− deleteFunc :: forall a. k a -> NodeInfo k v a -> Maybe (Constant () a)
603+ deleteFunc :: forall a. k a -> NodeInfo k p a -> Maybe (Constant () a)
357 deleteFunc _ ni = case _nodeInfo_from ni of
604 deleteFunc _ ni = case _nodeInfo_from ni of
358 From_Delete -> Just $ Constant ()
605 From_Delete -> Just $ Constant ()
359 _ -> Nothing
606 _ -> Nothing
361−-- | Get the values that will be replaced, deleted, or moved if the given patch is applied to the given 'DMap'.
608+-- | Get the values that will be replaced, deleted, or moved if the given patch
609+-- is applied to the given 'DMap'.
362−getDeletionsAndMoves :: GCompare k => PatchDMapWithMove k v -> DMap k v' -> DMap k (Product v' (ComposeMaybe k))
610+getDeletionsAndMoves
612+ , PatchSource1 p ~ PatchTarget1 p
614+ => PatchDMapWithMove k p
615+ -> DMap k (PatchSource1 p)
616+ -> DMap k (Product (PatchTarget1 p) (To k p))
363getDeletionsAndMoves (PatchDMapWithMove p) m = DMap.intersectionWithKey f m p
617getDeletionsAndMoves (PatchDMapWithMove p) m = DMap.intersectionWithKey f m p
364 where f _ v ni = Pair v $ _nodeInfo_to ni
618 where f _ v ni = Pair v $ _nodeInfo_to ni