-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | A map, where the keys may be complex structured data.
--   
--   This type implements maps where the keys are themselves complex
--   structured data. For example, the keys may be the abstract syntax
--   trees for a programming language. The map is implemented as a trie, so
--   common parts of the keys will be shared in the representation. The
--   library provides a generic implementation of the data structure, so
--   values of types that have support for <a>Generic</a> may be
--   automatically used as keys in the map.
@package generic-trie
@version 0.3.0.2


-- | Unstable implementation details
module Data.GenericTrie.Internal

-- | Types that may be used as the key of a <a>Trie</a>.
--   
--   For <tt>data</tt> delcarations, the instance can be automatically
--   derived from a <a>Generic</a> instance.
class TrieKey k where type TrieRep k :: * -> * type TrieRep k = TrieRepDefault k trieEmpty = genericEmpty trieSingleton = genericSingleton trieNull = genericTrieNull trieLookup = genericLookup trieInsert = genericInsert trieDelete = genericDelete trieMap = genericTrieMap trieTraverse = genericTrieTraverse trieShowsPrec = genericTrieShowsPrec trieMapMaybeWithKey = genericMapMaybeWithKey trieFoldWithKey = genericFoldWithKey trieTraverseWithKey = genericTraverseWithKey trieMergeWithKey = genericMergeWithKey where {
    type family TrieRep k :: * -> *;
    type TrieRep k = TrieRepDefault k;
}

-- | Construct an empty trie
trieEmpty :: TrieKey k => Trie k a

-- | Test for an empty trie
trieNull :: TrieKey k => Trie k a -> Bool

-- | Lookup element from trie
trieLookup :: TrieKey k => k -> Trie k a -> Maybe a

-- | Insert element into trie
trieInsert :: TrieKey k => k -> a -> Trie k a -> Trie k a

-- | Delete element from trie
trieDelete :: TrieKey k => k -> Trie k a -> Trie k a

-- | Construct a trie holding a single value
trieSingleton :: TrieKey k => k -> a -> Trie k a

-- | Apply a function to all values stored in a trie
trieMap :: TrieKey k => (a -> b) -> Trie k a -> Trie k b

-- | Traverse the values stored in a trie
trieTraverse :: (TrieKey k, Applicative f) => (a -> f b) -> Trie k a -> f (Trie k b)

-- | Show the representation of a trie
trieShowsPrec :: (TrieKey k, Show a) => Int -> Trie k a -> ShowS

-- | Apply a function to the values of a <a>Trie</a> and keep the elements
--   of the trie that result in a <a>Just</a> value.
trieMapMaybeWithKey :: TrieKey k => (k -> a -> Maybe b) -> Trie k a -> Trie k b

-- | Fold a trie with a function of both key and value.
trieFoldWithKey :: TrieKey k => (k -> a -> r -> r) -> r -> Trie k a -> r

-- | Traverse a trie with a function of both key and value.
trieTraverseWithKey :: (TrieKey k, Applicative f) => (k -> a -> f b) -> Trie k a -> f (Trie k b)
trieMergeWithKey :: TrieKey k => (k -> a -> b -> Maybe c) -> (Trie k a -> Trie k c) -> (Trie k b -> Trie k c) -> Trie k a -> Trie k b -> Trie k c

-- | Construct an empty trie
trieEmpty :: (TrieKey k, TrieRep k ~ TrieRepDefault k) => Trie k a

-- | Construct a trie holding a single value
trieSingleton :: (TrieKey k, GTrieKey (Rep k), Generic k, TrieRep k ~ TrieRepDefault k) => k -> a -> Trie k a

-- | Test for an empty trie
trieNull :: (TrieKey k, TrieRep k ~ TrieRepDefault k) => Trie k a -> Bool

-- | Lookup element from trie
trieLookup :: (TrieKey k, GTrieKey (Rep k), Generic k, TrieRep k ~ TrieRepDefault k) => k -> Trie k a -> Maybe a

-- | Insert element into trie
trieInsert :: (TrieKey k, GTrieKey (Rep k), Generic k, TrieRep k ~ TrieRepDefault k) => k -> a -> Trie k a -> Trie k a

