Data.GenericTrie.Internal

generic-trie-0.3.0.2: A map, where the keys may be complex structured data.

Safe Haskell | Trustworthy
Language | Haskell2010

Data.GenericTrie.Internal

Contents

- Generic derivation implementation

Description

Unstable implementation details

Synopsis

- class TrieKey k where
  - type TrieRep k :: * -> *
- newtype Trie k a = MkTrie (TrieRep k a)
- newtype OrdKey k = OrdKey {
  - getOrdKey :: k
  }
- genericTrieNull :: TrieRep k ~ TrieRepDefault k => Trie k a -> Bool
- genericTrieMap :: (GTrieKey (Rep k), TrieRep k ~ TrieRepDefault k) => (a -> b) -> Trie k a -> Trie k b
- genericTrieTraverse :: (GTrieKey (Rep k), TrieRep k ~ TrieRepDefault k, Applicative f) => (a -> f b) -> Trie k a -> f (Trie k b)
- genericTrieShowsPrec :: (Show a, GTrieKeyShow (Rep k), TrieRep k ~ TrieRepDefault k) => Int -> Trie k a -> ShowS
- genericInsert :: (GTrieKey (Rep k), Generic k, TrieRep k ~ TrieRepDefault k) => k -> a -> Trie k a -> Trie k a
- genericLookup :: (GTrieKey (Rep k), Generic k, TrieRep k ~ TrieRepDefault k) => k -> Trie k a -> Maybe a
- genericDelete :: (GTrieKey (Rep k), Generic k, TrieRep k ~ TrieRepDefault k) => k -> Trie k a -> Trie k a
- genericMapMaybeWithKey :: (GTrieKey (Rep k), Generic k, TrieRep k ~ TrieRepDefault k) => (k -> a -> Maybe b) -> Trie k a -> Trie k b
- genericSingleton :: (GTrieKey (Rep k), Generic k, TrieRep k ~ TrieRepDefault k) => k -> a -> Trie k a
- genericEmpty :: TrieRep k ~ TrieRepDefault k => Trie k a
- genericFoldWithKey :: (GTrieKey (Rep k), Generic k, TrieRep k ~ TrieRepDefault k) => (k -> a -> r -> r) -> r -> Trie k a -> r
- genericTraverseWithKey :: (GTrieKey (Rep k), Generic k, TrieRep k ~ TrieRepDefault k, Applicative f) => (k -> a -> f b) -> Trie k a -> f (Trie k b)
- type TrieRepDefault k = Compose Maybe (GTrie (Rep k))
- class GTrieKey f where
- data family GTrie (f :: * -> *) a

# Documentation

class TrieKey k where #

Types that may be used as the key of a `Trie`.

For `data` delcarations, the instance can be automatically derived from a `Generic` instance.

Associated Types

type TrieRep k :: * -> * #

Type of the representation of tries for this key.

Methods

trieEmpty :: Trie k a #

Construct an empty trie

trieNull :: Trie k a -> Bool #

Test for an empty trie

trieLookup :: k -> Trie k a -> Maybe a #

Lookup element from trie

trieInsert :: k -> a -> Trie k a -> Trie k a #

Insert element into trie

trieDelete :: k -> Trie k a -> Trie k a #

Delete element from trie

trieSingleton :: k -> a -> Trie k a #

Construct a trie holding a single value

trieMap :: (a -> b) -> Trie k a -> Trie k b #

Apply a function to all values stored in a trie

trieTraverse :: Applicative f => (a -> f b) -> Trie k a -> f (Trie k b) #

Traverse the values stored in a trie

trieShowsPrec :: Show a => Int -> Trie k a -> ShowS #

Show the representation of a trie

