    {-# LANGUAGE DeriveDataTypeable #-}

    -- | In some cases, 'Data' instances for abstract types are incorrect,
    --   and fail to work correctly with Uniplate. This module defines three helper
    --   types ('Hide', 'Trigger' and 'Invariant') to assist when writing instances
    --   for abstract types. The 'Hide' type is useful when you want to mark some part
    --   of your data type as being ignored by "Data.Generics.Uniplate.Data"
    --   (and any other 'Data' based generics libraries, such as @syb@).
    --
    --   Using the helper types, this module defines wrappers for types in
    --   the @containers@ package, namely 'Map', 'Set', 'IntMap' and 'IntSet'.
    --   The standard @containers@ 'Data' instances all treat the types as abstract,
    --   but the wrapper types allow you to traverse within the data types, ensuring
    --   the necessary invariants are maintained. In particular, if you do not modify
    --   the keys reconstruct will be /O(n)/ instead of /O(n log n)/.
    --
    --   As an example of how to implement your own abstract type wrappers, the 'Map' data
    --   type is defined as:
    --
    -- @
    --   newtype Map k v = Map ('Invariant' ('Trigger' [k], 'Trigger' [v], Hide (Map.Map k v)))
    --      deriving (Data, Typeable)
    -- @
    --
    --   The 'Map' type is defined as an 'Invariant' of three components - the keys, the values, and
    --   the underlying @Map@. We use 'Invariant' to ensure that the keys/values/map always remain in sync.
    --   We use 'Trigger' on the keys and values to ensure that whenever the keys or values change we
    --   rebuild the @Map@, but if they don't, we reuse the previous @Map@. The 'fromMap' function is
    --   implemented by pattern matching on the 'Map' type:
    --
    -- @
    --   'fromMap' ('Map' ('Invariant' _ (_,_,'Hide' x))) = x
    -- @
    --
    --   The 'toMap' function is slightly harder, as we need to come up with an invariant restoring function:
    --
    -- > toMap :: Ord k => Map.Map k v -> Map k v
    -- > toMap x = Map $ Invariant inv $ create x
    -- >     where
    -- >         create x = (Trigger False ks, Trigger False vs, Hide x)
    -- >             where (ks,vs) = unzip $ Map.toAscList x
    -- >
    -- >         inv (ks,vs,x)
    -- >             | trigger ks = create $ Map.fromList $ zip (fromTrigger ks) (fromTrigger vs)
    -- >             | trigger vs = create $ Map.fromDistinctAscList $ zip (fromTrigger ks) (fromTrigger vs)
    -- >             | otherwise = (ks,vs,x)
    --
    --   The 'create' function creates a value from a @Map@, getting the correct keys and values. The 'inv'
    --   function looks at the triggers on the keys/values. If the keys trigger has been tripped, then we
    --   reconstruct the @Map@ using @fromList@. If the values trigger has been tripped, but they keys trigger
    --   has not, we can use @fromDistinctAscList@, reducing the complexity of constructing the @Map@. If nothing
    --   has changed we can reuse the previous value.
    --
    --   The end result is that all Uniplate (or @syb@) traversals over 'Map' result in a valid value, which has
    --   had all appropriate transformations applied.
    module Data.Generics.Uniplate.Data.Instances(
        Hide(..), Trigger(..), Invariant(..),
        Map, fromMap, toMap,
        Set, fromSet, toSet,
        IntMap, fromIntMap, toIntMap,
        IntSet, fromIntSet, toIntSet
        ) where

    import Data.Data
    import qualified Data.Map as Map
    import qualified Data.Set as Set
    import qualified Data.IntMap as IntMap
    import qualified Data.IntSet as IntSet

    ---------------------------------------------------------------------
    -- DATA TYPES

    -- | The 'Hide' data type has a 'Data' instance which reports having no constructors,
    --   as though the type was defined as using the extension @EmptyDataDecls@:
    --
    -- > data Hide a
    --
    --   This type is suitable for defining regions that are avoided by Uniplate traversals.
    --   As an example:
    --
    -- > transformBi (+1) (1, 2, Hide 3, Just 4) == (2, 3, Hide 3, Just 4)
    --
    --   As a result of having no constructors, any calls to the methods 'toConstr' or 'gunfold'
    --   will raise an error.
    newtype Hide a = Hide {Hide a -> a
    fromHide :: a}
        deriving (ReadPrec [Hide a]
    ReadPrec (Hide a)
    Int -> ReadS (Hide a)
    ReadS [Hide a]
    (Int -> ReadS (Hide a))
    -> ReadS [Hide a]
    -> ReadPrec (Hide a)
    -> ReadPrec [Hide a]
    -> Read (Hide a)
    forall a. Read a => ReadPrec [Hide a]
    forall a. Read a => ReadPrec (Hide a)
    forall a. Read a => Int -> ReadS (Hide a)
    forall a. Read a => ReadS [Hide a]
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    readListPrec :: ReadPrec [Hide a]
    $creadListPrec :: forall a. Read a => ReadPrec [Hide a]
    readPrec :: ReadPrec (Hide a)
    $creadPrec :: forall a. Read a => ReadPrec (Hide a)
    readList :: ReadS [Hide a]
    $creadList :: forall a. Read a => ReadS [Hide a]
    readsPrec :: Int -> ReadS (Hide a)
    $creadsPrec :: forall a. Read a => Int -> ReadS (Hide a)
    Read,Eq (Hide a)
    Eq (Hide a) =>
    (Hide a -> Hide a -> Ordering)
    -> (Hide a -> Hide a -> Bool)
    -> (Hide a -> Hide a -> Bool)
    -> (Hide a -> Hide a -> Bool)
    -> (Hide a -> Hide a -> Bool)
    -> (Hide a -> Hide a -> Hide a)
    -> (Hide a -> Hide a -> Hide a)
    -> Ord (Hide a)
    Hide a -> Hide a -> Bool
    Hide a -> Hide a -> Ordering
    Hide a -> Hide a -> Hide a
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    forall a. Ord a => Eq (Hide a)
    forall a. Ord a => Hide a -> Hide a -> Bool
    forall a. Ord a => Hide a -> Hide a -> Ordering
    forall a. Ord a => Hide a -> Hide a -> Hide a
    min :: Hide a -> Hide a -> Hide a
    $cmin :: forall a. Ord a => Hide a -> Hide a -> Hide a
    max :: Hide a -> Hide a -> Hide a
    $cmax :: forall a. Ord a => Hide a -> Hide a -> Hide a
    >= :: Hide a -> Hide a -> Bool
    $c>= :: forall a. Ord a => Hide a -> Hide a -> Bool
    > :: Hide a -> Hide a -> Bool
    $c> :: forall a. Ord a => Hide a -> Hide a -> Bool
    <= :: Hide a -> Hide a -> Bool
    $c<= :: forall a. Ord a => Hide a -> Hide a -> Bool
    < :: Hide a -> Hide a -> Bool
    $c< :: forall a. Ord a => Hide a -> Hide a -> Bool
    compare :: Hide a -> Hide a -> Ordering
    $ccompare :: forall a. Ord a => Hide a -> Hide a -> Ordering
    $cp1Ord :: forall a. Ord a => Eq (Hide a)
    Ord,Hide a -> Hide a -> Bool
    (Hide a -> Hide a -> Bool)
    -> (Hide a -> Hide a -> Bool) -> Eq (Hide a)
    forall a. Eq a => Hide a -> Hide a -> Bool
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    /= :: Hide a -> Hide a -> Bool
    $c/= :: forall a. Eq a => Hide a -> Hide a -> Bool
    == :: Hide a -> Hide a -> Bool
    $c== :: forall a. Eq a => Hide a -> Hide a -> Bool
    Eq,Typeable)

    instance Show a => Show (Hide a) where
        show :: Hide a -> String
    show (Hide a :: a
    a) = "Hide " String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ a -> String
    forall a. Show a => a -> String
    show a
    a

    instance Functor Hide where
        fmap :: (a -> b) -> Hide a -> Hide b
    fmap f :: a -> b
    f (Hide x :: a
    x) = b -> Hide b
    forall a. a -> Hide a
    Hide (b -> Hide b) -> b -> Hide b
    forall a b. (a -> b) -> a -> b
    $ a -> b
    f a
    x

    instance Typeable a => Data (Hide a) where
        gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Hide a -> c (Hide a)
    gfoldl k :: forall d b. Data d => c (d -> b) -> d -> c b
    k z :: forall g. g -> c g
    z x :: Hide a
    x = Hide a -> c (Hide a)
    forall g. g -> c g
    z Hide a
    x
        gunfold :: (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Hide a)
    gunfold k :: forall b r. Data b => c (b -> r) -> c r
    k z :: forall r. r -> c r
    z c :: Constr
    c = String -> c (Hide a)
    forall a. HasCallStack => String -> a
    error "Data.Generics.Uniplate.Data.Instances.Hide: gunfold not implemented - data type has no constructors"
        toConstr :: Hide a -> Constr
    toConstr _ = String -> Constr
    forall a. HasCallStack => String -> a
    error "Data.Generics.Uniplate.Data.Instances.Hide: toConstr not implemented - data type has no constructors"
        dataTypeOf :: Hide a -> DataType
    dataTypeOf _ = DataType
    tyHide

    tyHide :: DataType
    tyHide = String -> [Constr] -> DataType
    mkDataType "Data.Generics.Uniplate.Data.Instances.Hide" []

    -- | The 'Trigger' data type has a 'Data' instance which reports as being defined:
    --
    -- > data Trigger a = Trigger a
    --
    --   However, whenever a 'gfoldl' or 'gunfold' constructs a new value, it will have the
    --   'trigger' field set to 'True'. The trigger information is useful to indicate whether
    --   any invariants have been broken, and thus need fixing. As an example:
    --
    -- > data SortedList a = SortedList (Trigger [a]) deriving (Data,Typeable)
    -- > toSortedList xs = SortedList $ Trigger False $ sort xs
    -- > fromSortedList (SortedList (Trigger t xs)) = if t then sort xs else xs
    --
    --   This data type represents a sorted list. When constructed the items are initially sorted,
    --   but operations such as 'gmapT' could break that invariant. The 'Trigger' type is used to
    --   detect when the Data operations have been performed, and resort the list.
    --
    --   The 'Trigger' type is often used in conjunction with 'Invariant', which fixes the invariants.
    data Trigger a = Trigger {Trigger a -> Bool
    trigger :: Bool, Trigger a -> a
    fromTrigger :: a}
        deriving (ReadPrec [Trigger a]
    ReadPrec (Trigger a)
    Int -> ReadS (Trigger a)
    ReadS [Trigger a]
    (Int -> ReadS (Trigger a))
    -> ReadS [Trigger a]
    -> ReadPrec (Trigger a)
    -> ReadPrec [Trigger a]
    -> Read (Trigger a)
    forall a. Read a => ReadPrec [Trigger a]
    forall a. Read a => ReadPrec (Trigger a)
    forall a. Read a => Int -> ReadS (Trigger a)
    forall a. Read a => ReadS [Trigger a]
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    readListPrec :: ReadPrec [Trigger a]
    $creadListPrec :: forall a. Read a => ReadPrec [Trigger a]
    readPrec :: ReadPrec (Trigger a)
    $creadPrec :: forall a. Read a => ReadPrec (Trigger a)
    readList :: ReadS [Trigger a]
    $creadList :: forall a. Read a => ReadS [Trigger a]
    readsPrec :: Int -> ReadS (Trigger a)
    $creadsPrec :: forall a. Read a => Int -> ReadS (Trigger a)
    Read,Eq (Trigger a)
    Eq (Trigger a) =>
    (Trigger a -> Trigger a -> Ordering)
    -> (Trigger a -> Trigger a -> Bool)
    -> (Trigger a -> Trigger a -> Bool)
    -> (Trigger a -> Trigger a -> Bool)
    -> (Trigger a -> Trigger a -> Bool)
    -> (Trigger a -> Trigger a -> Trigger a)
    -> (Trigger a -> Trigger a -> Trigger a)
    -> Ord (Trigger a)
    Trigger a -> Trigger a -> Bool
    Trigger a -> Trigger a -> Ordering
    Trigger a -> Trigger a -> Trigger a
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    forall a. Ord a => Eq (Trigger a)
    forall a. Ord a => Trigger a -> Trigger a -> Bool
    forall a. Ord a => Trigger a -> Trigger a -> Ordering
    forall a. Ord a => Trigger a -> Trigger a -> Trigger a
    min :: Trigger a -> Trigger a -> Trigger a
    $cmin :: forall a. Ord a => Trigger a -> Trigger a -> Trigger a
    max :: Trigger a -> Trigger a -> Trigger a
    $cmax :: forall a. Ord a => Trigger a -> Trigger a -> Trigger a
    >= :: Trigger a -> Trigger a -> Bool
    $c>= :: forall a. Ord a => Trigger a -> Trigger a -> Bool
    > :: Trigger a -> Trigger a -> Bool
    $c> :: forall a. Ord a => Trigger a -> Trigger a -> Bool
    <= :: Trigger a -> Trigger a -> Bool
    $c<= :: forall a. Ord a => Trigger a -> Trigger a -> Bool
    < :: Trigger a -> Trigger a -> Bool
    $c< :: forall a. Ord a => Trigger a -> Trigger a -> Bool
    compare :: Trigger a -> Trigger a -> Ordering
    $ccompare :: forall a. Ord a => Trigger a -> Trigger a -> Ordering
    $cp1Ord :: forall a. Ord a => Eq (Trigger a)
    Ord,Trigger a -> Trigger a -> Bool
    (Trigger a -> Trigger a -> Bool)
    -> (Trigger a -> Trigger a -> Bool) -> Eq (Trigger a)
    forall a. Eq a => Trigger a -> Trigger a -> Bool
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    /= :: Trigger a -> Trigger a -> Bool
    $c/= :: forall a. Eq a => Trigger a -> Trigger a -> Bool
    == :: Trigger a -> Trigger a -> Bool
    $c== :: forall a. Eq a => Trigger a -> Trigger a -> Bool
    Eq,Int -> Trigger a -> ShowS
    [Trigger a] -> ShowS
    Trigger a -> String
    (Int -> Trigger a -> ShowS)
    -> (Trigger a -> String)
    -> ([Trigger a] -> ShowS)
    -> Show (Trigger a)
    forall a. Show a => Int -> Trigger a -> ShowS
    forall a. Show a => [Trigger a] -> ShowS
    forall a. Show a => Trigger a -> String
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    showList :: [Trigger a] -> ShowS
    $cshowList :: forall a. Show a => [Trigger a] -> ShowS
    show :: Trigger a -> String
    $cshow :: forall a. Show a => Trigger a -> String
    showsPrec :: Int -> Trigger a -> ShowS
    $cshowsPrec :: forall a. Show a => Int -> Trigger a -> ShowS
    Show,Typeable)

    instance Functor Trigger where
        fmap :: (a -> b) -> Trigger a -> Trigger b
    fmap f :: a -> b
    f (Trigger a :: Bool
    a b :: a
    b) = Bool -> b -> Trigger b
    forall a. Bool -> a -> Trigger a
    Trigger Bool
    a (b -> Trigger b) -> b -> Trigger b
    forall a b. (a -> b) -> a -> b
    $ a -> b
    f a
    b

    instance (Data a, Typeable a) => Data (Trigger a) where
        gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Trigger a -> c (Trigger a)
    gfoldl k :: forall d b. Data d => c (d -> b) -> d -> c b
    k z :: forall g. g -> c g
    z (Trigger _ x :: a
    x) = (a -> Trigger a) -> c (a -> Trigger a)
    forall g. g -> c g
    z (Bool -> a -> Trigger a
    forall a. Bool -> a -> Trigger a
    Trigger Bool
    True) c (a -> Trigger a) -> a -> c (Trigger a)
    forall d b. Data d => c (d -> b) -> d -> c b
    `k` a
    x
        gunfold :: (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Trigger a)
    gunfold k :: forall b r. Data b => c (b -> r) -> c r
    k z :: forall r. r -> c r
    z c :: Constr
    c = c (a -> Trigger a) -> c (Trigger a)
    forall b r. Data b => c (b -> r) -> c r
    k (c (a -> Trigger a) -> c (Trigger a))
    -> c (a -> Trigger a) -> c (Trigger a)
    forall a b. (a -> b) -> a -> b
    $ (a -> Trigger a) -> c (a -> Trigger a)
    forall r. r -> c r
    z ((a -> Trigger a) -> c (a -> Trigger a))
    -> (a -> Trigger a) -> c (a -> Trigger a)
    forall a b. (a -> b) -> a -> b
    $ Bool -> a -> Trigger a
    forall a. Bool -> a -> Trigger a
    Trigger Bool
    True
        toConstr :: Trigger a -> Constr
    toConstr Trigger{} = Constr
    conTrigger
        dataTypeOf :: Trigger a -> DataType
    dataTypeOf _ = DataType
    tyTrigger

    conTrigger :: Constr
    conTrigger = DataType -> String -> [String] -> Fixity -> Constr
    mkConstr DataType
    tyTrigger "Trigger" [] Fixity
    Prefix
    tyTrigger :: DataType
    tyTrigger = String -> [Constr] -> DataType
    mkDataType "Data.Generics.Uniplate.Data.Instances.Trigger" [Constr
    conTrigger]

    -- | The 'Invariant' data type as a 'Data' instance which reports as being defined:
    --
    -- > data Invariant a = Invariant a
    --
    --   However, whenever a 'gfoldl' constructs a new value, it will have the function in
    --   the 'invariant' field applied to it. As an example:
    --
    -- > data SortedList a = SortedList (Invariant [a]) deriving (Data,Typeable)
    -- > toSortedList xs = SortedList $ Invariant sort (sort xs)
    -- > fromSortedList (SortedList (Invariant _ xs)) = xs
    --
    --   Any time an operation such as 'gmapT' is applied to the data type, the 'invariant' function
    --   is applied to the result. The @fromSortedList@ function can then rely on this invariant.
    --
    --   The 'gunfold' method is partially implemented - all constructed values will have an undefined
    --   value for all fields, regardless of which function is passed to 'fromConstrB'. If you only use
    --   'fromConstr' (as Uniplate does) then the 'gunfold' method is sufficient.
    data Invariant a = Invariant {Invariant a -> a -> a
    invariant :: a -> a, Invariant a -> a
    fromInvariant :: a}
        deriving Typeable

    instance Show a => Show (Invariant a) where
        show :: Invariant a -> String
    show (Invariant _ x :: a
    x) = "Invariant " String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ a -> String
    forall a. Show a => a -> String
    show a
    x

    instance (Data a, Typeable a) => Data (Invariant a) where
        gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Invariant a -> c (Invariant a)
    gfoldl k :: forall d b. Data d => c (d -> b) -> d -> c b
    k z :: forall g. g -> c g
    z (Invariant f :: a -> a
    f x :: a
    x) = (a -> Invariant a) -> c (a -> Invariant a)
    forall g. g -> c g
    z ((a -> a) -> a -> Invariant a
    forall a. (a -> a) -> a -> Invariant a
    Invariant a -> a
    f (a -> Invariant a) -> (a -> a) -> a -> Invariant a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> a
    f) c (a -> Invariant a) -> a -> c (Invariant a)
    forall d b. Data d => c (d -> b) -> d -> c b
    `k` a
    x
        gunfold :: (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Invariant a)
    gunfold k :: forall b r. Data b => c (b -> r) -> c r
    k z :: forall r. r -> c r
    z c :: Constr
    c = c (a -> Invariant a) -> c (Invariant a)
    forall b r. Data b => c (b -> r) -> c r
    k (c (a -> Invariant a) -> c (Invariant a))
    -> c (a -> Invariant a) -> c (Invariant a)
    forall a b. (a -> b) -> a -> b
    $ (a -> Invariant a) -> c (a -> Invariant a)
    forall r. r -> c r
    z ((a -> Invariant a) -> c (a -> Invariant a))
    -> (a -> Invariant a) -> c (a -> Invariant a)
    forall a b. (a -> b) -> a -> b
    $ \x :: a
    x -> (a -> a) -> a -> Invariant a
    forall a. (a -> a) -> a -> Invariant a
    Invariant (String -> a -> a
    forall a. HasCallStack => String -> a
    error String
    msg) (String -> a
    forall a. HasCallStack => String -> a
    error String
    msg a -> a -> a
    forall a. a -> a -> a
    `asTypeOf` a
    x)
            where msg :: String
    msg = "Data.Generics.Uniplate.Data.Instances.Invariant: gunfold only partially implemented"
        toConstr :: Invariant a -> Constr
    toConstr Invariant{} = Constr
    conInvariant
        dataTypeOf :: Invariant a -> DataType
    dataTypeOf _ = DataType
    tyInvariant

    conInvariant :: Constr
    conInvariant = DataType -> String -> [String] -> Fixity -> Constr
    mkConstr DataType
    tyInvariant "Invariant" [] Fixity
    Prefix
    tyInvariant :: DataType
    tyInvariant = String -> [Constr] -> DataType
    mkDataType "Data.Generics.Uniplate.Data.Instances.Invariant" [Constr
    conInvariant]

    ---------------------------------------------------------------------
    -- DATA TYPES

    -- | Invariant preserving version of @Map@ from the @containers@ packages, suitable for use with 'Uniplate'.
    --   Use 'toMap' to construct values, and 'fromMap' to deconstruct values.
    newtype Map k v = Map (Invariant (Trigger [k], Trigger [v], Hide (Map.Map k v)))
        deriving (Typeable (Map k v)
    DataType
    Constr
    Typeable (Map k v) =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> Map k v -> c (Map k v))
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c (Map k v))
    -> (Map k v -> Constr)
    -> (Map k v -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c (Map k v)))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Map k v)))
    -> ((forall b. Data b => b -> b) -> Map k v -> Map k v)
    -> (forall r r'.
        (r -> r' -> r)
        -> r -> (forall d. Data d => d -> r') -> Map k v -> r)
    -> (forall r r'.
        (r' -> r -> r)
        -> r -> (forall d. Data d => d -> r') -> Map k v -> r)
    -> (forall u. (forall d. Data d => d -> u) -> Map k v -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> Map k v -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> Map k v -> m (Map k v))
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> Map k v -> m (Map k v))
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> Map k v -> m (Map k v))
    -> Data (Map k v)
    Map k v -> DataType
    Map k v -> Constr
    (forall b. Data b => b -> b) -> Map k v -> Map k v
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Map k v -> c (Map k v)
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Map k v)
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Map k v))
    forall a.
    Typeable a =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> a -> c a)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c a)
    -> (a -> Constr)
    -> (a -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c a))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
    -> ((forall b. Data b => b -> b) -> a -> a)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall u. (forall d. Data d => d -> u) -> a -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> Data a
    forall u. Int -> (forall d. Data d => d -> u) -> Map k v -> u
    forall u. (forall d. Data d => d -> u) -> Map k v -> [u]
    forall k v. (Data k, Data v) => Typeable (Map k v)
    forall k v. (Data k, Data v) => Map k v -> DataType
    forall k v. (Data k, Data v) => Map k v -> Constr
    forall k v.
    (Data k, Data v) =>
    (forall b. Data b => b -> b) -> Map k v -> Map k v
    forall k v u.
    (Data k, Data v) =>
    Int -> (forall d. Data d => d -> u) -> Map k v -> u
    forall k v u.
    (Data k, Data v) =>
    (forall d. Data d => d -> u) -> Map k v -> [u]
    forall k v r r'.
    (Data k, Data v) =>
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Map k v -> r
    forall k v r r'.
    (Data k, Data v) =>
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Map k v -> r
    forall k v (m :: * -> *).
    (Data k, Data v, Monad m) =>
    (forall d. Data d => d -> m d) -> Map k v -> m (Map k v)
    forall k v (m :: * -> *).
    (Data k, Data v, MonadPlus m) =>
    (forall d. Data d => d -> m d) -> Map k v -> m (Map k v)
    forall k v (c :: * -> *).
    (Data k, Data v) =>
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Map k v)
    forall k v (c :: * -> *).
    (Data k, Data v) =>
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Map k v -> c (Map k v)
    forall k v (t :: * -> *) (c :: * -> *).
    (Data k, Data v, Typeable t) =>
    (forall d. Data d => c (t d)) -> Maybe (c (Map k v))
    forall k v (t :: * -> * -> *) (c :: * -> *).
    (Data k, Data v, Typeable t) =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Map k v))
    forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Map k v -> r
    forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Map k v -> r
    forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Map k v -> m (Map k v)
    forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Map k v -> m (Map k v)
    forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Map k v)
    forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Map k v -> c (Map k v)
    forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (Map k v))
    forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Map k v))
    $cMap :: Constr
    $tMap :: DataType
    gmapMo :: (forall d. Data d => d -> m d) -> Map k v -> m (Map k v)
    $cgmapMo :: forall k v (m :: * -> *).
    (Data k, Data v, MonadPlus m) =>
    (forall d. Data d => d -> m d) -> Map k v -> m (Map k v)
    gmapMp :: (forall d. Data d => d -> m d) -> Map k v -> m (Map k v)
    $cgmapMp :: forall k v (m :: * -> *).
    (Data k, Data v, MonadPlus m) =>
    (forall d. Data d => d -> m d) -> Map k v -> m (Map k v)
    gmapM :: (forall d. Data d => d -> m d) -> Map k v -> m (Map k v)
    $cgmapM :: forall k v (m :: * -> *).
    (Data k, Data v, Monad m) =>
    (forall d. Data d => d -> m d) -> Map k v -> m (Map k v)
    gmapQi :: Int -> (forall d. Data d => d -> u) -> Map k v -> u
    $cgmapQi :: forall k v u.
    (Data k, Data v) =>
    Int -> (forall d. Data d => d -> u) -> Map k v -> u
    gmapQ :: (forall d. Data d => d -> u) -> Map k v -> [u]
    $cgmapQ :: forall k v u.
    (Data k, Data v) =>
    (forall d. Data d => d -> u) -> Map k v -> [u]
    gmapQr :: (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Map k v -> r
    $cgmapQr :: forall k v r r'.
    (Data k, Data v) =>
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Map k v -> r
    gmapQl :: (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Map k v -> r
    $cgmapQl :: forall k v r r'.
    (Data k, Data v) =>
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Map k v -> r
    gmapT :: (forall b. Data b => b -> b) -> Map k v -> Map k v
    $cgmapT :: forall k v.
    (Data k, Data v) =>
    (forall b. Data b => b -> b) -> Map k v -> Map k v
    dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Map k v))
    $cdataCast2 :: forall k v (t :: * -> * -> *) (c :: * -> *).
    (Data k, Data v, Typeable t) =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Map k v))
    dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (Map k v))
    $cdataCast1 :: forall k v (t :: * -> *) (c :: * -> *).
    (Data k, Data v, Typeable t) =>
    (forall d. Data d => c (t d)) -> Maybe (c (Map k v))
    dataTypeOf :: Map k v -> DataType
    $cdataTypeOf :: forall k v. (Data k, Data v) => Map k v -> DataType
    toConstr :: Map k v -> Constr
    $ctoConstr :: forall k v. (Data k, Data v) => Map k v -> Constr
    gunfold :: (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Map k v)
    $cgunfold :: forall k v (c :: * -> *).
    (Data k, Data v) =>
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Map k v)
    gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Map k v -> c (Map k v)
    $cgfoldl :: forall k v (c :: * -> *).
    (Data k, Data v) =>
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Map k v -> c (Map k v)
    $cp1Data :: forall k v. (Data k, Data v) => Typeable (Map k v)
    Data, Typeable)

    instance (Show k, Show v) => Show (Map k v) where; show :: Map k v -> String
    show = Map k v -> String
    forall a. Show a => a -> String
    show (Map k v -> String) -> (Map k v -> Map k v) -> Map k v -> String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Map k v -> Map k v
    forall k v. Map k v -> Map k v
    fromMap
    instance (Eq k, Eq v) => Eq (Map k v) where; a :: Map k v
    a == :: Map k v -> Map k v -> Bool
    == b :: Map k v
    b = Map k v -> Map k v
    forall k v. Map k v -> Map k v
    fromMap Map k v
    a Map k v -> Map k v -> Bool
    forall a. Eq a => a -> a -> Bool
    == Map k v -> Map k v
    forall k v. Map k v -> Map k v
    fromMap Map k v
    b
    instance (Ord k, Ord v) => Ord (Map k v) where; compare :: Map k v -> Map k v -> Ordering
    compare a :: Map k v
    a b :: Map k v
    b = Map k v -> Map k v -> Ordering
    forall a. Ord a => a -> a -> Ordering
    compare (Map k v -> Map k v
    forall k v. Map k v -> Map k v
    fromMap Map k v
    a) (Map k v -> Map k v
    forall k v. Map k v -> Map k v
    fromMap Map k v
    b)

    -- | Deconstruct a value of type 'Map'.
    fromMap :: Map k v -> Map.Map k v
    fromMap :: Map k v -> Map k v
    fromMap (Map (Invariant _ (_,_,Hide x :: Map k v
    x))) = Map k v
    x

    -- | Construct a value of type 'Map'.
    toMap :: Ord k => Map.Map k v -> Map k v
    toMap :: Map k v -> Map k v
    toMap x :: Map k v
    x = Invariant (Trigger [k], Trigger [v], Hide (Map k v)) -> Map k v
    forall k v.
    Invariant (Trigger [k], Trigger [v], Hide (Map k v)) -> Map k v
    Map (Invariant (Trigger [k], Trigger [v], Hide (Map k v)) -> Map k v)
    -> Invariant (Trigger [k], Trigger [v], Hide (Map k v)) -> Map k v
    forall a b. (a -> b) -> a -> b
    $ ((Trigger [k], Trigger [v], Hide (Map k v))
     -> (Trigger [k], Trigger [v], Hide (Map k v)))
    -> (Trigger [k], Trigger [v], Hide (Map k v))
    -> Invariant (Trigger [k], Trigger [v], Hide (Map k v))
    forall a. (a -> a) -> a -> Invariant a
    Invariant (Trigger [k], Trigger [v], Hide (Map k v))
    -> (Trigger [k], Trigger [v], Hide (Map k v))
    forall a b.
    Ord a =>
    (Trigger [a], Trigger [b], Hide (Map a b))
    -> (Trigger [a], Trigger [b], Hide (Map a b))
    inv ((Trigger [k], Trigger [v], Hide (Map k v))
     -> Invariant (Trigger [k], Trigger [v], Hide (Map k v)))
    -> (Trigger [k], Trigger [v], Hide (Map k v))
    -> Invariant (Trigger [k], Trigger [v], Hide (Map k v))
    forall a b. (a -> b) -> a -> b
    $ Map k v -> (Trigger [k], Trigger [v], Hide (Map k v))
    forall a b. Map a b -> (Trigger [a], Trigger [b], Hide (Map a b))
    create Map k v
    x
        where
            create :: Map a b -> (Trigger [a], Trigger [b], Hide (Map a b))
    create x :: Map a b
    x = (Bool -> [a] -> Trigger [a]
    forall a. Bool -> a -> Trigger a
    Trigger Bool
    False [a]
    ks, Bool -> [b] -> Trigger [b]
    forall a. Bool -> a -> Trigger a
    Trigger Bool
    False [b]
    vs, Map a b -> Hide (Map a b)
    forall a. a -> Hide a
    Hide Map a b
    x)
                where (ks :: [a]
    ks,vs :: [b]
    vs) = [(a, b)] -> ([a], [b])
    forall a b. [(a, b)] -> ([a], [b])
    unzip ([(a, b)] -> ([a], [b])) -> [(a, b)] -> ([a], [b])
    forall a b. (a -> b) -> a -> b
    $ Map a b -> [(a, b)]
    forall k a. Map k a -> [(k, a)]
    Map.toAscList Map a b
    x

            inv :: (Trigger [a], Trigger [b], Hide (Map a b))
    -> (Trigger [a], Trigger [b], Hide (Map a b))
    inv (ks :: Trigger [a]
    ks,vs :: Trigger [b]
    vs,x :: Hide (Map a b)
    x)
                | Trigger [a] -> Bool
    forall a. Trigger a -> Bool
    trigger Trigger [a]
    ks = Map a b -> (Trigger [a], Trigger [b], Hide (Map a b))
    forall a b. Map a b -> (Trigger [a], Trigger [b], Hide (Map a b))
    create (Map a b -> (Trigger [a], Trigger [b], Hide (Map a b)))
    -> Map a b -> (Trigger [a], Trigger [b], Hide (Map a b))
    forall a b. (a -> b) -> a -> b
    $ [(a, b)] -> Map a b
    forall k a. Ord k => [(k, a)] -> Map k a
    Map.fromList ([(a, b)] -> Map a b) -> [(a, b)] -> Map a b
    forall a b. (a -> b) -> a -> b
    $ [a] -> [b] -> [(a, b)]
    forall a b. [a] -> [b] -> [(a, b)]
    zip (Trigger [a] -> [a]
    forall a. Trigger a -> a
    fromTrigger Trigger [a]
    ks) (Trigger [b] -> [b]
    forall a. Trigger a -> a
    fromTrigger Trigger [b]
    vs)
                | Trigger [b] -> Bool
    forall a. Trigger a -> Bool
    trigger Trigger [b]
    vs = Map a b -> (Trigger [a], Trigger [b], Hide (Map a b))
    forall a b. Map a b -> (Trigger [a], Trigger [b], Hide (Map a b))
    create (Map a b -> (Trigger [a], Trigger [b], Hide (Map a b)))
    -> Map a b -> (Trigger [a], Trigger [b], Hide (Map a b))
    forall a b. (a -> b) -> a -> b
    $ [(a, b)] -> Map a b
    forall k a. [(k, a)] -> Map k a
    Map.fromDistinctAscList ([(a, b)] -> Map a b) -> [(a, b)] -> Map a b
    forall a b. (a -> b) -> a -> b
    $ [a] -> [b] -> [(a, b)]
    forall a b. [a] -> [b] -> [(a, b)]
    zip (Trigger [a] -> [a]
    forall a. Trigger a -> a
    fromTrigger Trigger [a]
    ks) (Trigger [b] -> [b]
    forall a. Trigger a -> a
    fromTrigger Trigger [b]
    vs) -- recreate ks/vs to reduce memory usage
                | Bool
    otherwise = (Trigger [a]
    ks,Trigger [b]
    vs,Hide (Map a b)
    x)

    -- | Invariant preserving version of @Set@ from the @containers@ packages, suitable for use with 'Uniplate'.
    --   Use 'toSet' to construct values, and 'fromSet' to deconstruct values.
    newtype Set k = Set (Invariant (Trigger [k], Hide (Set.Set k)))
        deriving (Typeable (Set k)
    DataType
    Constr
    Typeable (Set k) =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> Set k -> c (Set k))
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c (Set k))
    -> (Set k -> Constr)
    -> (Set k -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c (Set k)))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Set k)))
    -> ((forall b. Data b => b -> b) -> Set k -> Set k)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Set k -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Set k -> r)
    -> (forall u. (forall d. Data d => d -> u) -> Set k -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> Set k -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> Set k -> m (Set k))
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> Set k -> m (Set k))
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> Set k -> m (Set k))
    -> Data (Set k)
    Set k -> DataType
    Set k -> Constr
    (forall d. Data d => c (t d)) -> Maybe (c (Set k))
    (forall b. Data b => b -> b) -> Set k -> Set k
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Set k -> c (Set k)
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Set k)
    forall k. Data k => Typeable (Set k)
    forall k. Data k => Set k -> DataType
    forall k. Data k => Set k -> Constr
    forall k. Data k => (forall b. Data b => b -> b) -> Set k -> Set k
    forall k u.
    Data k =>
    Int -> (forall d. Data d => d -> u) -> Set k -> u
    forall k u. Data k => (forall d. Data d => d -> u) -> Set k -> [u]
    forall k r r'.
    Data k =>
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Set k -> r
    forall k r r'.
    Data k =>
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Set k -> r
    forall k (m :: * -> *).
    (Data k, Monad m) =>
    (forall d. Data d => d -> m d) -> Set k -> m (Set k)
    forall k (m :: * -> *).
    (Data k, MonadPlus m) =>
    (forall d. Data d => d -> m d) -> Set k -> m (Set k)
    forall k (c :: * -> *).
    Data k =>
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Set k)
    forall k (c :: * -> *).
    Data k =>
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Set k -> c (Set k)
    forall k (t :: * -> *) (c :: * -> *).
    (Data k, Typeable t) =>
    (forall d. Data d => c (t d)) -> Maybe (c (Set k))
    forall k (t :: * -> * -> *) (c :: * -> *).
    (Data k, Typeable t) =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Set k))
    forall a.
    Typeable a =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> a -> c a)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c a)
    -> (a -> Constr)
    -> (a -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c a))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
    -> ((forall b. Data b => b -> b) -> a -> a)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall u. (forall d. Data d => d -> u) -> a -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> Data a
    forall u. Int -> (forall d. Data d => d -> u) -> Set k -> u
    forall u. (forall d. Data d => d -> u) -> Set k -> [u]
    forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Set k -> r
    forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Set k -> r
    forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Set k -> m (Set k)
    forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Set k -> m (Set k)
    forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Set k)
    forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Set k -> c (Set k)
    forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (Set k))
    forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Set k))
    $cSet :: Constr
    $tSet :: DataType
    gmapMo :: (forall d. Data d => d -> m d) -> Set k -> m (Set k)
    $cgmapMo :: forall k (m :: * -> *).
    (Data k, MonadPlus m) =>
    (forall d. Data d => d -> m d) -> Set k -> m (Set k)
    gmapMp :: (forall d. Data d => d -> m d) -> Set k -> m (Set k)
    $cgmapMp :: forall k (m :: * -> *).
    (Data k, MonadPlus m) =>
    (forall d. Data d => d -> m d) -> Set k -> m (Set k)
    gmapM :: (forall d. Data d => d -> m d) -> Set k -> m (Set k)
    $cgmapM :: forall k (m :: * -> *).
    (Data k, Monad m) =>
    (forall d. Data d => d -> m d) -> Set k -> m (Set k)
    gmapQi :: Int -> (forall d. Data d => d -> u) -> Set k -> u
    $cgmapQi :: forall k u.
    Data k =>
    Int -> (forall d. Data d => d -> u) -> Set k -> u
    gmapQ :: (forall d. Data d => d -> u) -> Set k -> [u]
    $cgmapQ :: forall k u. Data k => (forall d. Data d => d -> u) -> Set k -> [u]
    gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Set k -> r
    $cgmapQr :: forall k r r'.
    Data k =>
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Set k -> r
    gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Set k -> r
    $cgmapQl :: forall k r r'.
    Data k =>
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Set k -> r
    gmapT :: (forall b. Data b => b -> b) -> Set k -> Set k
    $cgmapT :: forall k. Data k => (forall b. Data b => b -> b) -> Set k -> Set k
    dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Set k))
    $cdataCast2 :: forall k (t :: * -> * -> *) (c :: * -> *).
    (Data k, Typeable t) =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Set k))
    dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (Set k))
    $cdataCast1 :: forall k (t :: * -> *) (c :: * -> *).
    (Data k, Typeable t) =>
    (forall d. Data d => c (t d)) -> Maybe (c (Set k))
    dataTypeOf :: Set k -> DataType
    $cdataTypeOf :: forall k. Data k => Set k -> DataType
    toConstr :: Set k -> Constr
    $ctoConstr :: forall k. Data k => Set k -> Constr
    gunfold :: (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Set k)
    $cgunfold :: forall k (c :: * -> *).
    Data k =>
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Set k)
    gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Set k -> c (Set k)
    $cgfoldl :: forall k (c :: * -> *).
    Data k =>
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Set k -> c (Set k)
    $cp1Data :: forall k. Data k => Typeable (Set k)
    Data, Typeable)

    instance Show k => Show (Set k) where; show :: Set k -> String
    show = Set k -> String
    forall a. Show a => a -> String
    show (Set k -> String) -> (Set k -> Set k) -> Set k -> String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Set k -> Set k
    forall k. Set k -> Set k
    fromSet
    instance Eq k => Eq (Set k) where; a :: Set k
    a == :: Set k -> Set k -> Bool
    == b :: Set k
    b = Set k -> Set k
    forall k. Set k -> Set k
    fromSet Set k
    a Set k -> Set k -> Bool
    forall a. Eq a => a -> a -> Bool
    == Set k -> Set k
    forall k. Set k -> Set k
    fromSet Set k
    b
    instance Ord k => Ord (Set k) where; compare :: Set k -> Set k -> Ordering
    compare a :: Set k
    a b :: Set k
    b = Set k -> Set k -> Ordering
    forall a. Ord a => a -> a -> Ordering
    compare (Set k -> Set k
    forall k. Set k -> Set k
    fromSet Set k
    a) (Set k -> Set k
    forall k. Set k -> Set k
    fromSet Set k
    b)

    -- | Deconstruct a value of type 'Set'.
    fromSet :: Set k -> Set.Set k
    fromSet :: Set k -> Set k
    fromSet (Set (Invariant _ (_,Hide x :: Set k
    x))) = Set k
    x

    -- | Construct a value of type 'Set'.
    toSet :: Ord k => Set.Set k -> Set k
    toSet :: Set k -> Set k
    toSet x :: Set k
    x = Invariant (Trigger [k], Hide (Set k)) -> Set k
    forall k. Invariant (Trigger [k], Hide (Set k)) -> Set k
    Set (Invariant (Trigger [k], Hide (Set k)) -> Set k)
    -> Invariant (Trigger [k], Hide (Set k)) -> Set k
    forall a b. (a -> b) -> a -> b
    $ ((Trigger [k], Hide (Set k)) -> (Trigger [k], Hide (Set k)))
    -> (Trigger [k], Hide (Set k))
    -> Invariant (Trigger [k], Hide (Set k))
    forall a. (a -> a) -> a -> Invariant a
    Invariant (Trigger [k], Hide (Set k)) -> (Trigger [k], Hide (Set k))
    forall a.
    Ord a =>
    (Trigger [a], Hide (Set a)) -> (Trigger [a], Hide (Set a))
    inv ((Trigger [k], Hide (Set k))
     -> Invariant (Trigger [k], Hide (Set k)))
    -> (Trigger [k], Hide (Set k))
    -> Invariant (Trigger [k], Hide (Set k))
    forall a b. (a -> b) -> a -> b
    $ Set k -> (Trigger [k], Hide (Set k))
    forall a. Set a -> (Trigger [a], Hide (Set a))
    create Set k
    x
        where
            create :: Set a -> (Trigger [a], Hide (Set a))
    create x :: Set a
    x = (Bool -> [a] -> Trigger [a]
    forall a. Bool -> a -> Trigger a
    Trigger Bool
    False ([a] -> Trigger [a]) -> [a] -> Trigger [a]
    forall a b. (a -> b) -> a -> b
    $ Set a -> [a]
    forall a. Set a -> [a]
    Set.toList Set a
    x, Set a -> Hide (Set a)
    forall a. a -> Hide a
    Hide Set a
    x)

            inv :: (Trigger [a], Hide (Set a)) -> (Trigger [a], Hide (Set a))
    inv (ks :: Trigger [a]
    ks,x :: Hide (Set a)
    x)
                | Trigger [a] -> Bool
    forall a. Trigger a -> Bool
    trigger Trigger [a]
    ks = Set a -> (Trigger [a], Hide (Set a))
    forall a. Set a -> (Trigger [a], Hide (Set a))
    create (Set a -> (Trigger [a], Hide (Set a)))
    -> Set a -> (Trigger [a], Hide (Set a))
    forall a b. (a -> b) -> a -> b
    $ [a] -> Set a
    forall a. Ord a => [a] -> Set a
    Set.fromList ([a] -> Set a) -> [a] -> Set a
    forall a b. (a -> b) -> a -> b
    $ Trigger [a] -> [a]
    forall a. Trigger a -> a
    fromTrigger Trigger [a]
    ks
                | Bool
    otherwise = (Trigger [a]
    ks,Hide (Set a)
    x)

    -- | Invariant preserving version of @IntMap@ from the @containers@ packages, suitable for use with 'Uniplate'.
    --   Use 'toIntMap' to construct values, and 'fromIntMap' to deconstruct values.
    newtype IntMap v = IntMap (Invariant (Trigger [Int], Trigger [v], Hide (IntMap.IntMap v)))
        deriving (Typeable (IntMap v)
    DataType
    Constr
    Typeable (IntMap v) =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> IntMap v -> c (IntMap v))
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c (IntMap v))
    -> (IntMap v -> Constr)
    -> (IntMap v -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c (IntMap v)))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e))
        -> Maybe (c (IntMap v)))
    -> ((forall b. Data b => b -> b) -> IntMap v -> IntMap v)
    -> (forall r r'.
        (r -> r' -> r)
        -> r -> (forall d. Data d => d -> r') -> IntMap v -> r)
    -> (forall r r'.
        (r' -> r -> r)
        -> r -> (forall d. Data d => d -> r') -> IntMap v -> r)
    -> (forall u. (forall d. Data d => d -> u) -> IntMap v -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> IntMap v -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> IntMap v -> m (IntMap v))
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> IntMap v -> m (IntMap v))
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> IntMap v -> m (IntMap v))
    -> Data (IntMap v)
    IntMap v -> DataType
    IntMap v -> Constr
    (forall d. Data d => c (t d)) -> Maybe (c (IntMap v))
    (forall b. Data b => b -> b) -> IntMap v -> IntMap v
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> IntMap v -> c (IntMap v)
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (IntMap v)
    forall v. Data v => Typeable (IntMap v)
    forall v. Data v => IntMap v -> DataType
    forall v. Data v => IntMap v -> Constr
    forall v.
    Data v =>
    (forall b. Data b => b -> b) -> IntMap v -> IntMap v
    forall v u.
    Data v =>
    Int -> (forall d. Data d => d -> u) -> IntMap v -> u
    forall v u.
    Data v =>
    (forall d. Data d => d -> u) -> IntMap v -> [u]
    forall v r r'.
    Data v =>
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> IntMap v -> r
    forall v r r'.
    Data v =>
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> IntMap v -> r
    forall v (m :: * -> *).
    (Data v, Monad m) =>
    (forall d. Data d => d -> m d) -> IntMap v -> m (IntMap v)
    forall v (m :: * -> *).
    (Data v, MonadPlus m) =>
    (forall d. Data d => d -> m d) -> IntMap v -> m (IntMap v)
    forall v (c :: * -> *).
    Data v =>
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (IntMap v)
    forall v (c :: * -> *).
    Data v =>
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> IntMap v -> c (IntMap v)
    forall v (t :: * -> *) (c :: * -> *).
    (Data v, Typeable t) =>
    (forall d. Data d => c (t d)) -> Maybe (c (IntMap v))
    forall v (t :: * -> * -> *) (c :: * -> *).
    (Data v, Typeable t) =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (IntMap v))
    forall a.
    Typeable a =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> a -> c a)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c a)
    -> (a -> Constr)
    -> (a -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c a))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
    -> ((forall b. Data b => b -> b) -> a -> a)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall u. (forall d. Data d => d -> u) -> a -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> Data a
    forall u. Int -> (forall d. Data d => d -> u) -> IntMap v -> u
    forall u. (forall d. Data d => d -> u) -> IntMap v -> [u]
    forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> IntMap v -> r
    forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> IntMap v -> r
    forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> IntMap v -> m (IntMap v)
    forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> IntMap v -> m (IntMap v)
    forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (IntMap v)
    forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> IntMap v -> c (IntMap v)
    forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (IntMap v))
    forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (IntMap v))
    $cIntMap :: Constr
    $tIntMap :: DataType
    gmapMo :: (forall d. Data d => d -> m d) -> IntMap v -> m (IntMap v)
    $cgmapMo :: forall v (m :: * -> *).
    (Data v, MonadPlus m) =>
    (forall d. Data d => d -> m d) -> IntMap v -> m (IntMap v)
    gmapMp :: (forall d. Data d => d -> m d) -> IntMap v -> m (IntMap v)
    $cgmapMp :: forall v (m :: * -> *).
    (Data v, MonadPlus m) =>
    (forall d. Data d => d -> m d) -> IntMap v -> m (IntMap v)
    gmapM :: (forall d. Data d => d -> m d) -> IntMap v -> m (IntMap v)
    $cgmapM :: forall v (m :: * -> *).
    (Data v, Monad m) =>
    (forall d. Data d => d -> m d) -> IntMap v -> m (IntMap v)
    gmapQi :: Int -> (forall d. Data d => d -> u) -> IntMap v -> u
    $cgmapQi :: forall v u.
    Data v =>
    Int -> (forall d. Data d => d -> u) -> IntMap v -> u
    gmapQ :: (forall d. Data d => d -> u) -> IntMap v -> [u]
    $cgmapQ :: forall v u.
    Data v =>
    (forall d. Data d => d -> u) -> IntMap v -> [u]
    gmapQr :: (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> IntMap v -> r
    $cgmapQr :: forall v r r'.
    Data v =>
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> IntMap v -> r
    gmapQl :: (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> IntMap v -> r
    $cgmapQl :: forall v r r'.
    Data v =>
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> IntMap v -> r
    gmapT :: (forall b. Data b => b -> b) -> IntMap v -> IntMap v
    $cgmapT :: forall v.
    Data v =>
    (forall b. Data b => b -> b) -> IntMap v -> IntMap v
    dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (IntMap v))
    $cdataCast2 :: forall v (t :: * -> * -> *) (c :: * -> *).
    (Data v, Typeable t) =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (IntMap v))
    dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (IntMap v))
    $cdataCast1 :: forall v (t :: * -> *) (c :: * -> *).
    (Data v, Typeable t) =>
    (forall d. Data d => c (t d)) -> Maybe (c (IntMap v))
    dataTypeOf :: IntMap v -> DataType
    $cdataTypeOf :: forall v. Data v => IntMap v -> DataType
    toConstr :: IntMap v -> Constr
    $ctoConstr :: forall v. Data v => IntMap v -> Constr
    gunfold :: (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (IntMap v)
    $cgunfold :: forall v (c :: * -> *).
    Data v =>
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (IntMap v)
    gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> IntMap v -> c (IntMap v)
    $cgfoldl :: forall v (c :: * -> *).
    Data v =>
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> IntMap v -> c (IntMap v)
    $cp1Data :: forall v. Data v => Typeable (IntMap v)
    Data, Typeable)

    instance Show v => Show (IntMap v) where; show :: IntMap v -> String
    show = IntMap v -> String
    forall a. Show a => a -> String
    show (IntMap v -> String)
    -> (IntMap v -> IntMap v) -> IntMap v -> String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . IntMap v -> IntMap v
    forall v. IntMap v -> IntMap v
    fromIntMap
    instance Eq v => Eq (IntMap v) where; a :: IntMap v
    a == :: IntMap v -> IntMap v -> Bool
    == b :: IntMap v
    b = IntMap v -> IntMap v
    forall v. IntMap v -> IntMap v
    fromIntMap IntMap v
    a IntMap v -> IntMap v -> Bool
    forall a. Eq a => a -> a -> Bool
    == IntMap v -> IntMap v
    forall v. IntMap v -> IntMap v
    fromIntMap IntMap v
    b
    instance Ord v => Ord (IntMap v) where; compare :: IntMap v -> IntMap v -> Ordering
    compare a :: IntMap v
    a b :: IntMap v
    b = IntMap v -> IntMap v -> Ordering
    forall a. Ord a => a -> a -> Ordering
    compare (IntMap v -> IntMap v
    forall v. IntMap v -> IntMap v
    fromIntMap IntMap v
    a) (IntMap v -> IntMap v
    forall v. IntMap v -> IntMap v
    fromIntMap IntMap v
    b)

    -- | Deconstruct a value of type 'IntMap'.
    fromIntMap :: IntMap v -> IntMap.IntMap v
    fromIntMap :: IntMap v -> IntMap v
    fromIntMap (IntMap (Invariant _ (_,_,Hide x :: IntMap v
    x))) = IntMap v
    x

    -- | Construct a value of type 'IntMap'.
    toIntMap :: IntMap.IntMap v -> IntMap v
    toIntMap :: IntMap v -> IntMap v
    toIntMap x :: IntMap v
    x = Invariant (Trigger [Int], Trigger [v], Hide (IntMap v)) -> IntMap v
    forall v.
    Invariant (Trigger [Int], Trigger [v], Hide (IntMap v)) -> IntMap v
    IntMap (Invariant (Trigger [Int], Trigger [v], Hide (IntMap v))
     -> IntMap v)
    -> Invariant (Trigger [Int], Trigger [v], Hide (IntMap v))
    -> IntMap v
    forall a b. (a -> b) -> a -> b
    $ ((Trigger [Int], Trigger [v], Hide (IntMap v))
     -> (Trigger [Int], Trigger [v], Hide (IntMap v)))
    -> (Trigger [Int], Trigger [v], Hide (IntMap v))
    -> Invariant (Trigger [Int], Trigger [v], Hide (IntMap v))
    forall a. (a -> a) -> a -> Invariant a
    Invariant (Trigger [Int], Trigger [v], Hide (IntMap v))
    -> (Trigger [Int], Trigger [v], Hide (IntMap v))
    forall b.
    (Trigger [Int], Trigger [b], Hide (IntMap b))
    -> (Trigger [Int], Trigger [b], Hide (IntMap b))
    inv ((Trigger [Int], Trigger [v], Hide (IntMap v))
     -> Invariant (Trigger [Int], Trigger [v], Hide (IntMap v)))
    -> (Trigger [Int], Trigger [v], Hide (IntMap v))
    -> Invariant (Trigger [Int], Trigger [v], Hide (IntMap v))
    forall a b. (a -> b) -> a -> b
    $ IntMap v -> (Trigger [Int], Trigger [v], Hide (IntMap v))
    forall b. IntMap b -> (Trigger [Int], Trigger [b], Hide (IntMap b))
    create IntMap v
    x
        where
            create :: IntMap b -> (Trigger [Int], Trigger [b], Hide (IntMap b))
    create x :: IntMap b
    x = (Bool -> [Int] -> Trigger [Int]
    forall a. Bool -> a -> Trigger a
    Trigger Bool
    False [Int]
    ks, Bool -> [b] -> Trigger [b]
    forall a. Bool -> a -> Trigger a
    Trigger Bool
    False [b]
    vs, IntMap b -> Hide (IntMap b)
    forall a. a -> Hide a
    Hide IntMap b
    x)
                where (ks :: [Int]
    ks,vs :: [b]
    vs) = [(Int, b)] -> ([Int], [b])
    forall a b. [(a, b)] -> ([a], [b])
    unzip ([(Int, b)] -> ([Int], [b])) -> [(Int, b)] -> ([Int], [b])
    forall a b. (a -> b) -> a -> b
    $ IntMap b -> [(Int, b)]
    forall a. IntMap a -> [(Int, a)]
    IntMap.toAscList IntMap b
    x

            inv :: (Trigger [Int], Trigger [b], Hide (IntMap b))
    -> (Trigger [Int], Trigger [b], Hide (IntMap b))
    inv (ks :: Trigger [Int]
    ks,vs :: Trigger [b]
    vs,x :: Hide (IntMap b)
    x)
                | Trigger [Int] -> Bool
    forall a. Trigger a -> Bool
    trigger Trigger [Int]
    ks = IntMap b -> (Trigger [Int], Trigger [b], Hide (IntMap b))
    forall b. IntMap b -> (Trigger [Int], Trigger [b], Hide (IntMap b))
    create (IntMap b -> (Trigger [Int], Trigger [b], Hide (IntMap b)))
    -> IntMap b -> (Trigger [Int], Trigger [b], Hide (IntMap b))
    forall a b. (a -> b) -> a -> b
    $ [(Int, b)] -> IntMap b
    forall a. [(Int, a)] -> IntMap a
    IntMap.fromList ([(Int, b)] -> IntMap b) -> [(Int, b)] -> IntMap b
    forall a b. (a -> b) -> a -> b
    $ [Int] -> [b] -> [(Int, b)]
    forall a b. [a] -> [b] -> [(a, b)]
    zip (Trigger [Int] -> [Int]
    forall a. Trigger a -> a
    fromTrigger Trigger [Int]
    ks) (Trigger [b] -> [b]
    forall a. Trigger a -> a
    fromTrigger Trigger [b]
    vs)
                | Trigger [b] -> Bool
    forall a. Trigger a -> Bool
    trigger Trigger [b]
    vs = IntMap b -> (Trigger [Int], Trigger [b], Hide (IntMap b))
    forall b. IntMap b -> (Trigger [Int], Trigger [b], Hide (IntMap b))
    create (IntMap b -> (Trigger [Int], Trigger [b], Hide (IntMap b)))
    -> IntMap b -> (Trigger [Int], Trigger [b], Hide (IntMap b))
    forall a b. (a -> b) -> a -> b
    $ [(Int, b)] -> IntMap b
    forall a. [(Int, a)] -> IntMap a
    IntMap.fromDistinctAscList ([(Int, b)] -> IntMap b) -> [(Int, b)] -> IntMap b
    forall a b. (a -> b) -> a -> b
    $ [Int] -> [b] -> [(Int, b)]
    forall a b. [a] -> [b] -> [(a, b)]
    zip (Trigger [Int] -> [Int]
    forall a. Trigger a -> a
    fromTrigger Trigger [Int]
    ks) (Trigger [b] -> [b]
    forall a. Trigger a -> a
    fromTrigger Trigger [b]
    vs) -- recreate ks/vs to reduce memory usage
                | Bool
    otherwise = (Trigger [Int]
    ks,Trigger [b]
    vs,Hide (IntMap b)
    x)

    -- | Invariant preserving version of @IntSet@ from the @containers@ packages, suitable for use with 'Uniplate'.
    --   Use 'toIntSet' to construct values, and 'fromIntSet' to deconstruct values.
    newtype IntSet = IntSet (Invariant (Trigger [Int], Hide (IntSet.IntSet)))
        deriving (Typeable IntSet
    DataType
    Constr
    Typeable IntSet =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> IntSet -> c IntSet)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c IntSet)
    -> (IntSet -> Constr)
    -> (IntSet -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c IntSet))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IntSet))
    -> ((forall b. Data b => b -> b) -> IntSet -> IntSet)
    -> (forall r r'.
        (r -> r' -> r)
        -> r -> (forall d. Data d => d -> r') -> IntSet -> r)
    -> (forall r r'.
        (r' -> r -> r)
        -> r -> (forall d. Data d => d -> r') -> IntSet -> r)
    -> (forall u. (forall d. Data d => d -> u) -> IntSet -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> IntSet -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> IntSet -> m IntSet)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> IntSet -> m IntSet)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> IntSet -> m IntSet)
    -> Data IntSet
    IntSet -> DataType
    IntSet -> Constr
    (forall b. Data b => b -> b) -> IntSet -> IntSet
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> IntSet -> c IntSet
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c IntSet
    forall a.
    Typeable a =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> a -> c a)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c a)
    -> (a -> Constr)
    -> (a -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c a))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
    -> ((forall b. Data b => b -> b) -> a -> a)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall u. (forall d. Data d => d -> u) -> a -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> Data a
    forall u. Int -> (forall d. Data d => d -> u) -> IntSet -> u
    forall u. (forall d. Data d => d -> u) -> IntSet -> [u]
    forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> IntSet -> r
    forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> IntSet -> r
    forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> IntSet -> m IntSet
    forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> IntSet -> m IntSet
    forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c IntSet
    forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> IntSet -> c IntSet
    forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c IntSet)
    forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IntSet)
    $cIntSet :: Constr
    $tIntSet :: DataType
    gmapMo :: (forall d. Data d => d -> m d) -> IntSet -> m IntSet
    $cgmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> IntSet -> m IntSet
    gmapMp :: (forall d. Data d => d -> m d) -> IntSet -> m IntSet
    $cgmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> IntSet -> m IntSet
    gmapM :: (forall d. Data d => d -> m d) -> IntSet -> m IntSet
    $cgmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> IntSet -> m IntSet
    gmapQi :: Int -> (forall d. Data d => d -> u) -> IntSet -> u
    $cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> IntSet -> u
    gmapQ :: (forall d. Data d => d -> u) -> IntSet -> [u]
    $cgmapQ :: forall u. (forall d. Data d => d -> u) -> IntSet -> [u]
    gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> IntSet -> r
    $cgmapQr :: forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> IntSet -> r
    gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> IntSet -> r
    $cgmapQl :: forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> IntSet -> r
    gmapT :: (forall b. Data b => b -> b) -> IntSet -> IntSet
    $cgmapT :: (forall b. Data b => b -> b) -> IntSet -> IntSet
    dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IntSet)
    $cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IntSet)
    dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c IntSet)
    $cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c IntSet)
    dataTypeOf :: IntSet -> DataType
    $cdataTypeOf :: IntSet -> DataType
    toConstr :: IntSet -> Constr
    $ctoConstr :: IntSet -> Constr
    gunfold :: (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c IntSet
    $cgunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c IntSet
    gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> IntSet -> c IntSet
    $cgfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> IntSet -> c IntSet
    $cp1Data :: Typeable IntSet
    Data, Typeable)

    instance Show IntSet where; show :: IntSet -> String
    show = IntSet -> String
    forall a. Show a => a -> String
    show (IntSet -> String) -> (IntSet -> IntSet) -> IntSet -> String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . IntSet -> IntSet
    fromIntSet
    instance Eq IntSet where; a :: IntSet
    a == :: IntSet -> IntSet -> Bool
    == b :: IntSet
    b = IntSet -> IntSet
    fromIntSet IntSet
    a IntSet -> IntSet -> Bool
    forall a. Eq a => a -> a -> Bool
    == IntSet -> IntSet
    fromIntSet IntSet
    b
    instance Ord IntSet where; compare :: IntSet -> IntSet -> Ordering
    compare a :: IntSet
    a b :: IntSet
    b = IntSet -> IntSet -> Ordering
    forall a. Ord a => a -> a -> Ordering
    compare (IntSet -> IntSet
    fromIntSet IntSet
    a) (IntSet -> IntSet
    fromIntSet IntSet
    b)

    -- | Deconstruct a value of type 'IntSet'.
    fromIntSet :: IntSet -> IntSet.IntSet
    fromIntSet :: IntSet -> IntSet
    fromIntSet (IntSet (Invariant _ (_,Hide x :: IntSet
    x))) = IntSet
    x

    -- | Construct a value of type 'IntSet'.
    toIntSet :: IntSet.IntSet -> IntSet
    toIntSet :: IntSet -> IntSet
    toIntSet x :: IntSet
    x = Invariant (Trigger [Int], Hide IntSet) -> IntSet
    IntSet (Invariant (Trigger [Int], Hide IntSet) -> IntSet)
    -> Invariant (Trigger [Int], Hide IntSet) -> IntSet
    forall a b. (a -> b) -> a -> b
    $ ((Trigger [Int], Hide IntSet) -> (Trigger [Int], Hide IntSet))
    -> (Trigger [Int], Hide IntSet)
    -> Invariant (Trigger [Int], Hide IntSet)
    forall a. (a -> a) -> a -> Invariant a
    Invariant (Trigger [Int], Hide IntSet) -> (Trigger [Int], Hide IntSet)
    inv ((Trigger [Int], Hide IntSet)
     -> Invariant (Trigger [Int], Hide IntSet))
    -> (Trigger [Int], Hide IntSet)
    -> Invariant (Trigger [Int], Hide IntSet)
    forall a b. (a -> b) -> a -> b
    $ IntSet -> (Trigger [Int], Hide IntSet)
    create IntSet
    x
        where
            create :: IntSet -> (Trigger [Int], Hide IntSet)
    create x :: IntSet
    x = (Bool -> [Int] -> Trigger [Int]
    forall a. Bool -> a -> Trigger a
    Trigger Bool
    False ([Int] -> Trigger [Int]) -> [Int] -> Trigger [Int]
    forall a b. (a -> b) -> a -> b
    $ IntSet -> [Int]
    IntSet.toList IntSet
    x, IntSet -> Hide IntSet
    forall a. a -> Hide a
    Hide IntSet
    x)

            inv :: (Trigger [Int], Hide IntSet) -> (Trigger [Int], Hide IntSet)
    inv (ks :: Trigger [Int]
    ks,x :: Hide IntSet
    x)
                | Trigger [Int] -> Bool
    forall a. Trigger a -> Bool
    trigger Trigger [Int]
    ks = IntSet -> (Trigger [Int], Hide IntSet)
    create (IntSet -> (Trigger [Int], Hide IntSet))
    -> IntSet -> (Trigger [Int], Hide IntSet)
    forall a b. (a -> b) -> a -> b
    $ [Int] -> IntSet
    IntSet.fromList ([Int] -> IntSet) -> [Int] -> IntSet
    forall a b. (a -> b) -> a -> b
    $ Trigger [Int] -> [Int]
    forall a. Trigger a -> a
    fromTrigger Trigger [Int]
    ks
                | Bool
    otherwise = (Trigger [Int]
    ks,Hide IntSet
    x)