kure-2.18.6: Combinators for Strategic Programming
Copyright(c) 2012--2021 The University of Kansas
LicenseBSD3
MaintainerNeil Sculthorpe <neil.sculthorpe@ntu.ac.uk>
Stabilitybeta
Portabilityghc
Safe HaskellSafe-Inferred
LanguageHaskell2010

Language.KURE.Path

Description

This module provides several Path abstractions, used for denoting a path through the tree.

Synopsis

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

newtype SnocPath crumb Source #

A SnocPath is a list stored in reverse order.

Constructors

SnocPath [crumb] 

Instances

Instances details
Functor SnocPath Source # 
Instance details

Defined in Language.KURE.Path

Methods

fmap :: (a -> b) -> SnocPath a -> SnocPath b #

(<$) :: a -> SnocPath b -> SnocPath a #

Eq crumb => Eq (SnocPath crumb) Source # 
Instance details

Defined in Language.KURE.Path

Methods

(==) :: SnocPath crumb -> SnocPath crumb -> Bool #

(/=) :: SnocPath crumb -> SnocPath crumb -> Bool #

Show crumb => Show (SnocPath crumb) Source # 
Instance details

Defined in Language.KURE.Path

Methods

showsPrec :: Int -> SnocPath crumb -> ShowS #

show :: SnocPath crumb -> String #

showList :: [SnocPath crumb] -> ShowS #

Semigroup (SnocPath crumb) Source # 
Instance details

Defined in Language.KURE.Path

Methods

(<>) :: SnocPath crumb -> SnocPath crumb -> SnocPath crumb #

sconcat :: NonEmpty (SnocPath crumb) -> SnocPath crumb #

stimes :: Integral b => b -> SnocPath crumb -> SnocPath crumb #

Monoid (SnocPath crumb) Source # 
Instance details

Defined in Language.KURE.Path

Methods

mempty :: SnocPath crumb #

mappend :: SnocPath crumb -> SnocPath crumb -> SnocPath crumb #

mconcat :: [SnocPath crumb] -> SnocPath crumb #

ReadPath (AbsolutePath crumb) crumb Source #

The simplest instance of ReadPath is AbsolutePath itself.

Instance details

Defined in Language.KURE.Path

Methods

absPath :: AbsolutePath crumb -> AbsolutePath crumb Source #

ExtendPath (SnocPath crumb) crumb Source #

Any SnocPath can be extended.

Instance details

Defined in Language.KURE.Path

Methods

(@@) :: SnocPath crumb -> crumb -> SnocPath crumb Source #

class ExtendPath c crumb | c -> crumb where Source #

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 ('' crumb) as an identity operation.

Methods

(@@) :: c -> crumb -> c Source #

Extend the current AbsolutePath by one crumb.

Instances

Instances details
ExtendPath (SnocPath crumb) crumb Source #

Any SnocPath can be extended.

Instance details

Defined in Language.KURE.Path

Methods

(@@) :: SnocPath crumb -> crumb -> SnocPath crumb Source #

(ExtendPath c crumb, ExtendPath e crumb) => ExtendPath (ExtendContext c e) crumb Source #

Both components of the context are updated with the crumb.

Instance details

Defined in Language.KURE.ExtendableContext

Methods

(@@) :: ExtendContext c e -> crumb -> ExtendContext c e Source #

snocPathToPath :: SnocPath crumb -> Path crumb Source #

Convert a SnocPath to a Path. O(n).

pathToSnocPath :: Path crumb -> SnocPath crumb Source #

Convert a Path to a SnocPath. O(n).

lastCrumb :: SnocPath crumb -> Maybe crumb Source #

Get the last crumb from a SnocPath. O(1).

Absolute and Local Paths

type LocalPath = SnocPath Source #

A SnocPath from a local origin.

type AbsolutePath = SnocPath Source #

A SnocPath from the root.

class ReadPath c crumb | c -> crumb where Source #

A class for contexts that store the current AbsolutePath, allowing transformations to depend upon it.

Methods

absPath :: c -> AbsolutePath crumb Source #

Read the current absolute path.

Instances

Instances details
ReadPath (AbsolutePath crumb) crumb Source #

The simplest instance of ReadPath is AbsolutePath itself.

Instance details

Defined in Language.KURE.Path

Methods

absPath :: AbsolutePath crumb -> AbsolutePath crumb Source #

lastCrumbT :: (ReadPath c crumb, MonadFail m) => Transform c m a crumb Source #

Lifted version of lastCrumb.

absPathT :: (ReadPath c crumb, Monad m) => Transform c m a (AbsolutePath crumb) Source #

Lifted version of absPath.