Uniquely merge the graphs, retaining the root from the right.
Uniquely merge the graphs, retaining the root from the left.
A bottom up (leaves first) monoidal fold of the graph.
Note that because this is using SMap, we cannot guarantee uniqueness is handled correctly if nodes include Free.
Note that because this is using SMap, we cannot guarantee uniqueness is handled correctly if nodes include Free. Make sure you do not rely on this. Also please note that this function is linear in the number of nodes, so try not to call it too often.
Removes the src
vertex, replacing any references to it with target
.
Allows rewriting of arbitrary subgraphs.
Allows rewriting of arbitrary subgraphs. Rewrites are applied in a bottom-up (leaves-first) order, which avoids ambiguities when changing nodes that are visible to subsequent rewrites. The one caveat here is that all "changes" to the graph must be additive in nature. You can never remove a node. Rewrites to the definition of a node are valid, but you cannot remove it from the graph, as other nodes will still point to it. This becomes relevant if you want to transform some subgraph g into f(g). When this happens, you must internally generate a new symbol for g and rewrite your subgraph to point to that new g, then the composite graph f(g) must be given the original symbol. As a safety check, because this case is just entirely unsound, the symbol you return at the root is entirely ignored in favor of the original root at that locus.