-- | Delete element from trie
trieDelete :: (TrieKey k, GTrieKey (Rep k), Generic k, TrieRep k ~ TrieRepDefault k) => k -> Trie k a -> Trie k a

-- | Apply a function to all values stored in a trie
trieMap :: (TrieKey k, GTrieKey (Rep k), TrieRep k ~ TrieRepDefault k) => (a -> b) -> Trie k a -> Trie k b

-- | Traverse the values stored in a trie
trieTraverse :: (TrieKey k, GTrieKey (Rep k), TrieRep k ~ TrieRepDefault k, Applicative f) => (a -> f b) -> Trie k a -> f (Trie k b)

-- | Show the representation of a trie
trieShowsPrec :: (TrieKey k, Show a, GTrieKeyShow (Rep k), TrieRep k ~ TrieRepDefault k) => Int -> Trie k a -> ShowS

-- | Apply a function to the values of a <a>Trie</a> and keep the elements
--   of the trie that result in a <a>Just</a> value.
trieMapMaybeWithKey :: (TrieKey k, GTrieKey (Rep k), Generic k, TrieRep k ~ TrieRepDefault k) => (k -> a -> Maybe b) -> Trie k a -> Trie k b

-- | Fold a trie with a function of both key and value.
trieFoldWithKey :: (TrieKey k, GTrieKey (Rep k), TrieRep k ~ TrieRepDefault k, Generic k) => (k -> a -> r -> r) -> r -> Trie k a -> r

-- | Traverse a trie with a function of both key and value.
trieTraverseWithKey :: (TrieKey k, GTrieKey (Rep k), TrieRep k ~ TrieRepDefault k, Generic k, Applicative f) => (k -> a -> f b) -> Trie k a -> f (Trie k b)
trieMergeWithKey :: (TrieKey k, GTrieKey (Rep k), TrieRep k ~ TrieRepDefault k, Generic k) => (k -> a -> b -> Maybe c) -> (Trie k a -> Trie k c) -> (Trie k b -> Trie k c) -> Trie k a -> Trie k b -> Trie k c

-- | A map from keys of type <tt>k</tt>, to values of type <tt>a</tt>.
newtype Trie k a
MkTrie :: (TrieRep k a) -> Trie k a

-- | Tries indexed by <a>OrdKey</a> will be represented as an ordinary
--   <a>Map</a> and the keys will be compared based on the <a>Ord</a>
--   instance for <tt>k</tt>.
newtype OrdKey k
OrdKey :: k -> OrdKey k
[getOrdKey] :: OrdKey k -> k

-- | Generic implementation of <a>trieNull</a>. This is the default
--   implementation.
genericTrieNull :: (TrieRep k ~ TrieRepDefault k) => Trie k a -> Bool

-- | Generic implementation of <a>trieMap</a>. This is the default
--   implementation.
genericTrieMap :: (GTrieKey (Rep k), TrieRep k ~ TrieRepDefault k) => (a -> b) -> Trie k a -> Trie k b

-- | Generic implementation of <a>trieTraverse</a>. This is the default
--   implementation.
genericTrieTraverse :: (GTrieKey (Rep k), TrieRep k ~ TrieRepDefault k, Applicative f) => (a -> f b) -> Trie k a -> f (Trie k b)

-- | Generic implementation of <a>trieShowsPrec</a>. This is the default
--   implementation.
genericTrieShowsPrec :: (Show a, GTrieKeyShow (Rep k), TrieRep k ~ TrieRepDefault k) => Int -> Trie k a -> ShowS

-- | Generic implementation of <tt>insert</tt>. This is the default
--   implementation.
genericInsert :: (GTrieKey (Rep k), Generic k, TrieRep k ~ TrieRepDefault k) => k -> a -> Trie k a -> Trie k a

-- | Generic implementation of <a>lookup</a>. This is the default
--   implementation.
genericLookup :: (GTrieKey (Rep k), Generic k, TrieRep k ~ TrieRepDefault k) => k -> Trie k a -> Maybe a

