algebra-dag-0.1.1.1: Infrastructure for DAG-shaped relational algebra plans

Safe HaskellNone
LanguageHaskell98

Database.Algebra.Rewrite.DagRewrite

Contents

Description

This module provides a monadic interface to rewrites on algebra DAGs.

Synopsis

The Rewrite monad

data Rewrite o e a Source

A Monad for DAG rewrites, parameterized over the type of algebra operators.

runRewrite :: Operator o => Rewrite o e r -> AlgebraDag o -> e -> Bool -> (AlgebraDag o, e, r, Log) Source

Run a rewrite action on the supplied graph. Returns the rewritten node map, the potentially modified list of root nodes, the result of the rewrite and the rewrite log.

initRewriteState :: (Ord o, Operator o) => AlgebraDag o -> e -> Bool -> RewriteState o e Source

type Log = Seq String Source

The log from a sequence of rewrite actions.

logGeneral :: String -> Rewrite o e () Source

Log a general message

logRewrite :: String -> AlgNode -> Rewrite o e () Source

Log a rewrite

reachableNodesFrom :: AlgNode -> Rewrite o e (Set AlgNode) Source

Return the set of nodes that are reachable from the specified node.

parents :: AlgNode -> Rewrite o e [AlgNode] Source

Return the parents of a node

topsort :: Operator o => Rewrite o e [AlgNode] Source

Return a topological ordering of all reachable nodes in the DAG.

operator :: Operator o => AlgNode -> Rewrite o e o Source

Return the operator for a node id.

rootNodes :: Rewrite o e [AlgNode] Source

Returns the root nodes of the DAG.

exposeDag :: Rewrite o e (AlgebraDag o) Source

Exposes the current state of the DAG

updateExtras :: e -> Rewrite o e () Source

condRewrite :: Rewrite o e Bool -> Rewrite o e Bool Source

Preserve the effects of a rewrite only if the rewrite signals success by returning True. Otherwise, the state before the rewrite is put in place again.

insert :: (Operator o, Show o) => o -> Rewrite o e AlgNode Source

Insert an operator into the DAG and return its node id. If the operator is already present (same op, same children), reuse it.

insertNoShare :: Operator o => o -> Rewrite o e AlgNode Source

Insert an operator into the DAG and return its node id WITHOUT reusing an operator if it is already present.

replaceChild :: Operator o => AlgNode -> AlgNode -> AlgNode -> Rewrite o e () Source

replaceChildM n old new replaces all links from node n to node old with links to node new

replace :: Operator o => AlgNode -> AlgNode -> Rewrite o e () Source

replace old new replaces _all_ links to old with links to new

replaceWithNew :: (Operator o, Show o) => AlgNode -> o -> Rewrite o e AlgNode Source

Creates a new node from the operator and replaces the old node with it by rewiring all links to the old node.

infer :: (AlgebraDag o -> b) -> Rewrite o e b Source

Apply a pure function to the DAG.

collect :: (Show o, Operator o) => Rewrite o e () Source