kure-2.12.0: Combinators for Strategic Programming

Portabilityghc
Stabilitybeta
MaintainerNeil Sculthorpe <neil@ittc.ku.edu>
Safe HaskellSafe-Inferred

Language.KURE.Pathfinder

Contents

Description

This module provides combinators to find LocalPaths sub-nodes specified by a predicate.

Synopsis

Finding Local Paths

Context Transformers

To find a LocalPath to a node that satisfies a predicate, use withLocalPathT (tt (acceptLocalPathT q)), where q is a translation returning Bool, and tt is a traversal strategy, such as collectT or onetdT. This will handle the tracking of the local path. See the example pathfinders below.

type WithLocalPath c crumb = ExtendContext c (LocalPath crumb)Source

A context transformer that adds a LocalPath (from the current node) to the context.

withLocalPathT :: Translate (WithLocalPath c crumb) m a b -> Translate c m a bSource

Apply a translation that stores a LocalPath in the context (starting at the current node).

exposeLocalPathT :: Monad m => Translate (WithLocalPath c crumb) m a (LocalPath crumb)Source

Extract the current LocalPath from the context.

acceptLocalPathT :: Monad m => Translate c m g Bool -> Translate (WithLocalPath c crumb) m g (LocalPath crumb)Source

Return the current LocalPath if the predicate translation succeeds.

Example Pathfinders

pathsToT :: (Walker (WithLocalPath c crumb) g, MonadCatch m) => Translate c m g Bool -> Translate c m g [LocalPath crumb]Source

Find the LocalPaths to every node that satisfies the predicate.

onePathToT :: forall c crumb g m. (Walker (WithLocalPath c crumb) g, MonadCatch m) => Translate c m g Bool -> Translate c m g (LocalPath crumb)Source

Find the LocalPath to the first node that satisfies the predicate (in a pre-order traversal).

oneNonEmptyPathToT :: (Walker (WithLocalPath c crumb) g, MonadCatch m) => Translate c m g Bool -> Translate c m g (LocalPath crumb)Source

Find the LocalPath to the first descendent node that satisfies the predicate (in a pre-order traversal).

prunePathsToT :: (Walker (WithLocalPath c crumb) g, MonadCatch m) => Translate c m g Bool -> Translate c m g [LocalPath crumb]Source

Find the LocalPaths to every node that satisfies the predicate, ignoring nodes below successes.

uniquePathToT :: (Walker (WithLocalPath c crumb) g, MonadCatch m) => Translate c m g Bool -> Translate c m g (LocalPath crumb)Source

Find the LocalPath to the node that satisfies the predicate, failing if that does not uniquely identify a node.

uniquePrunePathToT :: (Walker (WithLocalPath c crumb) g, MonadCatch m) => Translate c m g Bool -> Translate c m g (LocalPath crumb)Source

Build a LocalPath to the node that satisfies the predicate, failing if that does not uniquely identify a node (ignoring nodes below successes).