Safe Haskell | None |
---|---|

Language | Haskell98 |

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.

- data Replace n a
- type Rule n = Pattern n (Rewrite n ())
- apply :: Rule n -> Rewrite n ()
- apply' :: Rule n -> Rewrite n Bool
- rewrite :: (Match -> Rewrite n a) -> Rule n
- erase :: View [Port] n => Rule n
- rewire :: View [Port] n => [[Edge]] -> Rule n
- replace :: View [Port] n => Replace n () -> Rule n
- byNode :: (View [Port] n, View v n) => v -> Replace n ()
- byNewNode :: View [Port] n => n -> Replace n ()
- byEdge :: Replace n Edge
- byWire :: Edge -> Edge -> Replace n ()
- byConnector :: [Edge] -> Replace n ()
- (>>>) :: Rule n -> Rule n -> Rule n
- exhaustive :: Rule n -> Rule n
- everywhere :: Rule n -> Rule n
- benchmark :: [Rule n] -> Rewrite n [Int]

# Documentation

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.

byConnector :: [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.