-- | Generic implementation of <tt>delete</tt>. This is the default
--   implementation.
genericDelete :: (GTrieKey (Rep k), Generic k, TrieRep k ~ TrieRepDefault k) => k -> Trie k a -> Trie k a

-- | Generic implementation of <tt>mapMaybe</tt>. This is the default
--   implementation.
genericMapMaybeWithKey :: (GTrieKey (Rep k), Generic k, TrieRep k ~ TrieRepDefault k) => (k -> a -> Maybe b) -> Trie k a -> Trie k b

-- | Generic implementation of <tt>singleton</tt>. This is the default
--   implementation.
genericSingleton :: (GTrieKey (Rep k), Generic k, TrieRep k ~ TrieRepDefault k) => k -> a -> Trie k a

-- | Generic implementation of <tt>empty</tt>. This is the default
--   implementation.
genericEmpty :: (TrieRep k ~ TrieRepDefault k) => Trie k a

-- | Generic implementation of <tt>foldWithKey</tt>. This is the default
--   implementation.
genericFoldWithKey :: (GTrieKey (Rep k), Generic k, TrieRep k ~ TrieRepDefault k) => (k -> a -> r -> r) -> r -> Trie k a -> r

-- | Generic implementation of <tt>traverseWithKey</tt>. This is the
--   default implementation.
genericTraverseWithKey :: (GTrieKey (Rep k), Generic k, TrieRep k ~ TrieRepDefault k, Applicative f) => (k -> a -> f b) -> Trie k a -> f (Trie k b)

-- | The default implementation of a <a>TrieRep</a> is <a>GTrie</a> wrapped
--   in a <a>Maybe</a>. This wrapping is due to the <a>GTrie</a> being a
--   non-empty trie allowing all the of the "emptiness" to be represented
--   at the top level for any given generically implemented key.
type TrieRepDefault k = Compose Maybe (GTrie (Rep k))

-- | TrieKey operations on Generic representations used to provide the
--   default implementations of tries.
class GTrieKey f
gtrieLookup :: GTrieKey f => f p -> GTrie f a -> Maybe a
gtrieInsert :: GTrieKey f => f p -> a -> GTrie f a -> GTrie f a
gtrieSingleton :: GTrieKey f => f p -> a -> GTrie f a
gtrieDelete :: GTrieKey f => f p -> GTrie f a -> Maybe (GTrie f a)
gtrieMap :: GTrieKey f => (a -> b) -> GTrie f a -> GTrie f b
gtrieTraverse :: (GTrieKey f, Applicative m) => (a -> m b) -> GTrie f a -> m (GTrie f b)
gmapMaybeWithKey :: GTrieKey f => (f p -> a -> Maybe b) -> GTrie f a -> Maybe (GTrie f b)
gfoldWithKey :: GTrieKey f => (f p -> a -> r -> r) -> r -> GTrie f a -> r
gtraverseWithKey :: (GTrieKey f, Applicative m) => (f p -> a -> m b) -> GTrie f a -> m (GTrie f b)
gmergeWithKey :: GTrieKey f => (f p -> a -> b -> Maybe c) -> (GTrie f a -> Maybe (GTrie f c)) -> (GTrie f b -> Maybe (GTrie f c)) -> GTrie f a -> GTrie f b -> Maybe (GTrie f c)

