-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Data structures for describing changes to other data structures. -- -- Data structures for describing changes to other data structures. -- -- In this library, a patch is something which can be applied, analogous -- to a function, and which distinguishes returning the argument it was -- provided from returning something else. @package patch @version 0.0.4.0 -- | This module provides types and functions with no particular theme, but -- which are relevant to the use of Functor-based datastructures -- like DMap. module Data.Functor.Misc -- | Const2 stores a value of a given type k and ensures -- that a particular type v is always given for the last type -- parameter data Const2 :: * -> x -> x -> * [Const2] :: k -> Const2 k v v -- | Extract the value from a Const2 unConst2 :: Const2 k v v' -> k -- | Convert a DMap to a regular Map dmapToMap :: DMap (Const2 k v) Identity -> Map k v -- | Convert a DMap to an IntMap dmapToIntMap :: DMap (Const2 Key v) Identity -> IntMap v -- | Convert a DMap to a regular Map, applying the given -- function to remove the wrapping Functor dmapToMapWith :: (f v -> v') -> DMap (Const2 k v) f -> Map k v' -- | Convert a regular Map to a DMap mapToDMap :: Map k v -> DMap (Const2 k v) Identity -- | Convert a DMap to a regular Map by forgetting the types -- associated with the keys, using a function to remove the wrapping -- Functor weakenDMapWith :: (forall a. v a -> v') -> DMap k v -> Map (Some k) v' -- | WrapArg can be used to tag a value in one functor with a type -- representing another functor. This was primarily used with -- dependent-map < 0.2, in which the value type was not wrapped in a -- separate functor. data WrapArg :: (k -> *) -> (k -> *) -> * -> * [WrapArg] :: f a -> WrapArg g f (g a) -- | Convert a regular Map, where the values are already wrapped in -- a functor, to a DMap mapWithFunctorToDMap :: Map k (f v) -> DMap (Const2 k v) f -- | Convert a regular IntMap, where the values are already wrapped -- in a functor, to a DMap intMapWithFunctorToDMap :: IntMap (f v) -> DMap (Const2 Key v) f -- | Map over all key/value pairs in a DMap, potentially altering -- the key as well as the value. The provided function MUST preserve the -- ordering of the keys, or the resulting DMap will be malformed. mapKeyValuePairsMonotonic :: (DSum k v -> DSum k' v') -> DMap k v -> DMap k' v' -- | Union two DMaps of different types, yielding another type. Each -- key that is present in either input map will be present in the output. combineDMapsWithKey :: forall f g h i. GCompare f => (forall a. f a -> These (g a) (h a) -> i a) -> DMap f g -> DMap f h -> DMap f i -- | Tag type for Either to use it as a DSum. data EitherTag l r a [LeftTag] :: EitherTag l r l [RightTag] :: EitherTag l r r -- | Extract the values of a DMap of EitherTags. dmapToThese :: DMap (EitherTag a b) Identity -> Maybe (These a b) -- | Convert Either to a DSum. Inverse of -- dsumToEither. eitherToDSum :: Either a b -> DSum (EitherTag a b) Identity -- | Convert DSum to Either. Inverse of eitherToDSum. dsumToEither :: DSum (EitherTag a b) Identity -> Either a b -- | We can't use Compose Maybe instead of ComposeMaybe, -- because that would make the f parameter have a nominal type -- role. We need f to be representational so that we can use safe -- coerce. newtype ComposeMaybe f a ComposeMaybe :: Maybe (f a) -> ComposeMaybe f a [getComposeMaybe] :: ComposeMaybe f a -> Maybe (f a) instance forall k (f :: k -> *) (a :: k). GHC.Classes.Ord (f a) => GHC.Classes.Ord (Data.Functor.Misc.ComposeMaybe f a) instance forall k (f :: k -> *) (a :: k). GHC.Classes.Eq (f a) => GHC.Classes.Eq (Data.Functor.Misc.ComposeMaybe f a) instance forall k (f :: k -> *) (a :: k). GHC.Show.Show (f a) => GHC.Show.Show (Data.Functor.Misc.ComposeMaybe f a) instance forall x k (v :: x) (v' :: x). GHC.Classes.Eq k => GHC.Classes.Eq (Data.Functor.Misc.Const2 k v v') instance forall x k (v :: x) (v' :: x). GHC.Classes.Ord k => GHC.Classes.Ord (Data.Functor.Misc.Const2 k v v') instance forall x k (v :: x) (v' :: x). GHC.Show.Show k => GHC.Show.Show (Data.Functor.Misc.Const2 k v v') instance forall x k (v :: x). GHC.Read.Read k => GHC.Read.Read (Data.Functor.Misc.Const2 k v v) instance forall k (f :: k -> *) (a :: k) (g :: k -> *) (g' :: k -> *). GHC.Classes.Eq (f a) => GHC.Classes.Eq (Data.Functor.Misc.WrapArg g f (g' a)) instance forall k (f :: k -> *) (a :: k) (g :: k -> *) (g' :: k -> *). GHC.Classes.Ord (f a) => GHC.Classes.Ord (Data.Functor.Misc.WrapArg g f (g' a)) instance forall k (f :: k -> *) (a :: k) (g :: k -> *) (g' :: k -> *). GHC.Show.Show (f a) => GHC.Show.Show (Data.Functor.Misc.WrapArg g f (g' a)) instance forall k (f :: k -> *) (a :: k) (g :: k -> *). GHC.Read.Read (f a) => GHC.Read.Read (Data.Functor.Misc.WrapArg g f (g a)) instance forall k (l :: k) (r :: k) (a :: k). GHC.Show.Show (Data.Functor.Misc.EitherTag l r a) instance forall k (l :: k) (r :: k) (a :: k). GHC.Classes.Eq (Data.Functor.Misc.EitherTag l r a) instance forall k (l :: k) (r :: k) (a :: k). GHC.Classes.Ord (Data.Functor.Misc.EitherTag l r a) instance GHC.Base.Functor f => GHC.Base.Functor (Data.Functor.Misc.ComposeMaybe f) instance forall k (l :: k) (r :: k). Data.GADT.Internal.GEq (Data.Functor.Misc.EitherTag l r) instance forall k (l :: k) (r :: k). Data.GADT.Internal.GCompare (Data.Functor.Misc.EitherTag l r) instance forall k (l :: k) (r :: k). Data.GADT.Internal.GShow (Data.Functor.Misc.EitherTag l r) instance forall k (f :: k -> *) (g :: k -> *). Data.GADT.Internal.GEq f => Data.GADT.Internal.GEq (Data.Functor.Misc.WrapArg g f) instance forall k (f :: k -> *) (g :: k -> *). Data.GADT.Internal.GCompare f => Data.GADT.Internal.GCompare (Data.Functor.Misc.WrapArg g f) instance forall k1 k2 (v :: k1). GHC.Show.Show k2 => Data.GADT.Internal.GShow (Data.Functor.Misc.Const2 k2 v) instance forall k1 k2 (v :: k1). GHC.Classes.Eq k2 => Data.GADT.Internal.GEq (Data.Functor.Misc.Const2 k2 v) instance forall k1 k2 (v :: k1). GHC.Classes.Ord k2 => Data.GADT.Internal.GCompare (Data.Functor.Misc.Const2 k2 v) module Data.Monoid.DecidablyEmpty -- | A DecidablyEmpty is one where it can be computed whether or not -- an arbitrary value is mempty. -- -- By using this class rather than Eq, we avoid unnecessary -- constraining the contents of Functors. This makes it possible -- to efficiently combine and/or nest patch maps with Eq-lacking -- values (e.g. functions) at the leaves. class Monoid a => DecidablyEmpty a isEmpty :: DecidablyEmpty a => a -> Bool isEmpty :: (DecidablyEmpty a, Eq a) => a -> Bool instance (GHC.Num.Num a, Data.Monoid.DecidablyEmpty.DecidablyEmpty a) => Data.Monoid.DecidablyEmpty.DecidablyEmpty (Data.Semigroup.Internal.Product a) instance (Data.Monoid.DecidablyEmpty.DecidablyEmpty a, GHC.Num.Num a) => Data.Monoid.DecidablyEmpty.DecidablyEmpty (Data.Semigroup.Internal.Sum a) instance Data.Monoid.DecidablyEmpty.DecidablyEmpty a => Data.Monoid.DecidablyEmpty.DecidablyEmpty (Data.Semigroup.Internal.Dual a) instance Data.Monoid.DecidablyEmpty.DecidablyEmpty a => Data.Monoid.DecidablyEmpty.DecidablyEmpty (Data.Functor.Identity.Identity a) instance Data.Monoid.DecidablyEmpty.DecidablyEmpty m => Data.Monoid.DecidablyEmpty.DecidablyEmpty (Data.Semigroup.WrappedMonoid m) instance forall k a (b :: k). Data.Monoid.DecidablyEmpty.DecidablyEmpty a => Data.Monoid.DecidablyEmpty.DecidablyEmpty (Data.Functor.Const.Const a b) instance Data.Monoid.DecidablyEmpty.DecidablyEmpty a => Data.Monoid.DecidablyEmpty.DecidablyEmpty (Data.Ord.Down a) instance Data.Monoid.DecidablyEmpty.DecidablyEmpty p => Data.Monoid.DecidablyEmpty.DecidablyEmpty (GHC.Generics.Par1 p) instance forall k (f :: k -> *) (p :: k). Data.Monoid.DecidablyEmpty.DecidablyEmpty (f p) => Data.Monoid.DecidablyEmpty.DecidablyEmpty (GHC.Generics.Rec1 f p) instance forall k (f :: k -> *) (p :: k) i (c :: GHC.Generics.Meta). Data.Monoid.DecidablyEmpty.DecidablyEmpty (f p) => Data.Monoid.DecidablyEmpty.DecidablyEmpty (GHC.Generics.M1 i c f p) instance forall k c i (p :: k). Data.Monoid.DecidablyEmpty.DecidablyEmpty c => Data.Monoid.DecidablyEmpty.DecidablyEmpty (GHC.Generics.K1 i c p) instance forall k1 k2 (f :: k2 -> *) (g :: k1 -> k2) (p :: k1). Data.Monoid.DecidablyEmpty.DecidablyEmpty (f (g p)) => Data.Monoid.DecidablyEmpty.DecidablyEmpty ((GHC.Generics.:.:) f g p) instance Data.Monoid.DecidablyEmpty.DecidablyEmpty GHC.Types.Ordering instance Data.Monoid.DecidablyEmpty.DecidablyEmpty () instance Data.Monoid.DecidablyEmpty.DecidablyEmpty Data.Semigroup.Internal.Any instance Data.Monoid.DecidablyEmpty.DecidablyEmpty Data.Semigroup.Internal.All instance Data.Monoid.DecidablyEmpty.DecidablyEmpty [a] instance GHC.Base.Semigroup a => Data.Monoid.DecidablyEmpty.DecidablyEmpty (GHC.Maybe.Maybe a) instance Data.Monoid.DecidablyEmpty.DecidablyEmpty (Data.Monoid.First a) instance Data.Monoid.DecidablyEmpty.DecidablyEmpty (Data.Monoid.Last a) instance GHC.Base.Semigroup a => Data.Monoid.DecidablyEmpty.DecidablyEmpty (Data.Semigroup.Option a) instance (GHC.Classes.Ord a, GHC.Enum.Bounded a) => Data.Monoid.DecidablyEmpty.DecidablyEmpty (Data.Semigroup.Max a) instance (GHC.Classes.Ord a, GHC.Enum.Bounded a) => Data.Monoid.DecidablyEmpty.DecidablyEmpty (Data.Semigroup.Min a) instance forall k (s :: k). Data.Monoid.DecidablyEmpty.DecidablyEmpty (Data.Proxy.Proxy s) instance forall k (p :: k). Data.Monoid.DecidablyEmpty.DecidablyEmpty (GHC.Generics.U1 p) instance forall k (f :: k -> *) (p :: k) (g :: k -> *). (Data.Monoid.DecidablyEmpty.DecidablyEmpty (f p), Data.Monoid.DecidablyEmpty.DecidablyEmpty (g p)) => Data.Monoid.DecidablyEmpty.DecidablyEmpty ((GHC.Generics.:*:) f g p) instance (Data.Monoid.DecidablyEmpty.DecidablyEmpty a, Data.Monoid.DecidablyEmpty.DecidablyEmpty b) => Data.Monoid.DecidablyEmpty.DecidablyEmpty (a, b) instance (Data.Monoid.DecidablyEmpty.DecidablyEmpty a, Data.Monoid.DecidablyEmpty.DecidablyEmpty b, Data.Monoid.DecidablyEmpty.DecidablyEmpty c) => Data.Monoid.DecidablyEmpty.DecidablyEmpty (a, b, c) instance (Data.Monoid.DecidablyEmpty.DecidablyEmpty a, Data.Monoid.DecidablyEmpty.DecidablyEmpty b, Data.Monoid.DecidablyEmpty.DecidablyEmpty c, Data.Monoid.DecidablyEmpty.DecidablyEmpty d) => Data.Monoid.DecidablyEmpty.DecidablyEmpty (a, b, c, d) instance (Data.Monoid.DecidablyEmpty.DecidablyEmpty a, Data.Monoid.DecidablyEmpty.DecidablyEmpty b, Data.Monoid.DecidablyEmpty.DecidablyEmpty c, Data.Monoid.DecidablyEmpty.DecidablyEmpty d, Data.Monoid.DecidablyEmpty.DecidablyEmpty e) => Data.Monoid.DecidablyEmpty.DecidablyEmpty (a, b, c, d, e) instance Data.Monoid.DecidablyEmpty.DecidablyEmpty Data.IntSet.Internal.IntSet instance Data.Monoid.DecidablyEmpty.DecidablyEmpty (Data.IntMap.Internal.IntMap v) instance GHC.Classes.Ord k => Data.Monoid.DecidablyEmpty.DecidablyEmpty (Data.Map.Internal.Map k v) instance Data.Monoid.DecidablyEmpty.DecidablyEmpty (Data.Sequence.Internal.Seq v) instance GHC.Classes.Ord k => Data.Monoid.DecidablyEmpty.DecidablyEmpty (Data.Set.Internal.Set k) instance forall k1 (k2 :: k1 -> *) (v :: k1 -> *). Data.GADT.Internal.GCompare k2 => Data.Monoid.DecidablyEmpty.DecidablyEmpty (Data.Dependent.Map.Internal.DMap k2 v) -- | The interface for types which represent changes made to other types module Data.Patch.Class -- | A Patch type represents a kind of change made to a -- datastructure. -- -- If an instance of Patch is also an instance of -- Semigroup, it should obey the law that applyAlways (f -- <> g) == applyAlways f . applyAlways g. class Patch p where { type family PatchTarget p :: *; } -- | Apply the patch p a to the value a. If no change is -- needed, return Nothing. apply :: Patch p => p -> PatchTarget p -> Maybe (PatchTarget p) -- | Apply a Patch; if it does nothing, return the original value applyAlways :: Patch p => p -> PatchTarget p -> PatchTarget p -- | Like '(.)', but composes functions that return patches rather than -- functions that return new values. The Semigroup instance for patches -- must apply patches right-to-left, like '(.)'. composePatchFunctions :: (Patch p, Semigroup p) => (PatchTarget p -> p) -> (PatchTarget p -> p) -> PatchTarget p -> p instance Data.Patch.Class.Patch (Data.Functor.Identity.Identity a) instance Data.Patch.Class.Patch (Data.Proxy.Proxy a) -- | Module containing PatchIntMap, a Patch for IntMap -- which allows for insert/update or delete of associations. module Data.Patch.IntMap -- | Patch for IntMap which represents insertion or deletion -- of keys in the mapping. Internally represented by 'IntMap (Maybe a)', -- where Just means insert/update and Nothing means -- delete. newtype PatchIntMap a PatchIntMap :: IntMap (Maybe a) -> PatchIntMap a [unPatchIntMap] :: PatchIntMap a -> IntMap (Maybe a) -- | Map a function Int -> a -> b over all as in -- the given PatchIntMap a (that is, all -- inserts/updates), producing a PatchIntMap b. mapIntMapPatchWithKey :: (Int -> a -> b) -> PatchIntMap a -> PatchIntMap b -- | Map an effectful function Int -> a -> f b over all -- as in the given PatchIntMap a (that is, all -- inserts/updates), producing a f (PatchIntMap b). traverseIntMapPatchWithKey :: Applicative f => (Int -> a -> f b) -> PatchIntMap a -> f (PatchIntMap b) -- | Extract all as inserted/updated by the given -- PatchIntMap a. patchIntMapNewElements :: PatchIntMap a -> [a] -- | Convert the given PatchIntMap a into an -- IntMap a with all the inserts/updates in the given -- patch. patchIntMapNewElementsMap :: PatchIntMap a -> IntMap a -- | Subset the given IntMap a to contain only the keys -- that would be deleted by the given PatchIntMap a. getDeletions :: PatchIntMap v -> IntMap v' -> IntMap v' instance (Data.Patch.IntMap.PatchIntMap a1 Data.Type.Equality.~ t) => Control.Lens.Wrapped.Rewrapped (Data.Patch.IntMap.PatchIntMap a2) t instance Control.Lens.Wrapped.Wrapped (Data.Patch.IntMap.PatchIntMap a) instance Data.Patch.Class.Patch (Data.Patch.IntMap.PatchIntMap a) instance Control.Lens.Indexed.FunctorWithIndex GHC.Types.Int Data.Patch.IntMap.PatchIntMap instance Control.Lens.Indexed.FoldableWithIndex GHC.Types.Int Data.Patch.IntMap.PatchIntMap instance Control.Lens.Indexed.TraversableWithIndex GHC.Types.Int Data.Patch.IntMap.PatchIntMap instance Data.Monoid.DecidablyEmpty.DecidablyEmpty (Data.Patch.IntMap.PatchIntMap a) instance GHC.Base.Monoid (Data.Patch.IntMap.PatchIntMap a) instance Data.Traversable.Traversable Data.Patch.IntMap.PatchIntMap instance Data.Foldable.Foldable Data.Patch.IntMap.PatchIntMap instance GHC.Base.Functor Data.Patch.IntMap.PatchIntMap instance GHC.Classes.Ord a => GHC.Classes.Ord (Data.Patch.IntMap.PatchIntMap a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.Patch.IntMap.PatchIntMap a) instance GHC.Read.Read a => GHC.Read.Read (Data.Patch.IntMap.PatchIntMap a) instance GHC.Show.Show a => GHC.Show.Show (Data.Patch.IntMap.PatchIntMap a) instance GHC.Base.Semigroup (Data.Patch.IntMap.PatchIntMap v) -- | Patches on Map that consist only of insertions -- (including overwrites) and deletions module Data.Patch.Map -- | A set of changes to a Map. Any element may be inserted/updated -- or deleted. Insertions are represented as values wrapped in -- Just, while deletions are represented as Nothings newtype PatchMap k v PatchMap :: Map k (Maybe v) -> PatchMap k v [unPatchMap] :: PatchMap k v -> Map k (Maybe v) -- | Returns all the new elements that will be added to the Map patchMapNewElements :: PatchMap k v -> [v] -- | Returns all the new elements that will be added to the Map patchMapNewElementsMap :: PatchMap k v -> Map k v instance (Data.Patch.Map.PatchMap k1 v1 Data.Type.Equality.~ t) => Control.Lens.Wrapped.Rewrapped (Data.Patch.Map.PatchMap k2 v2) t instance Control.Lens.Wrapped.Wrapped (Data.Patch.Map.PatchMap k v) instance GHC.Classes.Ord k => Data.Monoid.DecidablyEmpty.DecidablyEmpty (Data.Patch.Map.PatchMap k v) instance Data.Traversable.Traversable (Data.Patch.Map.PatchMap k) instance Data.Foldable.Foldable (Data.Patch.Map.PatchMap k) instance (GHC.Classes.Ord k, GHC.Classes.Ord v) => GHC.Classes.Ord (Data.Patch.Map.PatchMap k v) instance (GHC.Classes.Eq k, GHC.Classes.Eq v) => GHC.Classes.Eq (Data.Patch.Map.PatchMap k v) instance (GHC.Classes.Ord k, GHC.Read.Read k, GHC.Read.Read v) => GHC.Read.Read (Data.Patch.Map.PatchMap k v) instance (GHC.Show.Show k, GHC.Show.Show v) => GHC.Show.Show (Data.Patch.Map.PatchMap k v) instance GHC.Base.Functor (Data.Patch.Map.PatchMap k) instance GHC.Classes.Ord k => GHC.Base.Monoid (Data.Patch.Map.PatchMap k v) instance GHC.Classes.Ord k => GHC.Base.Semigroup (Data.Patch.Map.PatchMap k v) instance GHC.Classes.Ord k => Data.Patch.Class.Patch (Data.Patch.Map.PatchMap k v) instance Control.Lens.Indexed.FunctorWithIndex k (Data.Patch.Map.PatchMap k) instance Control.Lens.Indexed.FoldableWithIndex k (Data.Patch.Map.PatchMap k) instance Control.Lens.Indexed.TraversableWithIndex k (Data.Patch.Map.PatchMap k) -- | Patches on DMap that consist only of insertions (or -- overwrites) and deletions. module Data.Patch.DMap -- | A set of changes to a DMap. Any element may be inserted/updated -- or deleted. Insertions are represented as ComposeMaybe -- (Just value), while deletions are represented as -- ComposeMaybe Nothing. newtype PatchDMap k v PatchDMap :: DMap k (ComposeMaybe v) -> PatchDMap k v [unPatchDMap] :: PatchDMap k v -> DMap k (ComposeMaybe v) -- | Map a function v a -> v' a over any inserts/updates in the -- given PatchDMap k v to produce a PatchDMap -- k v'. mapPatchDMap :: (forall a. v a -> v' a) -> PatchDMap k v -> PatchDMap k v' -- | Map an effectful function v a -> f (v' a) over any -- inserts/updates in the given PatchDMap k v to produce -- a PatchDMap k v'. traversePatchDMap :: Applicative f => (forall a. v a -> f (v' a)) -> PatchDMap k v -> f (PatchDMap k v') -- | Map an effectful function k a -> v a -> f (v' a) over -- any inserts/updates in the given PatchDMap k v to -- produce a PatchDMap k v'. traversePatchDMapWithKey :: Applicative m => (forall a. k a -> v a -> m (v' a)) -> PatchDMap k v -> m (PatchDMap k v') -- | Weaken a PatchDMap k v to a PatchMap (Some -- k) v' using a function v a -> v' to weaken each value -- contained in the patch. weakenPatchDMapWith :: (forall a. v a -> v') -> PatchDMap k v -> PatchMap (Some k) v' -- | Convert a weak PatchDMap (Const2 k a) v where -- the a is known by way of the Const2 into a -- PatchMap k v' using a rank 1 function v a -> -- v'. patchDMapToPatchMapWith :: (v a -> v') -> PatchDMap (Const2 k a) v -> PatchMap k v' -- | Convert a PatchMap k v into a PatchDMap -- (Const2 k a) v' using a function v -> v' a. const2PatchDMapWith :: forall k v v' a. (v -> v' a) -> PatchMap k v -> PatchDMap (Const2 k a) v' -- | Convert a PatchIntMap v into a PatchDMap -- (Const2 Int a) v' using a function v -> v' a. const2IntPatchDMapWith :: forall v f a. (v -> f a) -> PatchIntMap v -> PatchDMap (Const2 Key a) f -- | Get the values that will be replaced or deleted if the given patch is -- applied to the given DMap. getDeletions :: GCompare k => PatchDMap k v -> DMap k v' -> DMap k v' instance forall k1 (k2 :: k1 -> *) (v :: k1 -> *). Data.GADT.Internal.GCompare k2 => GHC.Base.Semigroup (Data.Patch.DMap.PatchDMap k2 v) instance forall k1 (k2 :: k1 -> *) (v :: k1 -> *). Data.GADT.Internal.GCompare k2 => GHC.Base.Monoid (Data.Patch.DMap.PatchDMap k2 v) instance forall k1 (k2 :: k1 -> *) (v :: k1 -> *). Data.GADT.Internal.GCompare k2 => Data.Monoid.DecidablyEmpty.DecidablyEmpty (Data.Patch.DMap.PatchDMap k2 v) instance forall k1 (k2 :: k1 -> *) (v :: k1 -> *). Data.GADT.Internal.GCompare k2 => Data.Patch.Class.Patch (Data.Patch.DMap.PatchDMap k2 v) -- | Patches on Map that can insert, delete, and move values -- from one key to another module Data.Patch.MapWithMove -- | Patch a Map with additions, deletions, and moves. Invariant: If key -- k1 is coming from From_Move k2, then key k2 -- should be going to Just k1, and vice versa. There should -- never be any unpaired From/To keys. newtype PatchMapWithMove k v PatchMapWithMove :: Map k (NodeInfo k v) -> PatchMapWithMove k v -- | Extract the internal representation of the PatchMapWithMove [unPatchMapWithMove] :: PatchMapWithMove k v -> Map k (NodeInfo k v) -- | Holds the information about each key: where its new value should come -- from, and where its old value should go to data NodeInfo k v NodeInfo :: !From k v -> !To k -> NodeInfo k v -- | Where do we get the new value for this key? [_nodeInfo_from] :: NodeInfo k v -> !From k v -- | If the old value is being kept (i.e. moved rather than deleted or -- replaced), where is it going? [_nodeInfo_to] :: NodeInfo k v -> !To k -- | Describe how a key's new value should be produced data From k v -- | Insert the given value here From_Insert :: v -> From k v -- | Delete the existing value, if any, from here From_Delete :: From k v -- | Move the value here from the given key From_Move :: !k -> From k v -- | Describe where a key's old value will go. If this is Just, that -- means the key's old value will be moved to the given other key; if it -- is Nothing, that means it will be deleted. type To = Maybe -- | Create a PatchMapWithMove, validating it patchMapWithMove :: Ord k => Map k (NodeInfo k v) -> Maybe (PatchMapWithMove k v) -- | Create a PatchMapWithMove that inserts everything in the given -- Map patchMapWithMoveInsertAll :: Map k v -> PatchMapWithMove k v -- | Make a PatchMapWithMove k v which has the effect of -- inserting or updating a value v to the given key k, -- like insert. insertMapKey :: k -> v -> PatchMapWithMove k v -- | Make a PatchMapWithMove k v which has the effect of -- moving the value from the first key k to the second key -- k, equivalent to: -- --
--   delete src (maybe map (insert dst) (Map.lookup src map))
--   
moveMapKey :: Ord k => k -> k -> PatchMapWithMove k v -- | Make a PatchMapWithMove k v which has the effect of -- swapping two keys in the mapping, equivalent to: -- --
--   let aMay = Map.lookup a map
--       bMay = Map.lookup b map
--   in maybe id (Map.insert a) (bMay mplus aMay)
--    . maybe id (Map.insert b) (aMay mplus bMay)
--    . Map.delete a . Map.delete b $ map
--   
swapMapKey :: Ord k => k -> k -> PatchMapWithMove k v -- | Make a PatchMapWithMove k v which has the effect of -- deleting a key in the mapping, equivalent to delete. deleteMapKey :: k -> PatchMapWithMove k v -- | Wrap a Map k (NodeInfo k v) representing patch changes -- into a PatchMapWithMove k v, without checking any -- invariants. -- -- Warning: when using this function, you must ensure that the -- invariants of PatchMapWithMove are preserved; they will not be -- checked. unsafePatchMapWithMove :: Map k (NodeInfo k v) -> PatchMapWithMove k v -- | Returns all the new elements that will be added to the Map. patchMapWithMoveNewElements :: PatchMapWithMove k v -> [v] -- | Return a Map k v with all the inserts/updates from the -- given PatchMapWithMove k v. patchMapWithMoveNewElementsMap :: PatchMapWithMove k v -> Map k v -- | Create a PatchMapWithMove that, if applied to the given -- Map, will sort its values using the given ordering function. -- The set keys of the Map is not changed. patchThatSortsMapWith :: Ord k => (v -> v -> Ordering) -> Map k v -> PatchMapWithMove k v -- | Create a PatchMapWithMove that, if applied to the first -- Map provided, will produce a Map with the same values as -- the second Map but with the values sorted with the given -- ordering function. patchThatChangesAndSortsMapWith :: forall k v. (Ord k, Ord v) => (v -> v -> Ordering) -> Map k v -> Map k v -> PatchMapWithMove k v -- | Create a PatchMapWithMove that, if applied to the first -- Map provided, will produce the second Map. patchThatChangesMap :: (Ord k, Ord v) => Map k v -> Map k v -> PatchMapWithMove k v -- | Change the From value of a NodeInfo nodeInfoMapFrom :: (From k v -> From k v) -> NodeInfo k v -> NodeInfo k v -- | Change the From value of a NodeInfo, using a -- Functor (or Applicative, Monad, etc.) action to -- get the new value nodeInfoMapMFrom :: Functor f => (From k v -> f (From k v)) -> NodeInfo k v -> f (NodeInfo k v) -- | Set the To field of a NodeInfo nodeInfoSetTo :: To k -> NodeInfo k v -> NodeInfo k v -- | Helper data structure used for composing patches using the monoid -- instance. data Fixup k v Fixup_Delete :: Fixup k v Fixup_Update :: These (From k v) (To k) -> Fixup k v instance GHC.Classes.Ord k => GHC.Base.Semigroup (Data.Patch.MapWithMove.PatchMapWithMove k v) instance (Data.Patch.MapWithMove.PatchMapWithMove k1 v1 Data.Type.Equality.~ t) => Control.Lens.Wrapped.Rewrapped (Data.Patch.MapWithMove.PatchMapWithMove k2 v2) t instance Control.Lens.Wrapped.Wrapped (Data.Patch.MapWithMove.PatchMapWithMove k v) instance Control.Lens.Indexed.FunctorWithIndex k (Data.Patch.MapWithMove.PatchMapWithMove k) instance Control.Lens.Indexed.FoldableWithIndex k (Data.Patch.MapWithMove.PatchMapWithMove k) instance Control.Lens.Indexed.TraversableWithIndex k (Data.Patch.MapWithMove.PatchMapWithMove k) instance GHC.Classes.Ord k => Data.Patch.Class.Patch (Data.Patch.MapWithMove.PatchMapWithMove k v) instance GHC.Classes.Ord k => GHC.Base.Monoid (Data.Patch.MapWithMove.PatchMapWithMove k v) instance Data.Traversable.Traversable (Data.Patch.MapWithMove.PatchMapWithMove k) instance Data.Foldable.Foldable (Data.Patch.MapWithMove.PatchMapWithMove k) instance GHC.Base.Functor (Data.Patch.MapWithMove.PatchMapWithMove k) instance (GHC.Classes.Ord k, GHC.Classes.Ord v) => GHC.Classes.Ord (Data.Patch.MapWithMove.PatchMapWithMove k v) instance (GHC.Classes.Eq k, GHC.Classes.Eq v) => GHC.Classes.Eq (Data.Patch.MapWithMove.PatchMapWithMove k v) instance (GHC.Classes.Ord k, GHC.Read.Read k, GHC.Read.Read v) => GHC.Read.Read (Data.Patch.MapWithMove.PatchMapWithMove k v) instance (GHC.Show.Show k, GHC.Show.Show v) => GHC.Show.Show (Data.Patch.MapWithMove.PatchMapWithMove k v) instance Data.Traversable.Traversable (Data.Patch.MapWithMove.NodeInfo k) instance Data.Foldable.Foldable (Data.Patch.MapWithMove.NodeInfo k) instance GHC.Base.Functor (Data.Patch.MapWithMove.NodeInfo k) instance (GHC.Classes.Ord v, GHC.Classes.Ord k) => GHC.Classes.Ord (Data.Patch.MapWithMove.NodeInfo k v) instance (GHC.Classes.Eq v, GHC.Classes.Eq k) => GHC.Classes.Eq (Data.Patch.MapWithMove.NodeInfo k v) instance (GHC.Read.Read v, GHC.Read.Read k) => GHC.Read.Read (Data.Patch.MapWithMove.NodeInfo k v) instance (GHC.Show.Show v, GHC.Show.Show k) => GHC.Show.Show (Data.Patch.MapWithMove.NodeInfo k v) instance Data.Traversable.Traversable (Data.Patch.MapWithMove.From k) instance Data.Foldable.Foldable (Data.Patch.MapWithMove.From k) instance GHC.Base.Functor (Data.Patch.MapWithMove.From k) instance (GHC.Classes.Ord v, GHC.Classes.Ord k) => GHC.Classes.Ord (Data.Patch.MapWithMove.From k v) instance (GHC.Classes.Eq v, GHC.Classes.Eq k) => GHC.Classes.Eq (Data.Patch.MapWithMove.From k v) instance (GHC.Read.Read v, GHC.Read.Read k) => GHC.Read.Read (Data.Patch.MapWithMove.From k v) instance (GHC.Show.Show v, GHC.Show.Show k) => GHC.Show.Show (Data.Patch.MapWithMove.From k v) -- | Module containing PatchDMapWithMove k v and associated -- functions, which represents a Patch to a DMap k -- v which can insert, update, delete, and move values between keys. module Data.Patch.DMapWithMove -- | 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 destinations. -- -- Invariants: -- -- newtype PatchDMapWithMove k v PatchDMapWithMove :: DMap k (NodeInfo k v) -> PatchDMapWithMove k v -- | Structure which represents what changes apply to a particular key. -- _nodeInfo_from specifies what happens to this key, and in -- particular what other key the current key is moving from, while -- _nodeInfo_to specifies what key the current key is moving to -- if involved in a move. data NodeInfo k v a NodeInfo :: !From k v a -> !To k a -> NodeInfo k v a -- | Change applying to the current key, be it an insert, move, or delete. [_nodeInfo_from] :: NodeInfo k v a -> !From k v a -- | Where this key is moving to, if involved in a move. Should only be -- ComposeMaybe (Just k) when there is a corresponding -- From_Move. [_nodeInfo_to] :: NodeInfo k v a -> !To k a -- | 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 key (From_Delete), -- or moving a key (From_Move). data From (k :: a -> *) (v :: a -> *) :: a -> * -- | Insert a new or update an existing key with the given value v -- a [From_Insert] :: v a -> From k v a -- | Delete the existing key [From_Delete] :: From k v a -- | 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, usually but not necessarily with -- From_Delete. [From_Move] :: !k a -> From k v a -- | 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 operation. type To = ComposeMaybe -- | Test whether a PatchDMapWithMove satisfies its invariants. validPatchDMapWithMove :: forall k v. (GCompare k, GShow k) => DMap k (NodeInfo k v) -> Bool -- | Enumerate what reasons a PatchDMapWithMove doesn't satisfy its -- invariants, returning [] if it's valid. validationErrorsForPatchDMapWithMove :: forall k v. (GCompare k, GShow k) => DMap k (NodeInfo k v) -> [String] -- | Higher kinded 2-tuple, identical to Data.Functor.Product from -- base ≥ 4.9 data Pair1 f g a Pair1 :: f a -> g a -> Pair1 f g a -- | Helper data structure used for composing patches using the monoid -- instance. data Fixup k v a Fixup_Delete :: Fixup k v a Fixup_Update :: These (From k v a) (To k a) -> Fixup k v a -- | Make a PatchDMapWithMove k v which has the effect of -- inserting or updating a value v a to the given key k -- a, like insert. insertDMapKey :: k a -> v a -> PatchDMapWithMove k v -- | 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: -- --
--   delete src (maybe dmap (insert dst) (DMap.lookup src dmap))
--   
moveDMapKey :: GCompare k => k a -> k a -> PatchDMapWithMove k v -- | Make a PatchDMapWithMove k v which has the effect of -- swapping two keys in the mapping, equivalent to: -- --
--   let aMay = DMap.lookup a dmap
--       bMay = DMap.lookup b dmap
--   in maybe id (DMap.insert a) (bMay mplus aMay)
--    . maybe id (DMap.insert b) (aMay mplus bMay)
--    . DMap.delete a . DMap.delete b $ dmap
--   
swapDMapKey :: GCompare k => k a -> k a -> PatchDMapWithMove k v -- | Make a PatchDMapWithMove k v which has the effect of -- deleting a key in the mapping, equivalent to delete. deleteDMapKey :: k a -> PatchDMapWithMove k v -- | Extract the DMap representing the patch changes from the -- PatchDMapWithMove. unPatchDMapWithMove :: PatchDMapWithMove k v -> DMap k (NodeInfo k v) -- | Wrap a DMap representing patch changes into a -- PatchDMapWithMove, without checking any invariants. -- -- Warning: when using this function, you must ensure that the -- invariants of PatchDMapWithMove are preserved; they will not be -- checked. unsafePatchDMapWithMove :: DMap k (NodeInfo k v) -> PatchDMapWithMove k v -- | Wrap a DMap representing patch changes into a -- PatchDMapWithMove while checking invariants. If the invariants -- are satisfied, Right p is returned otherwise Left -- errors. patchDMapWithMove :: (GCompare k, GShow k) => DMap k (NodeInfo k v) -> Either [String] (PatchDMapWithMove k v) -- | Map a natural transform v -> v' over the given patch, -- transforming PatchDMapWithMove k v into -- PatchDMapWithMove k v'. mapPatchDMapWithMove :: forall k v v'. (forall a. v a -> v' a) -> PatchDMapWithMove k v -> PatchDMapWithMove k v' -- | 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 :: forall m k v v'. Applicative m => (forall a. v a -> m (v' a)) -> PatchDMapWithMove k v -> m (PatchDMapWithMove k v') -- | 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'). traversePatchDMapWithMoveWithKey :: forall m k v v'. Applicative m => (forall a. k a -> v a -> m (v' a)) -> PatchDMapWithMove k v -> m (PatchDMapWithMove k v') -- | Map a function which transforms From k v a into a -- From k v' a over a NodeInfo k v a. nodeInfoMapFrom :: (From k v a -> From k v' a) -> NodeInfo k v a -> NodeInfo k v' a -- | Map an effectful function which transforms From k v a -- into a f (From k v' a) over a NodeInfo k v -- a. nodeInfoMapFromM :: Functor f => (From k v a -> f (From k v' a)) -> NodeInfo k v a -> f (NodeInfo k v' a) -- | 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 values. weakenPatchDMapWithMoveWith :: forall k v v'. (forall a. v a -> v') -> PatchDMapWithMove k v -> PatchMapWithMove (Some k) v' -- | Weaken a PatchDMapWithMove (Const2 k a) v to a -- PatchMapWithMove k v'. Weaken is in scare quotes -- because the Const2 has already disabled any dependency in the -- typing and all points are already a, hence the function to -- map each value to v' is not higher rank. patchDMapWithMoveToPatchMapWithMoveWith :: forall k v v' a. (v a -> v') -> PatchDMapWithMove (Const2 k a) v -> PatchMapWithMove k v' -- | Strengthen a PatchMapWithMove k v into a -- 'PatchDMapWithMove (Const2 k a); that is, turn a -- non-dependently-typed patch into a dependently typed one but which -- always has a constant key type represented by Const2. Apply the -- given function to each v to produce a v' a. -- Completemented by patchDMapWithMoveToPatchMapWithMoveWith const2PatchDMapWithMoveWith :: forall k v v' a. (v -> v' a) -> PatchMapWithMove k v -> PatchDMapWithMove (Const2 k a) v' -- | Get the values that will be replaced, deleted, or moved if the given -- patch is applied to the given DMap. getDeletionsAndMoves :: GCompare k => PatchDMapWithMove k v -> DMap k v' -> DMap k (Product v' (ComposeMaybe k)) instance forall k1 (k2 :: k1 -> *) (v :: k1 -> *) (a :: k1). (GHC.Show.Show (v a), GHC.Show.Show (k2 a)) => GHC.Show.Show (Data.Patch.DMapWithMove.NodeInfo k2 v a) instance forall a (k :: a -> *) (v :: a -> *) (b :: a). (GHC.Classes.Ord (v b), GHC.Classes.Ord (k b)) => GHC.Classes.Ord (Data.Patch.DMapWithMove.From k v b) instance forall a (k :: a -> *) (v :: a -> *) (b :: a). (GHC.Classes.Eq (v b), GHC.Classes.Eq (k b)) => GHC.Classes.Eq (Data.Patch.DMapWithMove.From k v b) instance forall a (k :: a -> *) (v :: a -> *) (b :: a). (GHC.Read.Read (v b), GHC.Read.Read (k b)) => GHC.Read.Read (Data.Patch.DMapWithMove.From k v b) instance forall a (k :: a -> *) (v :: a -> *) (b :: a). (GHC.Show.Show (v b), GHC.Show.Show (k b)) => GHC.Show.Show (Data.Patch.DMapWithMove.From k v b) instance forall k1 (k2 :: k1 -> *) (v :: k1 -> *). Data.GADT.Internal.GCompare k2 => GHC.Base.Semigroup (Data.Patch.DMapWithMove.PatchDMapWithMove k2 v) instance forall k1 (k2 :: k1 -> *) (v :: k1 -> *). Data.GADT.Internal.GCompare k2 => Data.Monoid.DecidablyEmpty.DecidablyEmpty (Data.Patch.DMapWithMove.PatchDMapWithMove k2 v) instance forall k1 (k2 :: k1 -> *) (v :: k1 -> *). (Data.GADT.Internal.GEq k2, Data.Constraint.Extras.Has' GHC.Classes.Eq k2 (Data.Patch.DMapWithMove.NodeInfo k2 v)) => GHC.Classes.Eq (Data.Patch.DMapWithMove.PatchDMapWithMove k2 v) instance forall k1 (k2 :: k1 -> *) (v :: k1 -> *). Data.GADT.Internal.GCompare k2 => GHC.Base.Monoid (Data.Patch.DMapWithMove.PatchDMapWithMove k2 v) instance forall k1 (k2 :: k1 -> *) (v :: k1 -> *). Data.GADT.Internal.GCompare k2 => Data.Patch.Class.Patch (Data.Patch.DMapWithMove.PatchDMapWithMove k2 v) module Data.Patch -- | The elements of an Additive Semigroup can be considered -- as patches of their own type. newtype AdditivePatch p AdditivePatch :: p -> AdditivePatch p [unAdditivePatch] :: AdditivePatch p -> p -- | An Additive Semigroup is one where (<>) is -- commutative class Semigroup q => Additive q -- | A Group is a Monoid where every element has an inverse. class (Semigroup q, Monoid q) => Group q negateG :: Group q => q -> q (~~) :: Group q => q -> q -> q -- | A Patch type represents a kind of change made to a -- datastructure. -- -- If an instance of Patch is also an instance of -- Semigroup, it should obey the law that applyAlways (f -- <> g) == applyAlways f . applyAlways g. class Patch p where { type family PatchTarget p :: *; } -- | Apply the patch p a to the value a. If no change is -- needed, return Nothing. apply :: Patch p => p -> PatchTarget p -> Maybe (PatchTarget p) -- | Apply a Patch; if it does nothing, return the original value applyAlways :: Patch p => p -> PatchTarget p -> PatchTarget p -- | Like '(.)', but composes functions that return patches rather than -- functions that return new values. The Semigroup instance for patches -- must apply patches right-to-left, like '(.)'. composePatchFunctions :: (Patch p, Semigroup p) => (PatchTarget p -> p) -> (PatchTarget p -> p) -> PatchTarget p -> p -- | Patch for IntMap which represents insertion or deletion -- of keys in the mapping. Internally represented by 'IntMap (Maybe a)', -- where Just means insert/update and Nothing means -- delete. newtype PatchIntMap a PatchIntMap :: IntMap (Maybe a) -> PatchIntMap a [unPatchIntMap] :: PatchIntMap a -> IntMap (Maybe a) -- | Map a function Int -> a -> b over all as in -- the given PatchIntMap a (that is, all -- inserts/updates), producing a PatchIntMap b. mapIntMapPatchWithKey :: (Int -> a -> b) -> PatchIntMap a -> PatchIntMap b -- | Map an effectful function Int -> a -> f b over all -- as in the given PatchIntMap a (that is, all -- inserts/updates), producing a f (PatchIntMap b). traverseIntMapPatchWithKey :: Applicative f => (Int -> a -> f b) -> PatchIntMap a -> f (PatchIntMap b) -- | Extract all as inserted/updated by the given -- PatchIntMap a. patchIntMapNewElements :: PatchIntMap a -> [a] -- | Convert the given PatchIntMap a into an -- IntMap a with all the inserts/updates in the given -- patch. patchIntMapNewElementsMap :: PatchIntMap a -> IntMap a -- | A set of changes to a Map. Any element may be inserted/updated -- or deleted. Insertions are represented as values wrapped in -- Just, while deletions are represented as Nothings newtype PatchMap k v PatchMap :: Map k (Maybe v) -> PatchMap k v [unPatchMap] :: PatchMap k v -> Map k (Maybe v) -- | Returns all the new elements that will be added to the Map patchMapNewElements :: PatchMap k v -> [v] -- | Returns all the new elements that will be added to the Map patchMapNewElementsMap :: PatchMap k v -> Map k v -- | A set of changes to a DMap. Any element may be inserted/updated -- or deleted. Insertions are represented as ComposeMaybe -- (Just value), while deletions are represented as -- ComposeMaybe Nothing. newtype PatchDMap k v PatchDMap :: DMap k (ComposeMaybe v) -> PatchDMap k v [unPatchDMap] :: PatchDMap k v -> DMap k (ComposeMaybe v) -- | Map a function v a -> v' a over any inserts/updates in the -- given PatchDMap k v to produce a PatchDMap -- k v'. mapPatchDMap :: (forall a. v a -> v' a) -> PatchDMap k v -> PatchDMap k v' -- | Map an effectful function v a -> f (v' a) over any -- inserts/updates in the given PatchDMap k v to produce -- a PatchDMap k v'. traversePatchDMap :: Applicative f => (forall a. v a -> f (v' a)) -> PatchDMap k v -> f (PatchDMap k v') -- | Map an effectful function k a -> v a -> f (v' a) over -- any inserts/updates in the given PatchDMap k v to -- produce a PatchDMap k v'. traversePatchDMapWithKey :: Applicative m => (forall a. k a -> v a -> m (v' a)) -> PatchDMap k v -> m (PatchDMap k v') -- | Weaken a PatchDMap k v to a PatchMap (Some -- k) v' using a function v a -> v' to weaken each value -- contained in the patch. weakenPatchDMapWith :: (forall a. v a -> v') -> PatchDMap k v -> PatchMap (Some k) v' -- | Convert a weak PatchDMap (Const2 k a) v where -- the a is known by way of the Const2 into a -- PatchMap k v' using a rank 1 function v a -> -- v'. patchDMapToPatchMapWith :: (v a -> v') -> PatchDMap (Const2 k a) v -> PatchMap k v' -- | Convert a PatchMap k v into a PatchDMap -- (Const2 k a) v' using a function v -> v' a. const2PatchDMapWith :: forall k v v' a. (v -> v' a) -> PatchMap k v -> PatchDMap (Const2 k a) v' -- | Convert a PatchIntMap v into a PatchDMap -- (Const2 Int a) v' using a function v -> v' a. const2IntPatchDMapWith :: forall v f a. (v -> f a) -> PatchIntMap v -> PatchDMap (Const2 Key a) f -- | Patch a Map with additions, deletions, and moves. Invariant: If key -- k1 is coming from From_Move k2, then key k2 -- should be going to Just k1, and vice versa. There should -- never be any unpaired From/To keys. data PatchMapWithMove k v -- | Wrap a Map k (NodeInfo k v) representing patch changes -- into a PatchMapWithMove k v, without checking any -- invariants. -- -- Warning: when using this function, you must ensure that the -- invariants of PatchMapWithMove are preserved; they will not be -- checked. unsafePatchMapWithMove :: Map k (NodeInfo k v) -> PatchMapWithMove k v -- | Returns all the new elements that will be added to the Map. patchMapWithMoveNewElements :: PatchMapWithMove k v -> [v] -- | Return a Map k v with all the inserts/updates from the -- given PatchMapWithMove k v. patchMapWithMoveNewElementsMap :: PatchMapWithMove k v -> Map k v -- | 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 destinations. -- -- Invariants: -- -- data PatchDMapWithMove k v -- | Extract the DMap representing the patch changes from the -- PatchDMapWithMove. unPatchDMapWithMove :: PatchDMapWithMove k v -> DMap k (NodeInfo k v) -- | Wrap a DMap representing patch changes into a -- PatchDMapWithMove, without checking any invariants. -- -- Warning: when using this function, you must ensure that the -- invariants of PatchDMapWithMove are preserved; they will not be -- checked. unsafePatchDMapWithMove :: DMap k (NodeInfo k v) -> PatchDMapWithMove k v -- | Map a natural transform v -> v' over the given patch, -- transforming PatchDMapWithMove k v into -- PatchDMapWithMove k v'. mapPatchDMapWithMove :: forall k v v'. (forall a. v a -> v' a) -> PatchDMapWithMove k v -> PatchDMapWithMove k v' -- | 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'). traversePatchDMapWithMoveWithKey :: forall m k v v'. Applicative m => (forall a. k a -> v a -> m (v' a)) -> PatchDMapWithMove k v -> m (PatchDMapWithMove k v') -- | 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 values. weakenPatchDMapWithMoveWith :: forall k v v'. (forall a. v a -> v') -> PatchDMapWithMove k v -> PatchMapWithMove (Some k) v' -- | Weaken a PatchDMapWithMove (Const2 k a) v to a -- PatchMapWithMove k v'. Weaken is in scare quotes -- because the Const2 has already disabled any dependency in the -- typing and all points are already a, hence the function to -- map each value to v' is not higher rank. patchDMapWithMoveToPatchMapWithMoveWith :: forall k v v' a. (v a -> v') -> PatchDMapWithMove (Const2 k a) v -> PatchMapWithMove k v' -- | Strengthen a PatchMapWithMove k v into a -- 'PatchDMapWithMove (Const2 k a); that is, turn a -- non-dependently-typed patch into a dependently typed one but which -- always has a constant key type represented by Const2. Apply the -- given function to each v to produce a v' a. -- Completemented by patchDMapWithMoveToPatchMapWithMoveWith const2PatchDMapWithMoveWith :: forall k v v' a. (v -> v' a) -> PatchMapWithMove k v -> PatchDMapWithMove (Const2 k a) v' instance forall k a (x :: k). Data.Patch.Group a => Data.Patch.Group (Data.Functor.Const.Const a x) instance Data.Patch.Group a => Data.Patch.Group (Data.Functor.Identity.Identity a) instance Data.Patch.Additive p => Data.Patch.Class.Patch (Data.Patch.AdditivePatch p) instance (GHC.Classes.Ord k, Data.Patch.Additive q) => Data.Patch.Additive (Data.Map.Monoidal.MonoidalMap k q) instance Data.Patch.Additive () instance (Data.Patch.Additive a, Data.Patch.Additive b) => Data.Patch.Additive (a, b) instance forall k1 k2 (f :: k2 -> *) (g :: k1 -> k2) (a :: k1). Data.Patch.Additive (f (g a)) => Data.Patch.Additive ((GHC.Generics.:.:) f g a) instance forall k (f :: k -> *) (a :: k) (g :: k -> *). (Data.Patch.Additive (f a), Data.Patch.Additive (g a)) => Data.Patch.Additive ((GHC.Generics.:*:) f g a) instance forall k (x :: k). Data.Patch.Additive (Data.Proxy.Proxy x) instance forall k a (x :: k). Data.Patch.Additive a => Data.Patch.Additive (Data.Functor.Const.Const a x) instance Data.Patch.Additive a => Data.Patch.Additive (Data.Functor.Identity.Identity a) instance Data.Patch.Additive b => Data.Patch.Additive (a -> b) instance (GHC.Classes.Ord k, Data.Patch.Group q) => Data.Patch.Group (Data.Map.Monoidal.MonoidalMap k q) instance Data.Patch.Group () instance (Data.Patch.Group a, Data.Patch.Group b) => Data.Patch.Group (a, b) instance forall k1 k2 (f :: k2 -> *) (g :: k1 -> k2) (a :: k1). Data.Patch.Group (f (g a)) => Data.Patch.Group ((GHC.Generics.:.:) f g a) instance forall k (f :: k -> *) (a :: k) (g :: k -> *). (Data.Patch.Group (f a), Data.Patch.Group (g a)) => Data.Patch.Group ((GHC.Generics.:*:) f g a) instance forall k (x :: k). Data.Patch.Group (Data.Proxy.Proxy x) instance Data.Patch.Group b => Data.Patch.Group (a -> b) -- | Patches on Map that can insert, delete, and move values -- from one key to another module Data.Patch.MapWithPatchingMove -- | Patch a Map with additions, deletions, and moves. Invariant: If key -- k1 is coming from From_Move k2, then key k2 -- should be going to Just k1, and vice versa. There should -- never be any unpaired From/To keys. newtype PatchMapWithPatchingMove k p PatchMapWithPatchingMove :: Map k (NodeInfo k p) -> PatchMapWithPatchingMove k p -- | Extract the internal representation of the -- PatchMapWithPatchingMove [unPatchMapWithPatchingMove] :: PatchMapWithPatchingMove k p -> Map k (NodeInfo k p) -- | Holds the information about each key: where its new value should come -- from, and where its old value should go to data NodeInfo k p NodeInfo :: !From k p -> !To k -> NodeInfo k p -- | Where do we get the new value for this key? [_nodeInfo_from] :: NodeInfo k p -> !From k p -- | If the old value is being kept (i.e. moved rather than deleted or -- replaced), where is it going? [_nodeInfo_to] :: NodeInfo k p -> !To k bitraverseNodeInfo :: Applicative f => (k0 -> f k1) -> (p0 -> f p1) -> (PatchTarget p0 -> f (PatchTarget p1)) -> NodeInfo k0 p0 -> f (NodeInfo k1 p1) -- | Describe how a key's new value should be produced data From k p -- | Insert the given value here From_Insert :: PatchTarget p -> From k p -- | Delete the existing value, if any, from here From_Delete :: From k p -- | Move the value here from the given key, and apply the given patch From_Move :: !k -> !p -> From k p bitraverseFrom :: Applicative f => (k0 -> f k1) -> (p0 -> f p1) -> (PatchTarget p0 -> f (PatchTarget p1)) -> From k0 p0 -> f (From k1 p1) -- | Describe where a key's old value will go. If this is Just, that -- means the key's old value will be moved to the given other key; if it -- is Nothing, that means it will be deleted. type To = Maybe -- | Create a PatchMapWithPatchingMove, validating it patchMapWithPatchingMove :: Ord k => Map k (NodeInfo k p) -> Maybe (PatchMapWithPatchingMove k p) -- | Create a PatchMapWithPatchingMove that inserts everything in -- the given Map patchMapWithPatchingMoveInsertAll :: Map k (PatchTarget p) -> PatchMapWithPatchingMove k p -- | Make a PatchMapWithPatchingMove k p which has the -- effect of inserting or replacing a value v at the given key -- k, like insert. insertMapKey :: k -> PatchTarget p -> PatchMapWithPatchingMove k p -- | Make a PatchMapWithPatchingMove k p which has the -- effect of moving the value from the first key k to the second -- key k, equivalent to: -- --
--   delete src (maybe map (insert dst) (Map.lookup src map))
--   
moveMapKey :: (DecidablyEmpty p, Patch p) => Ord k => k -> k -> PatchMapWithPatchingMove k p -- | Make a PatchMapWithPatchingMove k p which has the -- effect of swapping two keys in the mapping, equivalent to: -- --
--   let aMay = Map.lookup a map
--       bMay = Map.lookup b map
--   in maybe id (Map.insert a) (bMay mplus aMay)
--    . maybe id (Map.insert b) (aMay mplus bMay)
--    . Map.delete a . Map.delete b $ map
--   
swapMapKey :: (DecidablyEmpty p, Patch p) => Ord k => k -> k -> PatchMapWithPatchingMove k p -- | Make a PatchMapWithPatchingMove k v which has the -- effect of deleting a key in the mapping, equivalent to delete. deleteMapKey :: k -> PatchMapWithPatchingMove k v -- | Wrap a Map k (NodeInfo k v) representing patch changes -- into a PatchMapWithPatchingMove k v, without checking -- any invariants. -- -- Warning: when using this function, you must ensure that the -- invariants of PatchMapWithPatchingMove are preserved; they will -- not be checked. unsafePatchMapWithPatchingMove :: Map k (NodeInfo k p) -> PatchMapWithPatchingMove k p -- | Returns all the new elements that will be added to the Map patchMapWithPatchingMoveNewElements :: PatchMapWithPatchingMove k p -> [PatchTarget p] -- | Return a Map k v with all the inserts/updates from the -- given PatchMapWithPatchingMove k v. patchMapWithPatchingMoveNewElementsMap :: PatchMapWithPatchingMove k p -> Map k (PatchTarget p) -- | Create a PatchMapWithPatchingMove that, if applied to the given -- Map, will sort its values using the given ordering function. -- The set keys of the Map is not changed. patchThatSortsMapWith :: (Ord k, Monoid p) => (PatchTarget p -> PatchTarget p -> Ordering) -> Map k (PatchTarget p) -> PatchMapWithPatchingMove k p -- | Create a PatchMapWithPatchingMove that, if applied to the first -- Map provided, will produce a Map with the same values as -- the second Map but with the values sorted with the given -- ordering function. patchThatChangesAndSortsMapWith :: forall k p. (Ord k, Ord (PatchTarget p), Monoid p) => (PatchTarget p -> PatchTarget p -> Ordering) -> Map k (PatchTarget p) -> Map k (PatchTarget p) -> PatchMapWithPatchingMove k p -- | Create a PatchMapWithPatchingMove that, if applied to the first -- Map provided, will produce the second Map. patchThatChangesMap :: (Ord k, Ord (PatchTarget p), Monoid p) => Map k (PatchTarget p) -> Map k (PatchTarget p) -> PatchMapWithPatchingMove k p -- | Change the From value of a NodeInfo nodeInfoMapFrom :: (From k v -> From k v) -> NodeInfo k v -> NodeInfo k v -- | Change the From value of a NodeInfo, using a -- Functor (or Applicative, Monad, etc.) action to -- get the new value nodeInfoMapMFrom :: Functor f => (From k v -> f (From k v)) -> NodeInfo k v -> f (NodeInfo k v) -- | Set the To field of a NodeInfo nodeInfoSetTo :: To k -> NodeInfo k v -> NodeInfo k v -- | Helper data structure used for composing patches using the monoid -- instance. data Fixup k v Fixup_Delete :: Fixup k v Fixup_Update :: These (From k v) (To k) -> Fixup k v instance (Data.Patch.MapWithPatchingMove.PatchMapWithPatchingMove k1 p1 Data.Type.Equality.~ t) => Control.Lens.Wrapped.Rewrapped (Data.Patch.MapWithPatchingMove.PatchMapWithPatchingMove k2 p2) t instance Control.Lens.Wrapped.Wrapped (Data.Patch.MapWithPatchingMove.PatchMapWithPatchingMove k p) instance (GHC.Show.Show k, GHC.Show.Show p, GHC.Show.Show (Data.Patch.Class.PatchTarget p)) => GHC.Show.Show (Data.Patch.MapWithPatchingMove.PatchMapWithPatchingMove k p) instance (GHC.Classes.Ord k, GHC.Read.Read k, GHC.Read.Read p, GHC.Read.Read (Data.Patch.Class.PatchTarget p)) => GHC.Read.Read (Data.Patch.MapWithPatchingMove.PatchMapWithPatchingMove k p) instance (GHC.Classes.Eq k, GHC.Classes.Eq p, GHC.Classes.Eq (Data.Patch.Class.PatchTarget p)) => GHC.Classes.Eq (Data.Patch.MapWithPatchingMove.PatchMapWithPatchingMove k p) instance (GHC.Classes.Ord k, GHC.Classes.Ord p, GHC.Classes.Ord (Data.Patch.Class.PatchTarget p)) => GHC.Classes.Ord (Data.Patch.MapWithPatchingMove.PatchMapWithPatchingMove k p) instance (GHC.Classes.Ord k, Data.Monoid.DecidablyEmpty.DecidablyEmpty p, Data.Patch.Class.Patch p) => Data.Monoid.DecidablyEmpty.DecidablyEmpty (Data.Patch.MapWithPatchingMove.PatchMapWithPatchingMove k p) instance (GHC.Show.Show k, GHC.Show.Show p, GHC.Show.Show (Data.Patch.Class.PatchTarget p)) => GHC.Show.Show (Data.Patch.MapWithPatchingMove.NodeInfo k p) instance (GHC.Read.Read k, GHC.Read.Read p, GHC.Read.Read (Data.Patch.Class.PatchTarget p)) => GHC.Read.Read (Data.Patch.MapWithPatchingMove.NodeInfo k p) instance (GHC.Classes.Eq k, GHC.Classes.Eq p, GHC.Classes.Eq (Data.Patch.Class.PatchTarget p)) => GHC.Classes.Eq (Data.Patch.MapWithPatchingMove.NodeInfo k p) instance (GHC.Classes.Ord k, GHC.Classes.Ord p, GHC.Classes.Ord (Data.Patch.Class.PatchTarget p)) => GHC.Classes.Ord (Data.Patch.MapWithPatchingMove.NodeInfo k p) instance (GHC.Show.Show k, GHC.Show.Show p, GHC.Show.Show (Data.Patch.Class.PatchTarget p)) => GHC.Show.Show (Data.Patch.MapWithPatchingMove.From k p) instance (GHC.Read.Read k, GHC.Read.Read p, GHC.Read.Read (Data.Patch.Class.PatchTarget p)) => GHC.Read.Read (Data.Patch.MapWithPatchingMove.From k p) instance (GHC.Classes.Eq k, GHC.Classes.Eq p, GHC.Classes.Eq (Data.Patch.Class.PatchTarget p)) => GHC.Classes.Eq (Data.Patch.MapWithPatchingMove.From k p) instance (GHC.Classes.Ord k, GHC.Classes.Ord p, GHC.Classes.Ord (Data.Patch.Class.PatchTarget p)) => GHC.Classes.Ord (Data.Patch.MapWithPatchingMove.From k p) instance (GHC.Classes.Ord k, Data.Monoid.DecidablyEmpty.DecidablyEmpty p, Data.Patch.Class.Patch p) => GHC.Base.Semigroup (Data.Patch.MapWithPatchingMove.PatchMapWithPatchingMove k p) instance (GHC.Classes.Ord k, Data.Patch.Class.Patch p) => Data.Patch.Class.Patch (Data.Patch.MapWithPatchingMove.PatchMapWithPatchingMove k p) instance (GHC.Classes.Ord k, Data.Monoid.DecidablyEmpty.DecidablyEmpty p, Data.Patch.Class.Patch p) => GHC.Base.Monoid (Data.Patch.MapWithPatchingMove.PatchMapWithPatchingMove k p)