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