-- | Mapping of generic representation of keys to trie structures.
instance GHC.Classes.Ord k => GHC.Classes.Ord (Data.GenericTrie.Internal.OrdKey k)
instance GHC.Classes.Eq k => GHC.Classes.Eq (Data.GenericTrie.Internal.OrdKey k)
instance GHC.Show.Show k => GHC.Show.Show (Data.GenericTrie.Internal.OrdKey k)
instance GHC.Read.Read k => GHC.Read.Read (Data.GenericTrie.Internal.OrdKey k)
instance Data.GenericTrie.Internal.TrieKey GHC.Types.Int
instance Data.GenericTrie.Internal.TrieKey GHC.Integer.Type.Integer
instance Data.GenericTrie.Internal.TrieKey GHC.Types.Char
instance (GHC.Show.Show k, GHC.Classes.Ord k) => Data.GenericTrie.Internal.TrieKey (Data.GenericTrie.Internal.OrdKey k)
instance Data.GenericTrie.Internal.TrieKey ()
instance Data.GenericTrie.Internal.TrieKey GHC.Types.Bool
instance Data.GenericTrie.Internal.TrieKey k => Data.GenericTrie.Internal.TrieKey (GHC.Base.Maybe k)
instance (Data.GenericTrie.Internal.TrieKey a, Data.GenericTrie.Internal.TrieKey b) => Data.GenericTrie.Internal.TrieKey (Data.Either.Either a b)
instance (Data.GenericTrie.Internal.TrieKey a, Data.GenericTrie.Internal.TrieKey b) => Data.GenericTrie.Internal.TrieKey (a, b)
instance (Data.GenericTrie.Internal.TrieKey a, Data.GenericTrie.Internal.TrieKey b, Data.GenericTrie.Internal.TrieKey c) => Data.GenericTrie.Internal.TrieKey (a, b, c)
instance (Data.GenericTrie.Internal.TrieKey a, Data.GenericTrie.Internal.TrieKey b, Data.GenericTrie.Internal.TrieKey c, Data.GenericTrie.Internal.TrieKey d) => Data.GenericTrie.Internal.TrieKey (a, b, c, d)
instance (Data.GenericTrie.Internal.TrieKey a, Data.GenericTrie.Internal.TrieKey b, Data.GenericTrie.Internal.TrieKey c, Data.GenericTrie.Internal.TrieKey d, Data.GenericTrie.Internal.TrieKey e) => Data.GenericTrie.Internal.TrieKey (a, b, c, d, e)
instance Data.GenericTrie.Internal.TrieKey k => Data.GenericTrie.Internal.TrieKey [k]
instance Data.GenericTrie.Internal.GTrieKey f => GHC.Base.Functor (Data.GenericTrie.Internal.GTrie f)
instance Data.GenericTrie.Internal.GTrieKey f => Data.GenericTrie.Internal.GTrieKey (GHC.Generics.M1 i c f)
instance Data.GenericTrie.Internal.GTrieKeyShow f => Data.GenericTrie.Internal.GTrieKeyShow (GHC.Generics.M1 GHC.Generics.D d f)
instance (GHC.Generics.Constructor c, Data.GenericTrie.Internal.GTrieKeyShow f) => Data.GenericTrie.Internal.GTrieKeyShow (GHC.Generics.M1 GHC.Generics.C c f)
instance Data.GenericTrie.Internal.GTrieKeyShow f => Data.GenericTrie.Internal.GTrieKeyShow (GHC.Generics.M1 GHC.Generics.S s f)
instance Data.GenericTrie.Internal.TrieKey k => Data.GenericTrie.Internal.GTrieKey (GHC.Generics.K1 i k)
instance Data.GenericTrie.Internal.TrieKey k => Data.GenericTrie.Internal.GTrieKeyShow (GHC.Generics.K1 i k)
instance (Data.GenericTrie.Internal.GTrieKey f, Data.GenericTrie.Internal.GTrieKey g) => Data.GenericTrie.Internal.GTrieKey (f GHC.Generics.:*: g)
instance (Data.GenericTrie.Internal.GTrieKeyShow f, Data.GenericTrie.Internal.GTrieKeyShow g) => Data.GenericTrie.Internal.GTrieKeyShow (f GHC.Generics.:*: g)
instance (Data.GenericTrie.Internal.GTrieKey f, Data.GenericTrie.Internal.GTrieKey g) => Data.GenericTrie.Internal.GTrieKey (f GHC.Generics.:+: g)
instance (Data.GenericTrie.Internal.GTrieKeyShow f, Data.GenericTrie.Internal.GTrieKeyShow g) => Data.GenericTrie.Internal.GTrieKeyShow (f GHC.Generics.:+: g)
instance Data.GenericTrie.Internal.GTrieKey GHC.Generics.U1
instance Data.GenericTrie.Internal.GTrieKeyShow GHC.Generics.U1
instance Data.GenericTrie.Internal.GTrieKey GHC.Generics.V1
instance Data.GenericTrie.Internal.GTrieKeyShow GHC.Generics.V1
instance (GHC.Show.Show a, Data.GenericTrie.Internal.TrieKey k) => GHC.Show.Show (Data.GenericTrie.Internal.Trie k a)
instance (GHC.Show.Show a, Data.GenericTrie.Internal.GTrieKeyShow f) => GHC.Show.Show (Data.GenericTrie.Internal.GTrie f a)
instance Data.GenericTrie.Internal.TrieKey k => GHC.Base.Functor (Data.GenericTrie.Internal.Trie k)
instance Data.GenericTrie.Internal.TrieKey k => Data.Foldable.Foldable (Data.GenericTrie.Internal.Trie k)
instance Data.GenericTrie.Internal.TrieKey k => Data.Traversable.Traversable (Data.GenericTrie.Internal.Trie k)


