pred-trie-0.4.0: Predicative tries

Copyright(c) 2015 Athan Clark
LicenseBSD-3
Maintainerathan.clark@gmail.com
Stabilityexperimental
PortabilityGHC
Safe HaskellNone
LanguageHaskell2010

Data.Trie.Pred

Contents

Description

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).

Synopsis

Predicated Trie

data PredTrie s a Source

Constructors

PredTrie 

Fields

predLits :: HashMapStep PredTrie s a

a literal step

predPreds :: PredSteps PredTrie s a

a predicative step

Instances

(Hashable s, Eq s) => Trie NonEmpty s PredTrie Source 
Functor (PredTrie s) Source 
Show (PredTrie s a) Source

Dummy instance for quickcheck

(Hashable s, Eq s) => Monoid (PredTrie s a) Source 
(Arbitrary s, Arbitrary a, Eq s, Hashable s) => Arbitrary (PredTrie s a) Source 

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.

matchesPT :: (Hashable s, Eq s) => NonEmpty s -> PredTrie s a -> [(NonEmpty s, a, [s])] Source

Rooted Predicated Trie

data RootedPredTrie s a Source

Constructors

RootedPredTrie 

Fields

rootedBase :: Maybe a

The "root" node - the path at []

rootedSub :: PredTrie s a

The actual predicative trie

Instances

(Hashable s, Eq s) => Trie [] s RootedPredTrie Source 
Functor (RootedPredTrie s) Source 
(Hashable s, Eq s) => Monoid (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