graph-rewriting-0.8.0: Monadic graph rewriting of hypergraphs with ports and multiedges
Safe HaskellSafe-Inferred
LanguageHaskell2010

GraphRewriting.Pattern

Description

Patterns allow monadic scrutinisation of the graph (modifications are not possible) while keeping track of matched nodes (history). A Pattern is interpreted by runPattern that returns a result for each position in the graph where the pattern matches. It is allowed to fail inside the Pattern monad, indicating that the pattern does not match, which corresponds to conditional rewriting.

Synopsis

Documentation

type Pattern n = PatternT n Identity Source #

A pattern represents a graph scrutinisation that memorises all the scrutinised nodes during matching.

runPatternT :: PatternT n m a -> Graph n -> m [(Match, a)] Source #

runPattern :: Pattern n a -> Graph n -> [(Match, a)] Source #

Apply a pattern on a graph returning a result for each matching position in the graph together with the matched nodes.

evalPattern :: Pattern n a -> Graph n -> [a] Source #

branch :: Monad m => [a] -> PatternT n m a Source #

Something like an implicit monadic map

branchNodes :: MonadFail m => [Node] -> PatternT n m Node Source #

branch on each node, add it to the history, and return it

probe :: Monad m => PatternT n m a -> PatternT n m Bool Source #

Probe whether a pattern matches somewhere on the graph. You might want to combine this with amnesia.

matches :: Monad m => PatternT n m a -> PatternT n m [Match] Source #

probe a pattern returning the matches it has on the graph. You might want to combine this with amnesia.

match :: Monad m => PatternT n m a -> PatternT n m [(Match, a)] Source #

probe a pattern returning the matches it has on the graph. You might want to combine this with amnesia.

anyOf :: Alternative f => [f a] -> f a Source #

choice over a list of patterns

require :: MonadFail m => Bool -> m () Source #

conditional rewriting: fail when predicate is not met

requireFailure :: MonadFail m => PatternT n m a -> PatternT n m () Source #

fail if given pattern succeeds, succeed if it fails.

requireM :: MonadFail m => m Bool -> m () Source #

fail when monadic predicate is not met

liftReader :: Monad m => Reader (Graph n) a -> PatternT n m a Source #

Lift a scrutinisation from Reader to Pattern leaving the history unchanged.

node :: (MonadFail m, View v n) => PatternT n m v Source #

any node anywhere in the graph

nodeAt :: (Monad m, View v n) => Node -> PatternT n m v Source #

A specific node

edge :: Monad m => PatternT n m Edge Source #

any edge anywhere in the graph

nodeWith :: (MonadFail m, View v n) => Edge -> PatternT n m v Source #

node that is connected to given edge

edgeOf :: (Monad m, View [Port] n) => Node -> PatternT n m Edge Source #

edge that is attached to given node

neighbour :: MonadFail m => (View [Port] n, View v n) => Node -> PatternT n m v Source #

node that is connected to the given node, but not that node itself

relative :: (MonadFail m, View [Port] n, View v n) => Node -> PatternT n m v Source #

node that is connected to the given node, permitting the node itself

adverse :: (MonadFail m, View [Port] n, View v n) => Port -> Node -> PatternT n m v Source #

nodes connected to given port of the specified node, not including the node itself. Consider as an alternative linear combined with nodeWith.

visit :: MonadFail m => Node -> PatternT n m () Source #

A specific node

amnesia :: Monad m => PatternT n m a -> PatternT n m a Source #

Do not remember any of the nodes matched by the supplied pattern

history :: Monad m => PatternT n m Match Source #

list of nodes matched until now with the most recent node in head position

previous :: Monad m => PatternT n m Node Source #

a reference to the lastly matched node

nextFresh :: Monad m => PatternT n m a -> PatternT n m a Source #

only match nodes in the next pattern that have not been matched before

nextIs :: Monad m => Node -> PatternT n m a -> PatternT n m a Source #

only accept the given node in the next match

restrictOverlap :: Monad m => (Match -> Match -> Bool) -> PatternT n m a -> PatternT n m a Source #

Restrict a pattern based on the which of nodes have been matched previously and which nodes will be matched in the future. The first parameter of the supplied function is the history with the most recently matched node in head position. The second parameter is the future with the next matched node in head position.

linear :: Monad m => PatternT n m a -> PatternT n m a Source #

Nodes in the future may not be matched more than once.

data PatternT n m a Source #

A pattern represents a graph scrutinisation that memorises all the scrutinised nodes during matching.

Instances

Instances details
MonadTrans (PatternT n) Source # 
Instance details

Defined in GraphRewriting.Pattern

Methods

lift :: Monad m => m a -> PatternT n m a #

MonadFail m => MonadFail (PatternT n m) Source # 
Instance details

Defined in GraphRewriting.Pattern

Methods

fail :: String -> PatternT n m a #

MonadFail m => Alternative (PatternT n m) Source # 
Instance details

Defined in GraphRewriting.Pattern

Methods

empty :: PatternT n m a #