-- | This module implements an interface for working with maps.
--   
--   For primitive types, like <a>Int</a>, the library automatically
--   selects an efficient implementation (e.g., an <a>IntMap</a>).
--   
--   For complex structured types, the library uses an implementation based
--   on tries: this is useful when using large and similar keys where
--   comparing for order may become expensive, and storing the distinct
--   keys would be inefficient.
--   
--   The <a>OrdKey</a> type allows for maps with complex keys, where the
--   keys are compared based on order, rather than using the trie
--   implementation.
--   
--   All methods of <a>TrieKey</a> can be derived automatically using a
--   <a>Generic</a> instance.
--   
--   <pre>
--   data Demo = DemoC1 <a>Int</a> | DemoC2 <a>Int</a> <a>Char</a>  deriving <a>Generic</a>
--   
--   instance <a>TrieKey</a> Demo
--   </pre>
module Data.GenericTrie

-- | A map from keys of type <tt>k</tt>, to values of type <tt>a</tt>.
data Trie k a

-- | Types that may be used as the key of a <a>Trie</a>.
--   
--   For <tt>data</tt> delcarations, the instance can be automatically
--   derived from a <a>Generic</a> instance.
class TrieKey k where type TrieRep k = TrieRepDefault k trieEmpty = genericEmpty trieSingleton = genericSingleton trieNull = genericTrieNull trieLookup = genericLookup trieInsert = genericInsert trieDelete = genericDelete trieMap = genericTrieMap trieTraverse = genericTrieTraverse trieShowsPrec = genericTrieShowsPrec trieMapMaybeWithKey = genericMapMaybeWithKey trieFoldWithKey = genericFoldWithKey trieTraverseWithKey = genericTraverseWithKey trieMergeWithKey = genericMergeWithKey

-- | Construct an empty trie
empty :: TrieKey k => Trie k a

-- | Construct a trie holding a single value
singleton :: TrieKey k => k -> a -> Trie k a

-- | Construct a trie from a list of key-value pairs
fromList :: TrieKey k => [(k, v)] -> Trie k v

-- | Construct a trie from a list of key-value pairs. The given function is
--   used to combine values at the same key.
fromListWith :: TrieKey k => (v -> v -> v) -> [(k, v)] -> Trie k v

-- | Version of <a>fromListWith</a> which is strict in the result of the
--   combining function.
fromListWith' :: TrieKey k => (v -> v -> v) -> [(k, v)] -> Trie k v

-- | Alter the value at the given key location. The parameter function
--   takes the value stored at the given key, if one exists, and should
--   return a value to insert at that location, or <a>Nothing</a> to delete
--   from that location.
alter :: TrieKey k => k -> (Maybe a -> Maybe a) -> Trie k a -> Trie k a

-- | Insert an element into a trie
insert :: TrieKey k => k -> a -> Trie k a -> Trie k a

-- | Insert a value at the given key. The combining function is used when a
--   value is already stored at that key. The new value is the first
--   argument to the combining function.
insertWith :: TrieKey k => (v -> v -> v) -> k -> v -> Trie k v -> Trie k v

-- | Version of <a>insertWith</a> that is strict in the result of combining
--   two elements.
insertWith' :: TrieKey k => (v -> v -> v) -> k -> v -> Trie k v -> Trie k v

