Copyright | (c) 2015 Athan Clark |
---|---|
License | BSD-3 |
Maintainer | athan.clark@gmail.com |
Stability | experimental |
Portability | GHC |
Safe Haskell | None |
Language | Haskell2010 |
A "predicative" trie is a lookup table where you can embed arbitrary predicates as a method to satisfy a node as "found" - this is done with existential quantification. To embed our predicates, we need to build the trie's data constructors manually, to unify the existential data with the the result function.
As a botched example, you could imagine a "step" of the trie structure as something like this:
PredTrie s a = PNil | forall t. PCons { predicate :: s -> Maybe t , result :: t -> a }
This isn't how it's actually represented, of course - this doesn't acocunt for literal matches (i.e. enumerated results).
- data PredTrie s a = PredTrie {}
- emptyPT :: PredTrie s a
- matchPT :: (Hashable s, Eq s) => NonEmpty s -> PredTrie s a -> Maybe (NonEmpty s, a, [s])
- matchesPT :: (Hashable s, Eq s) => NonEmpty s -> PredTrie s a -> [(NonEmpty s, a, [s])]
- data RootedPredTrie s a = RootedPredTrie {
- rootedBase :: Maybe a
- rootedSub :: PredTrie s a
- emptyRPT :: RootedPredTrie s a
- matchRPT :: (Hashable s, Eq s) => [s] -> RootedPredTrie s a -> Maybe ([s], a, [s])
- matchesRPT :: (Hashable s, Eq s) => [s] -> RootedPredTrie s a -> [([s], a, [s])]
Predicated Trie
matchPT :: (Hashable s, Eq s) => NonEmpty s -> PredTrie s a -> Maybe (NonEmpty s, a, [s]) Source
Find the nearest parent node of the requested query, while returning the split of the string that was matched, and what wasn't.
Rooted Predicated Trie
data RootedPredTrie s a Source
RootedPredTrie | |
|
(Hashable s, Eq s) => Trie [] s RootedPredTrie Source | |
Functor (RootedPredTrie s) Source | |
(Hashable s, Eq s) => Monoid (RootedPredTrie s a) Source |
emptyRPT :: RootedPredTrie s a Source
matchRPT :: (Hashable s, Eq s) => [s] -> RootedPredTrie s a -> Maybe ([s], a, [s]) Source
matchesRPT :: (Hashable s, Eq s) => [s] -> RootedPredTrie s a -> [([s], a, [s])] Source