(<|>) :: PatternT n m a -> PatternT n m a -> PatternT n m a #

some :: PatternT n m a -> PatternT n m [a] #

many :: PatternT n m a -> PatternT n m [a] #

Monad m => Applicative (PatternT n m) Source # 
Instance details

Defined in GraphRewriting.Pattern

Methods

pure :: a -> PatternT n m a #

(<*>) :: PatternT n m (a -> b) -> PatternT n m a -> PatternT n m b #

liftA2 :: (a -> b -> c) -> PatternT n m a -> PatternT n m b -> PatternT n m c #

(*>) :: PatternT n m a -> PatternT n m b -> PatternT n m b #

(<*) :: PatternT n m a -> PatternT n m b -> PatternT n m a #

Monad m => Functor (PatternT n m) Source # 
Instance details

Defined in GraphRewriting.Pattern

Methods

fmap :: (a -> b) -> PatternT n m a -> PatternT n m b #

(<$) :: a -> PatternT n m b -> PatternT n m a #

Monad m => Monad (PatternT n m) Source # 
Instance details

Defined in GraphRewriting.Pattern

Methods

(>>=) :: PatternT n m a -> (a -> PatternT n m b) -> PatternT n m b #

(>>) :: PatternT n m a -> PatternT n m b -> PatternT n m b #

return :: a -> PatternT n m a #

MonadFail m => MonadPlus (PatternT n m) Source # 
Instance details

Defined in GraphRewriting.Pattern

Methods

mzero :: PatternT n m a #

mplus :: PatternT n m a -> PatternT n m a -> PatternT n m a #

MonadFail m => Monoid (PatternT n m a) Source # 
Instance details

Defined in GraphRewriting.Pattern

Methods

mempty :: PatternT n m a #

mappend :: PatternT n m a -> PatternT n m a -> PatternT n m a #

mconcat :: [PatternT n m a] -> PatternT n m a #

MonadFail m => Semigroup (PatternT n m a) Source # 
Instance details

Defined in GraphRewriting.Pattern

Methods

(<>) :: PatternT n m a -> PatternT n m a -> PatternT n m a #

sconcat :: NonEmpty (PatternT n m a) -> PatternT n m a #

stimes :: Integral b => b -> PatternT n m a -> PatternT n m a #

type Pattern n = PatternT n Identity Source #

A pattern represents a graph scrutinisation that memorises all the scrutinised nodes during matching.

type Match = [Node] Source #

Nodes matched in the evaluation of a pattern with the lastly matched node at the head

(<|>) :: Alternative f => f a -> f a -> f a infixl 3 #

An associative binary operation

Orphan instances

MonadFail Identity Source # 
Instance details

Methods

fail :: String -> Identity a #

MonadTrans (PatternT n) Source # 
Instance details

Methods

lift :: Monad m => m a -> PatternT n m a #

MonadFail m => MonadFail (PatternT n m) Source # 
Instance details

Methods

fail :: String -> PatternT n m a #

MonadFail m => Alternative (PatternT n m) Source # 
Instance details

Methods

empty :: PatternT n m a #

(<|>) :: PatternT n m a -> PatternT n m a -> PatternT n m a #

some :: PatternT n m a -> PatternT n m [a] #

many :: PatternT n m a -> PatternT n m [a] #

Monad m => Applicative (PatternT n m) Source # 
Instance details

Methods

pure :: a -> PatternT n m a #

(<*>) :: PatternT n m (a -> b) -> PatternT n m a -> PatternT n m b #

liftA2 :: (a -> b -> c) -> PatternT n m a -> PatternT n m b -> PatternT n m c #

(*>) :: PatternT n m a -> PatternT n m b -> PatternT n m b #

(<*) :: PatternT n m a -> PatternT n m b -> PatternT n m a #

Monad m => Functor (PatternT n m) Source # 
Instance details

Methods

fmap :: (a -> b) -> PatternT n m a -> PatternT n m b #

(<$) :: a -> PatternT n m b -> PatternT n m a #

Monad m => Monad (PatternT n m) Source # 
Instance details

Methods

(>>=) :: PatternT n m a -> (a -> PatternT n m b) -> PatternT n m b #

(>>) :: PatternT n m a -> PatternT n m b -> PatternT n m b #

return :: a -> PatternT n m a #

MonadFail m => MonadPlus (PatternT n m) Source # 
Instance details

Methods

mzero :: PatternT n m a #

mplus :: PatternT n m a -> PatternT n m a -> PatternT n m a #

MonadFail m => Monoid (PatternT n m a) Source # 
Instance details

Methods

mempty :: PatternT n m a #

mappend :: PatternT n m a -> PatternT n m a -> PatternT n m a #

mconcat :: [PatternT n m a] -> PatternT n m a #

MonadFail m => Semigroup (PatternT n m a) Source # 
Instance details

Methods

(<>) :: PatternT n m a -> PatternT n m a -> PatternT n m a #

sconcat :: NonEmpty (PatternT n m a) -> PatternT n m a #

stimes :: Integral b => b -> PatternT n m a -> PatternT n m a #