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

GraphRewriting.Rule

Description

Rewrite rules are represented as nested monads: a Rule is a Pattern that returns a Rewrite the latter directly defining the transformation of the graph.

For rule construction a few functions a provided: The most primitive one is rewrite. In most cases erase, rewire, and replace should be more convenient. These functions express rewrites that replace the matched nodes of the Pattern, which comes quite close to the L -> R form in which graph rewriting rules are usually expressed.

Synopsis

Documentation

data Replace n a Source #

Instances

Instances details
Applicative (Replace n) Source # 
Instance details

Defined in GraphRewriting.Rule

Methods

pure :: a -> Replace n a #

(<*>) :: Replace n (a -> b) -> Replace n a -> Replace n b #

liftA2 :: (a -> b -> c) -> Replace n a -> Replace n b -> Replace n c #

(*>) :: Replace n a -> Replace n b -> Replace n b #

(<*) :: Replace n a -> Replace n b -> Replace n a #

Functor (Replace n) Source # 
Instance details

Defined in GraphRewriting.Rule

Methods

fmap :: (a -> b) -> Replace n a -> Replace n b #

(<$) :: a -> Replace n b -> Replace n a #

Monad (Replace n) Source # 
Instance details

Defined in GraphRewriting.Rule

Methods

(>>=) :: Replace n a -> (a -> Replace n b) -> Replace n b #

(>>) :: Replace n a -> Replace n b -> Replace n b #

return :: a -> Replace n a #

Monoid (Replace n ()) Source # 
Instance details

Defined in GraphRewriting.Rule

Methods

mempty :: Replace n () #

mappend :: Replace n () -> Replace n () -> Replace n () #

mconcat :: [Replace n ()] -> Replace n () #

Semigroup (Replace n ()) Source # 
Instance details

Defined in GraphRewriting.Rule

Methods

(<>) :: Replace n () -> Replace n () -> Replace n () #

sconcat :: NonEmpty (Replace n ()) -> Replace n () #

stimes :: Integral b => b -> Replace n () -> Replace n () #

type Rule n = Pattern n (Rewrite n ()) Source #

A rewriting rule is defined as a Pattern that returns a Rewrite

apply :: Rule n -> Rewrite n () Source #

Apply rule at an arbitrary position if applicable

apply' :: Rule n -> Rewrite n Bool Source #

Apply rule at an arbitrary position. Return value states whether the rule was applicable.

rewrite :: (Match -> Rewrite n a) -> Rule n Source #

primitive rule construction with the matched nodes of the left hand side as a parameter

erase :: View [Port] n => Rule n Source #

constructs a rule that deletes all of the matched nodes from the graph

rewire :: View [Port] n => [[Edge]] -> Rule n Source #

Constructs a rule from a list of rewirings. Each rewiring specifies a list of hyperedges that are to be merged into a single hyperedge. All matched nodes of the left-hand side are removed.

replace :: View [Port] n => Replace n () -> Rule n Source #

byNode :: (View [Port] n, View v n) => v -> Replace n () Source #

byNewNode :: View [Port] n => n -> Replace n () Source #

byWire :: Edge -> Edge -> Replace n () Source #

(>>>) :: Rule n -> Rule n -> Rule n Source #

Apply two rules consecutively. Second rule is only applied if first one succeeds. Fails if (and only if) first rule fails.

exhaustive :: Rule n -> Rule n Source #

Make a rule exhaustive, i.e. such that (when applied) it reduces redexes until no redexes are occur in the graph.

everywhere :: Rule n -> Rule n Source #

Make a rule parallel, i.e. such that (when applied) all current redexes are contracted one by one. Neither new redexes or destroyed redexes are reduced.

benchmark :: [Rule n] -> Rewrite n [Int] Source #

Repeatedly apply the rules from the given list prefering earlier entries. Returns a list of indexes reporting the sequence of rules that has applied.

Orphan instances

Applicative (Replace n) Source # 
Instance details

Methods

pure :: a -> Replace n a #

(<*>) :: Replace n (a -> b) -> Replace n a -> Replace n b #

liftA2 :: (a -> b -> c) -> Replace n a -> Replace n b -> Replace n c #

(*>) :: Replace n a -> Replace n b -> Replace n b #

(<*) :: Replace n a -> Replace n b -> Replace n a #

Functor (Replace n) Source # 
Instance details

Methods

fmap :: (a -> b) -> Replace n a -> Replace n b #

(<$) :: a -> Replace n b -> Replace n a #

Monad (Replace n) Source # 
Instance details

Methods

(>>=) :: Replace n a -> (a -> Replace n b) -> Replace n b #

(>>) :: Replace n a -> Replace n b -> Replace n b #

return :: a -> Replace n a #

Monoid (Replace n ()) Source # 
Instance details

Methods

mempty :: Replace n () #

mappend :: Replace n () -> Replace n () -> Replace n () #

mconcat :: [Replace n ()] -> Replace n () #

Semigroup (Replace n ()) Source # 
Instance details

Methods

(<>) :: Replace n () -> Replace n () -> Replace n () #

sconcat :: NonEmpty (Replace n ()) -> Replace n () #

stimes :: Integral b => b -> Replace n () -> Replace n () #