-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Infrastructure for writing patches which act on other types. -- -- 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.0.1 -- | 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.Compare.GEq (Data.Functor.Misc.EitherTag l r) instance forall k (l :: k) (r :: k). Data.GADT.Compare.GCompare (Data.Functor.Misc.EitherTag l r) instance forall k (l :: k) (r :: k). Data.GADT.Show.GShow (Data.Functor.Misc.EitherTag l r) instance forall k (f :: k -> *) (g :: k -> *). Data.GADT.Compare.GEq f => Data.GADT.Compare.GEq (Data.Functor.Misc.WrapArg g f) instance forall k (f :: k -> *) (g :: k -> *). Data.GADT.Compare.GCompare f => Data.GADT.Compare.GCompare (Data.Functor.Misc.WrapArg g f) instance forall k1 k2 (v :: k1). GHC.Show.Show k2 => Data.GADT.Show.GShow (Data.Functor.Misc.Const2 k2 v) instance forall k1 k2 (v :: k1). GHC.Classes.Eq k2 => Data.GADT.Compare.GEq (Data.Functor.Misc.Const2 k2 v) instance forall k1 k2 (v :: k1). GHC.Classes.Ord k2 => Data.GADT.Compare.GCompare (Data.Functor.Misc.Const2 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) -- | 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 -- | 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 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 Data.Patch.Class.Patch (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 (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.Classes.Ord k => Data.Patch.Class.Patch (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 => GHC.Base.Monoid (Data.Patch.Map.PatchMap k v) instance GHC.Base.Functor (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.Compare.GCompare k2 => GHC.Base.Semigroup (Data.Patch.DMap.PatchDMap k2 v) instance forall k1 (k2 :: k1 -> *) (v :: k1 -> *). Data.GADT.Compare.GCompare k2 => GHC.Base.Monoid (Data.Patch.DMap.PatchDMap k2 v) instance forall k1 (k2 :: k1 -> *) (v :: k1 -> *). Data.GADT.Compare.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 DMap 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 -- | 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 -- | Extract the internal representation of the PatchMapWithMove unPatchMapWithMove :: PatchMapWithMove k v -> Map k (NodeInfo 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 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.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) instance GHC.Classes.Ord k => GHC.Base.Semigroup (Data.Patch.MapWithMove.PatchMapWithMove k v) 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) -- | 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: -- --
-- 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.Compare.GCompare k2 => GHC.Base.Semigroup (Data.Patch.DMapWithMove.PatchDMapWithMove k2 v) instance forall k1 (k2 :: k1 -> *) (v :: k1 -> *). (Data.GADT.Compare.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.Compare.GCompare k2 => GHC.Base.Monoid (Data.Patch.DMapWithMove.PatchDMapWithMove k2 v) instance forall k1 (k2 :: k1 -> *) (v :: k1 -> *). Data.GADT.Compare.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 -- | 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 DMap 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 -- | Extract the internal representation of the PatchMapWithMove unPatchMapWithMove :: PatchMapWithMove k v -> Map k (NodeInfo 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: -- --