-- | Delete an element from a trie
delete :: TrieKey k => k -> Trie k a -> Trie k a

-- | Lens for the value at a given key
at :: (Functor f, TrieKey k) => k -> (Maybe a -> f (Maybe a)) -> Trie k a -> f (Trie k a)

-- | Returns <a>True</a> when the <a>Trie</a> has a value stored at the
--   given key.
member :: TrieKey k => k -> Trie k a -> Bool

-- | Returns <a>False</a> when the <a>Trie</a> has a value stored at the
--   given key.
notMember :: TrieKey k => k -> Trie k a -> Bool

-- | Test for an empty trie
null :: TrieKey k => Trie k a -> Bool

-- | Lookup an element from a trie
lookup :: TrieKey k => k -> Trie k a -> Maybe a

-- | Fold a trie with a function of both key and value
foldWithKey :: TrieKey k => (k -> a -> r -> r) -> r -> Trie k a -> r

-- | Fold a trie with a function of the value
fold :: TrieKey k => (a -> r -> r) -> r -> Trie k a -> r

-- | Transform a trie to an association list.
toList :: TrieKey k => Trie k a -> [(k, a)]

-- | Traverse a trie with a function of both key and value
traverseWithKey :: (TrieKey k, Applicative f) => (k -> a -> f b) -> Trie k a -> f (Trie k b)

-- | Map a function over a trie filtering out elements where function
--   returns <a>Nothing</a>
mapMaybe :: TrieKey k => (a -> Maybe b) -> Trie k a -> Trie k b

-- | Apply a function to the values of a trie and keep the elements of the
--   trie that result in a <a>Just</a> value.
mapMaybeWithKey :: TrieKey k => (k -> a -> Maybe b) -> Trie k a -> Trie k b

-- | Filter the values of a trie with the given predicate.
filter :: TrieKey k => (a -> Bool) -> Trie k a -> Trie k a

-- | Version of <a>filter</a> where the predicate also gets the key.
filterWithKey :: TrieKey k => (k -> a -> Bool) -> Trie k a -> Trie k a

-- | Left-biased union of two tries
union :: TrieKey k => Trie k a -> Trie k a -> Trie k a

-- | Union of two tries with function used to merge overlapping elements
unionWith :: TrieKey k => (a -> a -> a) -> Trie k a -> Trie k a -> Trie k a

-- | Union of two tries with function used to merge overlapping elements
--   along with key
unionWithKey :: TrieKey k => (k -> a -> a -> a) -> Trie k a -> Trie k a -> Trie k a

-- | Left-biased intersection of two tries
intersection :: TrieKey k => Trie k a -> Trie k b -> Trie k a

-- | Intersection of two tries parameterized by a combining function of the
--   values at overlapping keys
intersectionWith :: TrieKey k => (a -> b -> c) -> Trie k a -> Trie k b -> Trie k c

-- | Intersection of two tries parameterized by a combining function of the
--   key and the values at overlapping keys
intersectionWithKey :: TrieKey k => (k -> a -> b -> c) -> Trie k a -> Trie k b -> Trie k c

-- | Remove the keys of the right trie from the left trie
difference :: TrieKey k => Trie k a -> Trie k b -> Trie k a

-- | Parameterized <a>difference</a> using a custom merge function. Return
--   <a>Just</a> to change the value stored in left trie, or <a>Nothing</a>
--   to remove from the left trie.
differenceWith :: TrieKey k => (a -> b -> Maybe a) -> Trie k a -> Trie k b -> Trie k a

-- | <a>differenceWith</a> where function also has access to the key
differenceWithKey :: TrieKey k => (k -> a -> b -> Maybe a) -> Trie k a -> Trie k b -> Trie k a

-- | Tries indexed by <a>OrdKey</a> will be represented as an ordinary
--   <a>Map</a> and the keys will be compared based on the <a>Ord</a>
--   instance for <tt>k</tt>.
newtype OrdKey k
OrdKey :: k -> OrdKey k
[getOrdKey] :: OrdKey k -> k
