Folding over terms, and walking them with a zipper #
Term.fold visits a term's nodes; Term.walk visits them through a zipper and can replace them.
Both hand each node to the user as its view, the inductive def.term_view V generates, and both
take two optional functions: pre, called on reaching a node, before its kids, and post, called
on leaving it, after them. Each answers what to do next — descend, skip the kids, stop, and for a
walk replace the node — along with the new state.
fold runs in any monad, taking a term apart being pure. walk needs a monad Env lifts
into, to rebuild what it replaced under.
Folding #
Folds over a term's nodes, presented as present builds them.
What Term.fold and its typed counterpart are built on. Depth-first: each node is entered —
pre — then, unless that answered skip, its kids are folded over left to right, and then it is
left — post.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Folds over a term's nodes, in depth-first order, with early exit.
Each node is handed over with its view. Both functions default to carrying on, so a fold passes only
those it needs: pre to act on reaching a node, and to skip its kids; post to act on leaving it,
once its kids are done. Runs in any monad.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The zipper #
A position in a term: the focus, and the path back to the root. Each node carries a payload P,
computed when the zipper reaches it — nothing for the sort-erased Zipper, its sort for the typed
one. Nothing about the path is at the type level: an edit replaces the focus by a term of the same
sort, so every ancestor keeps its sort.
One ancestor of the focus, as the path to the root holds it.
- parent : Cvc.Untyped.Term
- payload : P
- parentDirty : Bool
- left : Cvc.Untyped.Terms
- right : List Cvc.Untyped.Term
- dirty : Bool
Instances For
A position in a term, each node carrying a payload P.
- term : Cvc.Untyped.Term
- payload : P
- dirty : Bool
- path : List (Cvc.Untyped.ZipperOf.Frame P)
Instances For
The focus.
Equations
Instances For
The focus's payload.
Equations
Instances For
How deep the focus is: 0 at the root.
Equations
Instances For
Replaces the focus, unchecked: the replacement must have the focus's sort.
Equations
- z.replaceUnchecked t = { term := t, payload := Cvc.Untyped.ZipperOf.payload✝ z, dirty := true, path := Cvc.Untyped.ZipperOf.path✝ z }
Instances For
Walks a term's nodes through a zipper, presented as the functions see fit.
What Term.walk and its typed counterpart are built on. Depth-first: pre on reaching a node,
then — unless it skipped, replaced or stopped — its kids, then post on leaving it. A replacement
is unchecked; a stop keeps every replacement made. Answers the rebuilt term and the final state.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The sort-erased zipper #
A position in a sort-erased term.
Equations
Instances For
A sort-erased zipper focused on a term's root.
Equations
Instances For
The focus's view.
Instances For
Focuses on the i-th kid, if there is one.
Equations
- Cvc.Untyped.ZipperOf.down z i = (Cvc.Untyped.ZipperOf.downWith (fun (x : Cvc.Untyped.Term) => pure ()) z i).run
Instances For
Focuses on the next sibling, if there is one.
Equations
- Cvc.Untyped.ZipperOf.right z = (Cvc.Untyped.ZipperOf.rightWith (fun (x : Cvc.Untyped.Term) => pure ()) z).run
Instances For
Focuses on the previous sibling, if there is one.
Equations
- Cvc.Untyped.ZipperOf.left z = (Cvc.Untyped.ZipperOf.leftWith (fun (x : Cvc.Untyped.Term) => pure ()) z).run
Instances For
Replaces the focus, checking that the replacement has the focus's sort.
Equations
Instances For
Walks a term's nodes through a zipper, in depth-first order, replacing some.
The same order as Term.fold, and the same two optional functions, each handed the zipper focused
on the node — so it sees the node's context too — and its view, and answering whether to replace it.
A replacement must have the sort of the node it replaces, which is checked. post sees a node
rebuilt with its replaced kids. Answers the rebuilt term with the final state, stop included.
Runs in any monad Env lifts into, since rebuilding a term needs Env.
Equations
- One or more equations did not get rendered due to their size.