trieMapMaybeWithKey :: (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 `Just` value.

trieFoldWithKey :: (k -> a -> r -> r) -> r -> Trie k a -> r #

Fold a trie with a function of both key and value.

trieTraverseWithKey :: Applicative f => (k -> a -> f b) -> Trie k a -> f (Trie k b) #

Traverse a trie with a function of both key and value.

trieMergeWithKey :: (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 #

trieEmpty :: TrieRep k ~ TrieRepDefault k => Trie k a #

Construct an empty trie

trieSingleton :: (GTrieKey (Rep k), Generic k, TrieRep k ~ TrieRepDefault k) => k -> a -> Trie k a #

Construct a trie holding a single value

trieNull :: TrieRep k ~ TrieRepDefault k => Trie k a -> Bool #

Test for an empty trie

trieLookup :: (GTrieKey (Rep k), Generic k, TrieRep k ~ TrieRepDefault k) => k -> Trie k a -> Maybe a #

Lookup element from trie

trieInsert :: (GTrieKey (Rep k), Generic k, TrieRep k ~ TrieRepDefault k) => k -> a -> Trie k a -> Trie k a #

Insert element into trie

trieDelete :: (GTrieKey (Rep k), Generic k, TrieRep k ~ TrieRepDefault k) => k -> Trie k a -> Trie k a #

Delete element from trie

trieMap :: (GTrieKey (Rep k), TrieRep k ~ TrieRepDefault k) => (a -> b) -> Trie k a -> Trie k b #

Apply a function to all values stored in a trie

trieTraverse :: (GTrieKey (Rep k), TrieRep k ~ TrieRepDefault k, Applicative f) => (a -> f b) -> Trie k a -> f (Trie k b) #

Traverse the values stored in a trie

trieShowsPrec :: (Show a, GTrieKeyShow (Rep k), TrieRep k ~ TrieRepDefault k) => Int -> Trie k a -> ShowS #

Show the representation of a trie

trieMapMaybeWithKey :: (GTrieKey (Rep k), Generic k, TrieRep k ~ TrieRepDefault k) => (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 `Just` value.

trieFoldWithKey :: (GTrieKey (Rep k), TrieRep k ~ TrieRepDefault k, Generic k) => (k -> a -> r -> r) -> r -> Trie k a -> r #

Fold a trie with a function of both key and value.

trieTraverseWithKey :: (GTrieKey (Rep k), TrieRep k ~ TrieRepDefault k, Generic k, Applicative f) => (k -> a -> f b) -> Trie k a -> f (Trie k b) #

Traverse a trie with a function of both key and value.

trieMergeWithKey :: (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 #

Instances

TrieKey Bool # |
Associated Types type TrieRep Bool :: * -> * # Methods trieEmpty :: Trie Bool a # trieNull :: Trie Bool a -> Bool # trieLookup :: Bool -> Trie Bool a -> Maybe a # trieInsert :: Bool -> a -> Trie Bool a -> Trie Bool a # trieDelete :: Bool -> Trie Bool a -> Trie Bool a # trieSingleton :: Bool -> a -> Trie Bool a # trieMap :: (a -> b) -> Trie Bool a -> Trie Bool b # trieTraverse :: Applicative f => (a -> f b) -> Trie Bool a -> f (Trie Bool b) # trieShowsPrec :: Show a => Int -> Trie Bool a -> ShowS # trieMapMaybeWithKey :: (Bool -> a -> Maybe b) -> Trie Bool a -> Trie Bool b # trieFoldWithKey :: (Bool -> a -> r -> r) -> r -> Trie Bool a -> r # trieTraverseWithKey :: Applicative f => (Bool -> a -> f b) -> Trie Bool a -> f (Trie Bool b) # trieMergeWithKey :: (Bool -> a -> b -> Maybe c) -> (Trie Bool a -> Trie Bool c) -> (Trie Bool b -> Trie Bool c) -> Trie Bool a -> Trie Bool b -> Trie Bool c #
TrieKey Char # | `Char` tries are implemented with `IntMap`.
Associated Types type TrieRep Char :: * -> * # Methods trieEmpty :: Trie Char a # trieNull :: Trie Char a -> Bool # trieLookup :: Char -> Trie Char a -> Maybe a # trieInsert :: Char -> a -> Trie Char a -> Trie Char a # trieDelete :: Char -> Trie Char a -> Trie Char a # trieSingleton :: Char -> a -> Trie Char a # trieMap :: (a -> b) -> Trie Char a -> Trie Char b # trieTraverse :: Applicative f => (a -> f b) -> Trie Char a -> f (Trie Char b) # trieShowsPrec :: Show a => Int -> Trie Char a -> ShowS # trieMapMaybeWithKey :: (Char -> a -> Maybe b) -> Trie Char a -> Trie Char b # trieFoldWithKey :: (Char -> a -> r -> r) -> r -> Trie Char a -> r # trieTraverseWithKey :: Applicative f => (Char -> a -> f b) -> Trie Char a -> f (Trie Char b) # trieMergeWithKey :: (Char -> a -> b -> Maybe c) -> (Trie Char a -> Trie Char c) -> (Trie Char b -> Trie Char c) -> Trie Char a -> Trie Char b -> Trie Char c #
TrieKey Int # | `Int` tries are implemented with `IntMap`.
Associated Types type TrieRep Int :: * -> * # Methods trieEmpty :: Trie Int a # trieNull :: Trie Int a -> Bool # trieLookup :: Int -> Trie Int a -> Maybe a # trieInsert :: Int -> a -> Trie Int a -> Trie Int a # trieDelete :: Int -> Trie Int a -> Trie Int a # trieSingleton :: Int -> a -> Trie Int a # trieMap :: (a -> b) -> Trie Int a -> Trie Int b # trieTraverse :: Applicative f => (a -> f b) -> Trie Int a -> f (Trie Int b) # trieShowsPrec :: Show a => Int -> Trie Int a -> ShowS # trieMapMaybeWithKey :: (Int -> a -> Maybe b) -> Trie Int a -> Trie Int b # trieFoldWithKey :: (Int -> a -> r -> r) -> r -> Trie Int a -> r # trieTraverseWithKey :: Applicative f => (Int -> a -> f b) -> Trie Int a -> f (Trie Int b) # trieMergeWithKey :: (Int -> a -> b -> Maybe c) -> (Trie Int a -> Trie Int c) -> (Trie Int b -> Trie Int c) -> Trie Int a -> Trie Int b -> Trie Int c #
TrieKey Integer # | `Integer` tries are implemented with `Map`.
Associated Types type TrieRep Integer :: * -> * # Methods trieEmpty :: Trie Integer a # trieNull :: Trie Integer a -> Bool # trieLookup :: Integer -> Trie Integer a -> Maybe a # trieInsert :: Integer -> a -> Trie Integer a -> Trie Integer a # trieDelete :: Integer -> Trie Integer a -> Trie Integer a # trieSingleton :: Integer -> a -> Trie Integer a # trieMap :: (a -> b) -> Trie Integer a -> Trie Integer b # trieTraverse :: Applicative f => (a -> f b) -> Trie Integer a -> f (Trie Integer b) # trieShowsPrec :: Show a => Int -> Trie Integer a -> ShowS # trieMapMaybeWithKey :: (Integer -> a -> Maybe b) -> Trie Integer a -> Trie Integer b # trieFoldWithKey :: (Integer -> a -> r -> r) -> r -> Trie Integer a -> r # trieTraverseWithKey :: Applicative f => (Integer -> a -> f b) -> Trie Integer a -> f (Trie Integer b) # trieMergeWithKey :: (Integer -> a -> b -> Maybe c) -> (Trie Integer a -> Trie Integer c) -> (Trie Integer b -> Trie Integer c) -> Trie Integer a -> Trie Integer b -> Trie Integer c #
TrieKey () # |
Associated Types type TrieRep () :: * -> * # Methods trieEmpty :: Trie () a # trieNull :: Trie () a -> Bool # trieLookup :: () -> Trie () a -> Maybe a # trieInsert :: () -> a -> Trie () a -> Trie () a # trieDelete :: () -> Trie () a -> Trie () a # trieSingleton :: () -> a -> Trie () a # trieMap :: (a -> b) -> Trie () a -> Trie () b # trieTraverse :: Applicative f => (a -> f b) -> Trie () a -> f (Trie () b) # trieShowsPrec :: Show a => Int -> Trie () a -> ShowS # trieMapMaybeWithKey :: (() -> a -> Maybe b) -> Trie () a -> Trie () b # trieFoldWithKey :: (() -> a -> r -> r) -> r -> Trie () a -> r # trieTraverseWithKey :: Applicative f => (() -> a -> f b) -> Trie () a -> f (Trie () b) # trieMergeWithKey :: (() -> a -> b -> Maybe c) -> (Trie () a -> Trie () c) -> (Trie () b -> Trie () c) -> Trie () a -> Trie () b -> Trie () c #
TrieKey k => TrieKey [k] # |
Associated Types type TrieRep [k] :: * -> * # Methods trieEmpty :: Trie [k] a # trieNull :: Trie [k] a -> Bool # trieLookup :: [k] -> Trie [k] a -> Maybe a # trieInsert :: [k] -> a -> Trie [k] a -> Trie [k] a # trieDelete :: [k] -> Trie [k] a -> Trie [k] a # trieSingleton :: [k] -> a -> Trie [k] a # trieMap :: (a -> b) -> Trie [k] a -> Trie [k] b # trieTraverse :: Applicative f => (a -> f b) -> Trie [k] a -> f (Trie [k] b) # trieShowsPrec :: Show a => Int -> Trie [k] a -> ShowS # trieMapMaybeWithKey :: ([k] -> a -> Maybe b) -> Trie [k] a -> Trie [k] b # trieFoldWithKey :: ([k] -> a -> r -> r) -> r -> Trie [k] a -> r # trieTraverseWithKey :: Applicative f => ([k] -> a -> f b) -> Trie [k] a -> f (Trie [k] b) # trieMergeWithKey :: ([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 #
TrieKey k => TrieKey (Maybe k) # |
Associated Types type TrieRep (Maybe k) :: * -> * # Methods trieEmpty :: Trie (Maybe k) a # trieNull :: Trie (Maybe k) a -> Bool # trieLookup :: Maybe k -> Trie (Maybe k) a -> Maybe a # trieInsert :: Maybe k -> a -> Trie (Maybe k) a -> Trie (Maybe k) a # trieDelete :: Maybe k -> Trie (Maybe k) a -> Trie (Maybe k) a # trieSingleton :: Maybe k -> a -> Trie (Maybe k) a # trieMap :: (a -> b) -> Trie (Maybe k) a -> Trie (Maybe k) b # trieTraverse :: Applicative f => (a -> f b) -> Trie (Maybe k) a -> f (Trie (Maybe k) b) # trieShowsPrec :: Show a => Int -> Trie (Maybe k) a -> ShowS # trieMapMaybeWithKey :: (Maybe k -> a -> Maybe b) -> Trie (Maybe k) a -> Trie (Maybe k) b # trieFoldWithKey :: (Maybe k -> a -> r -> r) -> r -> Trie (Maybe k) a -> r # trieTraverseWithKey :: Applicative f => (Maybe k -> a -> f b) -> Trie (Maybe k) a -> f (Trie (Maybe k) b) # trieMergeWithKey :: (Maybe k -> a -> b -> Maybe c) -> (Trie (Maybe k) a -> Trie (Maybe k) c) -> (Trie (Maybe k) b -> Trie (Maybe k) c) -> Trie (Maybe k) a -> Trie (Maybe k) b -> Trie (Maybe k) c #
(Show k, Ord k) => TrieKey (OrdKey k) # | `OrdKey` tries are implemented with `Map`, this is intended for cases where it is better for some reason to force the use of a `Map` than to use the generically derived structure.
Associated Types type TrieRep (OrdKey k) :: * -> * # Methods trieEmpty :: Trie (OrdKey k) a # trieNull :: Trie (OrdKey k) a -> Bool # trieLookup :: OrdKey k -> Trie (OrdKey k) a -> Maybe a # trieInsert :: OrdKey k -> a -> Trie (OrdKey k) a -> Trie (OrdKey k) a # trieDelete :: OrdKey k -> Trie (OrdKey k) a -> Trie (OrdKey k) a # trieSingleton :: OrdKey k -> a -> Trie (OrdKey k) a # trieMap :: (a -> b) -> Trie (OrdKey k) a -> Trie (OrdKey k) b # trieTraverse :: Applicative f => (a -> f b) -> Trie (OrdKey k) a -> f (Trie (OrdKey k) b) # trieShowsPrec :: Show a => Int -> Trie (OrdKey k) a -> ShowS # trieMapMaybeWithKey :: (OrdKey k -> a -> Maybe b) -> Trie (OrdKey k) a -> Trie (OrdKey k) b # trieFoldWithKey :: (OrdKey k -> a -> r -> r) -> r -> Trie (OrdKey k) a -> r # trieTraverseWithKey :: Applicative f => (OrdKey k -> a -> f b) -> Trie (OrdKey k) a -> f (Trie (OrdKey k) b) # trieMergeWithKey :: (OrdKey k -> a -> b -> Maybe c) -> (Trie (OrdKey k) a -> Trie (OrdKey k) c) -> (Trie (OrdKey k) b -> Trie (OrdKey k) c) -> Trie (OrdKey k) a -> Trie (OrdKey k) b -> Trie (OrdKey k) c #
(TrieKey a, TrieKey b) => TrieKey (Either a b) # |
Associated Types type TrieRep (Either a b) :: * -> * # Methods trieEmpty :: Trie (Either a b) a # trieNull :: Trie (Either a b) a -> Bool # trieLookup :: Either a b -> Trie (Either a b) a -> Maybe a # trieInsert :: Either a b -> a -> Trie (Either a b) a -> Trie (Either a b) a # trieDelete :: Either a b -> Trie (Either a b) a -> Trie (Either a b) a # trieSingleton :: Either a b -> a -> Trie (Either a b) a # trieMap :: (a -> b) -> Trie (Either a b) a -> Trie (Either a b) b # trieTraverse :: Applicative f => (a -> f b) -> Trie (Either a b) a -> f (Trie (Either a b) b) # trieShowsPrec :: Show a => Int -> Trie (Either a b) a -> ShowS # trieMapMaybeWithKey :: (Either a b -> a -> Maybe b) -> Trie (Either a b) a -> Trie (Either a b) b # trieFoldWithKey :: (Either a b -> a -> r -> r) -> r -> Trie (Either a b) a -> r # trieTraverseWithKey :: Applicative f => (Either a b -> a -> f b) -> Trie (Either a b) a -> f (Trie (Either a b) b) # trieMergeWithKey :: (Either a b -> a -> b -> Maybe c) -> (Trie (Either a b) a -> Trie (Either a b) c) -> (Trie (Either a b) b -> Trie (Either a b) c) -> Trie (Either a b) a -> Trie (Either a b) b -> Trie (Either a b) c #
(TrieKey a, TrieKey b) => TrieKey (a, b) # |
Associated Types type TrieRep (a, b) :: * -> * # Methods trieEmpty :: Trie (a, b) a # trieNull :: Trie (a, b) a -> Bool # trieLookup :: (a, b) -> Trie (a, b) a -> Maybe a # trieInsert :: (a, b) -> a -> Trie (a, b) a -> Trie (a, b) a # trieDelete :: (a, b) -> Trie (a, b) a -> Trie (a, b) a # trieSingleton :: (a, b) -> a -> Trie (a, b) a # trieMap :: (a -> b) -> Trie (a, b) a -> Trie (a, b) b # trieTraverse :: Applicative f => (a -> f b) -> Trie (a, b) a -> f (Trie (a, b) b) # trieShowsPrec :: Show a => Int -> Trie (a, b) a -> ShowS # trieMapMaybeWithKey :: ((a, b) -> a -> Maybe b) -> Trie (a, b) a -> Trie (a, b) b # trieFoldWithKey :: ((a, b) -> a -> r -> r) -> r -> Trie (a, b) a -> r # trieTraverseWithKey :: Applicative f => ((a, b) -> a -> f b) -> Trie (a, b) a -> f (Trie (a, b) b) # trieMergeWithKey :: ((a, b) -> a -> b -> Maybe c) -> (Trie (a, b) a -> Trie (a, b) c) -> (Trie (a, b) b -> Trie (a, b) c) -> Trie (a, b) a -> Trie (a, b) b -> Trie (a, b) c #
(TrieKey a, TrieKey b, TrieKey c) => TrieKey (a, b, c) # |
Associated Types type TrieRep (a, b, c) :: * -> * # Methods trieEmpty :: Trie (a, b, c) a # trieNull :: Trie (a, b, c) a -> Bool # trieLookup :: (a, b, c) -> Trie (a, b, c) a -> Maybe a # trieInsert :: (a, b, c) -> a -> Trie (a, b, c) a -> Trie (a, b, c) a # trieDelete :: (a, b, c) -> Trie (a, b, c) a -> Trie (a, b, c) a # trieSingleton :: (a, b, c) -> a -> Trie (a, b, c) a # trieMap :: (a -> b) -> Trie (a, b, c) a -> Trie (a, b, c) b # trieTraverse :: Applicative f => (a -> f b) -> Trie (a, b, c) a -> f (Trie (a, b, c) b) # trieShowsPrec :: Show a => Int -> Trie (a, b, c) a -> ShowS # trieMapMaybeWithKey :: ((a, b, c) -> a -> Maybe b) -> Trie (a, b, c) a -> Trie (a, b, c) b # trieFoldWithKey :: ((a, b, c) -> a -> r -> r) -> r -> Trie (a, b, c) a -> r # trieTraverseWithKey :: Applicative f => ((a, b, c) -> a -> f b) -> Trie (a, b, c) a -> f (Trie (a, b, c) b) # trieMergeWithKey :: ((a, b, c) -> a -> b -> Maybe c) -> (Trie (a, b, c) a -> Trie (a, b, c) c) -> (Trie (a, b, c) b -> Trie (a, b, c) c) -> Trie (a, b, c) a -> Trie (a, b, c) b -> Trie (a, b, c) c #
(TrieKey a, TrieKey b, TrieKey c, TrieKey d) => TrieKey (a, b, c, d) # |
Associated Types type TrieRep (a, b, c, d) :: * -> * # Methods trieEmpty :: Trie (a, b, c, d) a # trieNull :: Trie (a, b, c, d) a -> Bool # trieLookup :: (a, b, c, d) -> Trie (a, b, c, d) a -> Maybe a # trieInsert :: (a, b, c, d) -> a -> Trie (a, b, c, d) a -> Trie (a, b, c, d) a # trieDelete :: (a, b, c, d) -> Trie (a, b, c, d) a -> Trie (a, b, c, d) a # trieSingleton :: (a, b, c, d) -> a -> Trie (a, b, c, d) a # trieMap :: (a -> b) -> Trie (a, b, c, d) a -> Trie (a, b, c, d) b # trieTraverse :: Applicative f => (a -> f b) -> Trie (a, b, c, d) a -> f (Trie (a, b, c, d) b) # trieShowsPrec :: Show a => Int -> Trie (a, b, c, d) a -> ShowS # trieMapMaybeWithKey :: ((a, b, c, d) -> a -> Maybe b) -> Trie (a, b, c, d) a -> Trie (a, b, c, d) b # trieFoldWithKey :: ((a, b, c, d) -> a -> r -> r) -> r -> Trie (a, b, c, d) a -> r # trieTraverseWithKey :: Applicative f => ((a, b, c, d) -> a -> f b) -> Trie (a, b, c, d) a -> f (Trie (a, b, c, d) b) # trieMergeWithKey :: ((a, b, c, d) -> a -> b -> Maybe c) -> (Trie (a, b, c, d) a -> Trie (a, b, c, d) c) -> (Trie (a, b, c, d) b -> Trie (a, b, c, d) c) -> Trie (a, b, c, d) a -> Trie (a, b, c, d) b -> Trie (a, b, c, d) c #
(TrieKey a, TrieKey b, TrieKey c, TrieKey d, TrieKey e) => TrieKey (a, b, c, d, e) # |
Associated Types type TrieRep (a, b, c, d, e) :: * -> * # Methods trieEmpty :: Trie (a, b, c, d, e) a # trieNull :: Trie (a, b, c, d, e) a -> Bool # trieLookup :: (a, b, c, d, e) -> Trie (a, b, c, d, e) a -> Maybe a # trieInsert :: (a, b, c, d, e) -> a -> Trie (a, b, c, d, e) a -> Trie (a, b, c, d, e) a # trieDelete :: (a, b, c, d, e) -> Trie (a, b, c, d, e) a -> Trie (a, b, c, d, e) a # trieSingleton :: (a, b, c, d, e) -> a -> Trie (a, b, c, d, e) a # trieMap :: (a -> b) -> Trie (a, b, c, d, e) a -> Trie (a, b, c, d, e) b # trieTraverse :: Applicative f => (a -> f b) -> Trie (a, b, c, d, e) a -> f (Trie (a, b, c, d, e) b) # trieShowsPrec :: Show a => Int -> Trie (a, b, c, d, e) a -> ShowS # trieMapMaybeWithKey :: ((a, b, c, d, e) -> a -> Maybe b) -> Trie (a, b, c, d, e) a -> Trie (a, b, c, d, e) b # trieFoldWithKey :: ((a, b, c, d, e) -> a -> r -> r) -> r -> Trie (a, b, c, d, e) a -> r # trieTraverseWithKey :: Applicative f => ((a, b, c, d, e) -> a -> f b) -> Trie (a, b, c, d, e) a -> f (Trie (a, b, c, d, e) b) # trieMergeWithKey :: ((a, b, c, d, e) -> a -> b -> Maybe c) -> (Trie (a, b, c, d, e) a -> Trie (a, b, c, d, e) c) -> (Trie (a, b, c, d, e) b -> Trie (a, b, c, d, e) c) -> Trie (a, b, c, d, e) a -> Trie (a, b, c, d, e) b -> Trie (a, b, c, d, e) c #

newtype Trie k a #

A map from keys of type `k`, to values of type `a`.

Constructors

MkTrie (TrieRep k a) |

Instances

TrieKey k => Functor (Trie k) # |
Methods fmap :: (a -> b) -> Trie k a -> Trie k b # (<$) :: a -> Trie k b -> Trie k a #
TrieKey k => Foldable (Trie k) # |
Methods fold :: Monoid m => Trie k m -> m # foldMap :: Monoid m => (a -> m) -> Trie k a -> m # foldr :: (a -> b -> b) -> b -> Trie k a -> b # foldr' :: (a -> b -> b) -> b -> Trie k a -> b # foldl :: (b -> a -> b) -> b -> Trie k a -> b # foldl' :: (b -> a -> b) -> b -> Trie k a -> b # foldr1 :: (a -> a -> a) -> Trie k a -> a # foldl1 :: (a -> a -> a) -> Trie k a -> a # toList :: Trie k a -> [a] # null :: Trie k a -> Bool # length :: Trie k a -> Int # elem :: Eq a => a -> Trie k a -> Bool # maximum :: Ord a => Trie k a -> a # minimum :: Ord a => Trie k a -> a # sum :: Num a => Trie k a -> a # product :: Num a => Trie k a -> a #
TrieKey k => Traversable (Trie k) # |
Methods traverse :: Applicative f => (a -> f b) -> Trie k a -> f (Trie k b) # sequenceA :: Applicative f => Trie k (f a) -> f (Trie k a) # mapM :: Monad m => (a -> m b) -> Trie k a -> m (Trie k b) # sequence :: Monad m => Trie k (m a) -> m (Trie k a) #
(Show a, TrieKey k) => Show (Trie k a) # |
Methods showsPrec :: Int -> Trie k a -> ShowS # show :: Trie k a -> String # showList :: [Trie k a] -> ShowS #

newtype OrdKey k #

Tries indexed by `OrdKey` will be represented as an ordinary `Map` and the keys will be compared based on the `Ord` instance for `k`.

Constructors

OrdKey |
Fields getOrdKey :: k

Instances

Eq k => Eq (OrdKey k) # |
Methods (==) :: OrdKey k -> OrdKey k -> Bool # (/=) :: OrdKey k -> OrdKey k -> Bool #
Ord k => Ord (OrdKey k) # |
Methods compare :: OrdKey k -> OrdKey k -> Ordering # (<) :: OrdKey k -> OrdKey k -> Bool # (<=) :: OrdKey k -> OrdKey k -> Bool # (>) :: OrdKey k -> OrdKey k -> Bool # (>=) :: OrdKey k -> OrdKey k -> Bool # max :: OrdKey k -> OrdKey k -> OrdKey k # min :: OrdKey k -> OrdKey k -> OrdKey k #
Read k => Read (OrdKey k) # |
Methods readsPrec :: Int -> ReadS (OrdKey k) # readList :: ReadS [OrdKey k] # readPrec :: ReadPrec (OrdKey k) # readListPrec :: ReadPrec [OrdKey k] #
Show k => Show (OrdKey k) # |
Methods showsPrec :: Int -> OrdKey k -> ShowS # show :: OrdKey k -> String # showList :: [OrdKey k] -> ShowS #
(Show k, Ord k) => TrieKey (OrdKey k) # | `OrdKey` tries are implemented with `Map`, this is intended for cases where it is better for some reason to force the use of a `Map` than to use the generically derived structure.
Associated Types type TrieRep (OrdKey k) :: * -> * # Methods trieEmpty :: Trie (OrdKey k) a # trieNull :: Trie (OrdKey k) a -> Bool # trieLookup :: OrdKey k -> Trie (OrdKey k) a -> Maybe a # trieInsert :: OrdKey k -> a -> Trie (OrdKey k) a -> Trie (OrdKey k) a # trieDelete :: OrdKey k -> Trie (OrdKey k) a -> Trie (OrdKey k) a # trieSingleton :: OrdKey k -> a -> Trie (OrdKey k) a # trieMap :: (a -> b) -> Trie (OrdKey k) a -> Trie (OrdKey k) b # trieTraverse :: Applicative f => (a -> f b) -> Trie (OrdKey k) a -> f (Trie (OrdKey k) b) # trieShowsPrec :: Show a => Int -> Trie (OrdKey k) a -> ShowS # trieMapMaybeWithKey :: (OrdKey k -> a -> Maybe b) -> Trie (OrdKey k) a -> Trie (OrdKey k) b # trieFoldWithKey :: (OrdKey k -> a -> r -> r) -> r -> Trie (OrdKey k) a -> r # trieTraverseWithKey :: Applicative f => (OrdKey k -> a -> f b) -> Trie (OrdKey k) a -> f (Trie (OrdKey k) b) # trieMergeWithKey :: (OrdKey k -> a -> b -> Maybe c) -> (Trie (OrdKey k) a -> Trie (OrdKey k) c) -> (Trie (OrdKey k) b -> Trie (OrdKey k) c) -> Trie (OrdKey k) a -> Trie (OrdKey k) b -> Trie (OrdKey k) c #
type TrieRep (OrdKey k) # |
type TrieRep (OrdKey k) = Map k

# Generic derivation implementation

genericTrieNull :: TrieRep k ~ TrieRepDefault k => Trie k a -> Bool #

Generic implementation of `trieNull`. This is the default implementation.

genericTrieMap :: (GTrieKey (Rep k), TrieRep k ~ TrieRepDefault k) => (a -> b) -> Trie k a -> Trie k b #

Generic implementation of `trieMap`. 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 `trieTraverse`. This is the default implementation.

genericTrieShowsPrec :: (Show a, GTrieKeyShow (Rep k), TrieRep k ~ TrieRepDefault k) => Int -> Trie k a -> ShowS #

Generic implementation of `trieShowsPrec`. 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 `insert`. This is the default implementation.

genericLookup :: (GTrieKey (Rep k), Generic k, TrieRep k ~ TrieRepDefault k) => k -> Trie k a -> Maybe a #

Generic implementation of `lookup`. 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 `delete`. 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 `mapMaybe`. This is the default implementation.

genericSingleton :: (GTrieKey (Rep k), Generic k, TrieRep k ~ TrieRepDefault k) => k -> a -> Trie k a #

Generic implementation of `singleton`. This is the default implementation.

genericEmpty :: TrieRep k ~ TrieRepDefault k => Trie k a #

Generic implementation of `empty`. 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 `foldWithKey`. 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) #

Generic implementation of `traverseWithKey`. This is the default implementation.

type TrieRepDefault k = Compose Maybe (GTrie (Rep k)) #

The default implementation of a `TrieRep` is `GTrie` wrapped in a `Maybe`. This wrapping is due to the `GTrie` being a non-empty trie allowing all the of the "emptiness" to be represented at the top level for any given generically implemented key.

class GTrieKey f where #

TrieKey operations on Generic representations used to provide the default implementations of tries.

Minimal complete definition

gtrieLookup, gtrieInsert, gtrieSingleton, gtrieDelete, gtrieMap, gtrieTraverse, gmapMaybeWithKey, gfoldWithKey, gtraverseWithKey, gmergeWithKey

Methods

gtrieLookup :: f p -> GTrie f a -> Maybe a #

gtrieInsert :: f p -> a -> GTrie f a -> GTrie f a #

gtrieSingleton :: f p -> a -> GTrie f a #

gtrieDelete :: f p -> GTrie f a -> Maybe (GTrie f a) #

gtrieMap :: (a -> b) -> GTrie f a -> GTrie f b #

gtrieTraverse :: Applicative m => (a -> m b) -> GTrie f a -> m (GTrie f b) #

gmapMaybeWithKey :: (f p -> a -> Maybe b) -> GTrie f a -> Maybe (GTrie f b) #

gfoldWithKey :: (f p -> a -> r -> r) -> r -> GTrie f a -> r #

gtraverseWithKey :: Applicative m => (f p -> a -> m b) -> GTrie f a -> m (GTrie f b) #

gmergeWithKey :: (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) #

Instances

GTrieKey V1 # | Tries of types without constructors are represented by a unit.
Methods gtrieLookup :: V1 p -> GTrie V1 a -> Maybe a # gtrieInsert :: V1 p -> a -> GTrie V1 a -> GTrie V1 a # gtrieSingleton :: V1 p -> a -> GTrie V1 a # gtrieDelete :: V1 p -> GTrie V1 a -> Maybe (GTrie V1 a) # gtrieMap :: (a -> b) -> GTrie V1 a -> GTrie V1 b # gtrieTraverse :: Applicative m => (a -> m b) -> GTrie V1 a -> m (GTrie V1 b) # gmapMaybeWithKey :: (V1 p -> a -> Maybe b) -> GTrie V1 a -> Maybe (GTrie V1 b) # gfoldWithKey :: (V1 p -> a -> r -> r) -> r -> GTrie V1 a -> r # gtraverseWithKey :: Applicative m => (V1 p -> a -> m b) -> GTrie V1 a -> m (GTrie V1 b) # gmergeWithKey :: (V1 p -> a -> b -> Maybe c) -> (GTrie V1 a -> Maybe (GTrie V1 c)) -> (GTrie V1 b -> Maybe (GTrie V1 c)) -> GTrie V1 a -> GTrie V1 b -> Maybe (GTrie V1 c) #
GTrieKey U1 # | Tries of constructors without fields are represented by a single value.
Methods gtrieLookup :: U1 p -> GTrie U1 a -> Maybe a # gtrieInsert :: U1 p -> a -> GTrie U1 a -> GTrie U1 a # gtrieSingleton :: U1 p -> a -> GTrie U1 a # gtrieDelete :: U1 p -> GTrie U1 a -> Maybe (GTrie U1 a) # gtrieMap :: (a -> b) -> GTrie U1 a -> GTrie U1 b # gtrieTraverse :: Applicative m => (a -> m b) -> GTrie U1 a -> m (GTrie U1 b) # gmapMaybeWithKey :: (U1 p -> a -> Maybe b) -> GTrie U1 a -> Maybe (GTrie U1 b) # gfoldWithKey :: (U1 p -> a -> r -> r) -> r -> GTrie U1 a -> r # gtraverseWithKey :: Applicative m => (U1 p -> a -> m b) -> GTrie U1 a -> m (GTrie U1 b) # gmergeWithKey :: (U1 p -> a -> b -> Maybe c) -> (GTrie U1 a -> Maybe (GTrie U1 c)) -> (GTrie U1 b -> Maybe (GTrie U1 c)) -> GTrie U1 a -> GTrie U1 b -> Maybe (GTrie U1 c) #
TrieKey k => GTrieKey (K1 i k) # | Generic fields are represented by tries of the field type.
Methods gtrieLookup :: K1 i k p -> GTrie (K1 i k) a -> Maybe a # gtrieInsert :: K1 i k p -> a -> GTrie (K1 i k) a -> GTrie (K1 i k) a # gtrieSingleton :: K1 i k p -> a -> GTrie (K1 i k) a # gtrieDelete :: K1 i k p -> GTrie (K1 i k) a -> Maybe (GTrie (K1 i k) a) # gtrieMap :: (a -> b) -> GTrie (K1 i k) a -> GTrie (K1 i k) b # gtrieTraverse :: Applicative m => (a -> m b) -> GTrie (K1 i k) a -> m (GTrie (K1 i k) b) # gmapMaybeWithKey :: (K1 i k p -> a -> Maybe b) -> GTrie (K1 i k) a -> Maybe (GTrie (K1 i k) b) # gfoldWithKey :: (K1 i k p -> a -> r -> r) -> r -> GTrie (K1 i k) a -> r # gtraverseWithKey :: Applicative m => (K1 i k p -> a -> m b) -> GTrie (K1 i k) a -> m (GTrie (K1 i k) b) # gmergeWithKey :: (K1 i k p -> a -> b -> Maybe c) -> (GTrie (K1 i k) a -> Maybe (GTrie (K1 i k) c)) -> (GTrie (K1 i k) b -> Maybe (GTrie (K1 i k) c)) -> GTrie (K1 i k) a -> GTrie (K1 i k) b -> Maybe (GTrie (K1 i k) c) #
(GTrieKey f, GTrieKey g) => GTrieKey ((:+:) f g) # | Generic sums are represented by up to a pair of sub-tries.
Methods gtrieLookup :: (f :+: g) p -> GTrie (f :+: g) a -> Maybe a # gtrieInsert :: (f :+: g) p -> a -> GTrie (f :+: g) a -> GTrie (f :+: g) a # gtrieSingleton :: (f :+: g) p -> a -> GTrie (f :+: g) a # gtrieDelete :: (f :+: g) p -> GTrie (f :+: g) a -> Maybe (GTrie (f :+: g) a) # gtrieMap :: (a -> b) -> GTrie (f :+: g) a -> GTrie (f :+: g) b # gtrieTraverse :: Applicative m => (a -> m b) -> GTrie (f :+: g) a -> m (GTrie (f :+: g) b) # gmapMaybeWithKey :: ((f :+: g) p -> a -> Maybe b) -> GTrie (f :+: g) a -> Maybe (GTrie (f :+: g) b) # gfoldWithKey :: ((f :+: g) p -> a -> r -> r) -> r -> GTrie (f :+: g) a -> r # gtraverseWithKey :: Applicative m => ((f :+: g) p -> a -> m b) -> GTrie (f :+: g) a -> m (GTrie (f :+: g) b) # gmergeWithKey :: ((f :+: g) p -> a -> b -> Maybe c) -> (GTrie (f :+: g) a -> Maybe (GTrie (f :+: g) c)) -> (GTrie (f :+: g) b -> Maybe (GTrie (f :+: g) c)) -> GTrie (f :+: g) a -> GTrie (f :+: g) b -> Maybe (GTrie (f :+: g) c) #
(GTrieKey f, GTrieKey g) => GTrieKey ((:*:) f g) # | Generic products are represented by tries of tries.
Methods gtrieLookup :: (f :*: g) p -> GTrie (f :*: g) a -> Maybe a # gtrieInsert :: (f :*: g) p -> a -> GTrie (f :*: g) a -> GTrie (f :*: g) a # gtrieSingleton :: (f :*: g) p -> a -> GTrie (f :*: g) a # gtrieDelete :: (f :*: g) p -> GTrie (f :*: g) a -> Maybe (GTrie (f :*: g) a) # gtrieMap :: (a -> b) -> GTrie (f :*: g) a -> GTrie (f :*: g) b # gtrieTraverse :: Applicative m => (a -> m b) -> GTrie (f :*: g) a -> m (GTrie (f :*: g) b) # gmapMaybeWithKey :: ((f :*: g) p -> a -> Maybe b) -> GTrie (f :*: g) a -> Maybe (GTrie (f :*: g) b) # gfoldWithKey :: ((f :*: g) p -> a -> r -> r) -> r -> GTrie (f :*: g) a -> r # gtraverseWithKey :: Applicative m => ((f :*: g) p -> a -> m b) -> GTrie (f :*: g) a -> m (GTrie (f :*: g) b) # gmergeWithKey :: ((f :*: g) p -> a -> b -> Maybe c) -> (GTrie (f :*: g) a -> Maybe (GTrie (f :*: g) c)) -> (GTrie (f :*: g) b -> Maybe (GTrie (f :*: g) c)) -> GTrie (f :*: g) a -> GTrie (f :*: g) b -> Maybe (GTrie (f :*: g) c) #
GTrieKey f => GTrieKey (M1 i c f) # | Generic metadata is skipped in trie representation and operations.
Methods gtrieLookup :: M1 i c f p -> GTrie (M1 i c f) a -> Maybe a # gtrieInsert :: M1 i c f p -> a -> GTrie (M1 i c f) a -> GTrie (M1 i c f) a # gtrieSingleton :: M1 i c f p -> a -> GTrie (M1 i c f) a # gtrieDelete :: M1 i c f p -> GTrie (M1 i c f) a -> Maybe (GTrie (M1 i c f) a) # gtrieMap :: (a -> b) -> GTrie (M1 i c f) a -> GTrie (M1 i c f) b # gtrieTraverse :: Applicative m => (a -> m b) -> GTrie (M1 i c f) a -> m (GTrie (M1 i c f) b) # gmapMaybeWithKey :: (M1 i c f p -> a -> Maybe b) -> GTrie (M1 i c f) a -> Maybe (GTrie (M1 i c f) b) # gfoldWithKey :: (M1 i c f p -> a -> r -> r) -> r -> GTrie (M1 i c f) a -> r # gtraverseWithKey :: Applicative m => (M1 i c f p -> a -> m b) -> GTrie (M1 i c f) a -> m (GTrie (M1 i c f) b) # gmergeWithKey :: (M1 i c f p -> a -> b -> Maybe c) -> (GTrie (M1 i c f) a -> Maybe (GTrie (M1 i c f) c)) -> (GTrie (M1 i c f) b -> Maybe (GTrie (M1 i c f) c)) -> GTrie (M1 i c f) a -> GTrie (M1 i c f) b -> Maybe (GTrie (M1 i c f) c) #

data family GTrie (f :: * -> *) a #

Mapping of generic representation of keys to trie structures.

Instances

GTrieKey f => Functor (GTrie f) # |
Methods fmap :: (a -> b) -> GTrie f a -> GTrie f b # (<$) :: a -> GTrie f b -> GTrie f a #
(Show a, GTrieKeyShow f) => Show (GTrie f a) # |
Methods showsPrec :: Int -> GTrie f a -> ShowS # show :: GTrie f a -> String # showList :: [GTrie f a] -> ShowS #
data GTrie V1 # |
data GTrie V1
data GTrie U1 # |
data GTrie U1 = UTrie a
data GTrie (K1 i k) # |
data GTrie (K1 i k) = KTrie (Trie k a)
data GTrie ((:+:) f g) # |
data GTrie ((:+:) f g) = STrieL !(GTrie f a) | STrieR !(GTrie g a) | STrieB !(GTrie f a) !(GTrie g a)
data GTrie ((:*:) f g) # |
data GTrie ((:*:) f g) = PTrie (GTrie f (GTrie g a))
data GTrie (M1 i c f) # |
data GTrie (M1 i c f) = MTrie (GTrie f a)