Portability | ghc |
---|---|
Stability | beta |
Maintainer | Neil Sculthorpe <neil@ittc.ku.edu> |
Safe Haskell | Safe-Inferred |
This module provides several Path abstractions, used for denoting a path through the tree.
- type Path crumb = [crumb]
- newtype SnocPath crumb = SnocPath [crumb]
- class ExtendPath c crumb | c -> crumb where
- (@@) :: c -> crumb -> c
- snocPathToPath :: SnocPath crumb -> Path crumb
- pathToSnocPath :: Path crumb -> SnocPath crumb
- lastCrumb :: SnocPath crumb -> Maybe crumb
- type LocalPath = SnocPath
- type AbsolutePath = SnocPath
- class ReadPath c crumb | c -> crumb where
- absPath :: c -> AbsolutePath crumb
- lastCrumbT :: (ReadPath c crumb, Monad m) => Translate c m a crumb
- absPathT :: (ReadPath c crumb, Monad m) => Translate c m a (AbsolutePath crumb)
Paths
A crumb
is a value that denotes which child node to descended into.
That is, a path through a tree is specified by a "trail of breadcrumbs".
For example, if the children are numbered, Int
could be used as the crumb
type.
SnocPath
is useful for recording where you have been, as it is cheap to keep adding to the end of the list as you travel further.
Path
is useful for recording where you intend to go, as you'll need to access it in order.
Relative Paths
type Path crumb = [crumb]Source
A Path
is just a list.
The intent is that a path represents a route through the tree from an arbitrary node.
Snoc Paths
A SnocPath
is a list stored in reverse order.
SnocPath [crumb] |
Eq crumb => Eq (SnocPath crumb) | |
Show crumb => Show (SnocPath crumb) | |
Monoid (SnocPath crumb) | |
ReadPath (AbsolutePath crumb) crumb | The simplest instance of |
ExtendPath (SnocPath crumb) crumb | Any |
class ExtendPath c crumb | c -> crumb whereSource
A class of things that can be extended by crumbs.
Typically, c
is a context type.
The typical use is to extend an AbsolutePath
stored in the context (during tree traversal).
Note however, that if an AbsolutePath
is not stored in the context, an instance can still be declared with (
as an identity operation.
@@
crumb)
Extend the current AbsolutePath
by one crumb.
ExtendPath (SnocPath crumb) crumb | Any |
(ExtendPath c crumb, ExtendPath e crumb) => ExtendPath (ExtendContext c e) crumb | Both components of the context are updated with the crumb. |
Absolute and Local Paths
type AbsolutePath = SnocPathSource
A SnocPath
from the root.
class ReadPath c crumb | c -> crumb whereSource
A class for contexts that store the current AbsolutePath
, allowing transformations to depend upon it.
absPath :: c -> AbsolutePath crumbSource
Read the current absolute path.
ReadPath (AbsolutePath crumb) crumb | The simplest instance of |