Unlike rewrite, which uses a leftmost outermost strategy for applying
rules and reduces the whole term with equations after each successful rule
rewrite, frewrite attempts to be position fair by making a number of
depth-first traversals of the term. On each traversal, each position that
existed at the start of the traversal is entitled to at most
rule rewrites when its turn comes around. After a rule rewrite succeeds, only
the subterm that was rewritten is reduced with equations in order to avoid
destroying positions that have not yet had their turn for the current traversal.
Traversals are made until
rule rewrites have been made, or
until no more rewrites are possible. When operators have the assoc or
iter attributes,
term depth and positions are relative to the
flattened or compact form of the term, respectively. Thus, fair rewriting
treats a whole stack of an iter operator as a single position for the
purposes of position fairness.
The are a couple of caveats with frewrite:
frewrite [n, k] t . continue m .
produces the same final answer as
frewrite [s, k] t .
when s = n + m. For an erewrite command, the same state information is preserved as for frewrite, but in this case nothing can be guaranteed, due to the interaction with the external environment.