@@ -1,4 +1,5 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE CPP #-}
2+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
2{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE LambdaCase #-}
5{-# LANGUAGE LambdaCase #-}
@@ -25,7 +26,7 @@ import Data.List
25import Data.Map (Map)
26import Data.Map (Map)
26import qualified Data.Map as Map
27import qualified Data.Map as Map
27import Data.Maybe
28import Data.Maybe
28−#if !MIN_VERSION_base(4,10,0)
29+#if !MIN_VERSION_base(4,11,0)
29import Data.Semigroup (Semigroup (..))
30import Data.Semigroup (Semigroup (..))
31import Data.Monoid.DecidablyEmpty
32import Data.Monoid.DecidablyEmpty
@@ -46,6 +47,14 @@ deriving instance (Ord k, Read k, Read p, Read (PatchTarget p)) => Read (PatchMa
46deriving instance (Eq k, Eq p, Eq (PatchTarget p)) => Eq (PatchMapWithPatchingMove k p)
47deriving instance (Eq k, Eq p, Eq (PatchTarget p)) => Eq (PatchMapWithPatchingMove k p)
47deriving instance (Ord k, Ord p, Ord (PatchTarget p)) => Ord (PatchMapWithPatchingMove k p)
48deriving instance (Ord k, Ord p, Ord (PatchTarget p)) => Ord (PatchMapWithPatchingMove k p)
50+deriving instance ( Ord k
51+#if !MIN_VERSION_base(4,11,0)
56+ ) => DecidablyEmpty (PatchMapWithPatchingMove k p)
49-- | Holds the information about each key: where its new value should come from,
58-- | Holds the information about each key: where its new value should come from,
50-- and where its old value should go to
59-- and where its old value should go to
51data NodeInfo k p = NodeInfo
60data NodeInfo k p = NodeInfo
@@ -127,7 +136,13 @@ insertMapKey k v = PatchMapWithPatchingMove . Map.singleton k $ NodeInfo (From_I
127-- 'Map.delete' src (maybe map ('Map.insert' dst) (Map.lookup src map))
136-- 'Map.delete' src (maybe map ('Map.insert' dst) (Map.lookup src map))
129moveMapKey
138moveMapKey
139+ :: ( DecidablyEmpty p
140+#if !MIN_VERSION_base(4,11,0)
130− :: (DecidablyEmpty p, Patch p) => Ord k => k -> k -> PatchMapWithPatchingMove k p
145+ => Ord k => k -> k -> PatchMapWithPatchingMove k p
131moveMapKey src dst
146moveMapKey src dst
132 | src == dst = mempty
147 | src == dst = mempty
133 | otherwise =
148 | otherwise =
@@ -146,7 +161,12 @@ moveMapKey src dst
146-- . Map.delete a . Map.delete b $ map
161-- . Map.delete a . Map.delete b $ map
148swapMapKey
163swapMapKey
149− :: (DecidablyEmpty p, Patch p)
164+ :: ( DecidablyEmpty p
165+#if !MIN_VERSION_base(4,11,0)
150 => Ord k => k -> k -> PatchMapWithPatchingMove k p
170 => Ord k => k -> k -> PatchMapWithPatchingMove k p
151swapMapKey src dst
171swapMapKey src dst
152 | src == dst = mempty
172 | src == dst = mempty
@@ -248,7 +268,7 @@ patchThatChangesMap oldByIndex newByIndex = patch
248 putRemainingKeys $ Set.delete k fromKs
268 putRemainingKeys $ Set.delete k fromKs
249 return $ NodeInfo (From_Move k mempty) $ Just undefined -- There's an existing value, and it's here, so no patch necessary
269 return $ NodeInfo (From_Move k mempty) $ Just undefined -- There's an existing value, and it's here, so no patch necessary
251− (fromK, remainingKeys) <- return . fromJust $ Set.minView fromKs -- There's an existing value, but it's not here; move it here
271+ (fromK, remainingKeys) <- return . fromMaybe (error "patchThatChangesMap: impossible: fromKs was empty") $ Set.minView fromKs -- There's an existing value, but it's not here; move it here
252 putRemainingKeys remainingKeys
272 putRemainingKeys remainingKeys
253 return $ NodeInfo (From_Move fromK mempty) $ Just undefined
273 return $ NodeInfo (From_Move fromK mempty) $ Just undefined
254 Map.traverseWithKey f newByIndex
274 Map.traverseWithKey f newByIndex
@@ -277,14 +297,17 @@ nodeInfoSetTo
277 :: To k -> NodeInfo k v -> NodeInfo k v
297 :: To k -> NodeInfo k v -> NodeInfo k v
278nodeInfoSetTo to ni = ni { _nodeInfo_to = to }
298nodeInfoSetTo to ni = ni { _nodeInfo_to = to }
280−-- |Helper data structure used for composing patches using the monoid instance.
300+-- | Helper data structure used for composing patches using the monoid instance.
281data Fixup k v
301data Fixup k v
282 = Fixup_Delete
302 = Fixup_Delete
283 | Fixup_Update (These (From k v) (To k))
303 | Fixup_Update (These (From k v) (To k))
285−-- |Compose patches having the same effect as applying the patches in turn: @'applyAlways' (p <> q) == 'applyAlways' p . 'applyAlways' q@
305+-- | Compose patches having the same effect as applying the patches in turn:
306+-- @'applyAlways' (p <> q) == 'applyAlways' p . 'applyAlways' q@
286instance ( Ord k
307instance ( Ord k
287− , Monoid p
308+#if !MIN_VERSION_base(4,11,0)
288 , DecidablyEmpty p
311 , DecidablyEmpty p
289 , Patch p
312 , Patch p
290 ) => Semigroup (PatchMapWithPatchingMove k p) where
313 ) => Semigroup (PatchMapWithPatchingMove k p) where
@@ -343,7 +366,9 @@ instance ( Ord k
343-- | Compose patches having the same effect as applying the patches in turn:
366-- | Compose patches having the same effect as applying the patches in turn:
344-- @'applyAlways' (p <> q) == 'applyAlways' p . 'applyAlways' q@
367-- @'applyAlways' (p <> q) == 'applyAlways' p . 'applyAlways' q@
345instance ( Ord k
368instance ( Ord k
346− , Monoid p
369+#if !MIN_VERSION_base(4,11,0)
347 , DecidablyEmpty p
372 , DecidablyEmpty p
348 , Patch p
373 , Patch p
349 ) => Monoid (PatchMapWithPatchingMove k p) where
374 ) => Monoid (PatchMapWithPatchingMove k p) where