Documentation

Cvc.Untyped.Traverse

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 #

def Cvc.Untyped.foldWith [Ω] {m : Type → Type u_1} {N σ : Type} [Monad m] (present : Term → m N) (t : Term) (init : σ) (pre : N → σ → m (FoldPre σ)) (post : N → σ → m (FoldPost σ)) :
m σ

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
    def Cvc.Untyped.Term.fold [Ω] {m : Type → Type u_1} {V σ : Type} [Monad m] [TermView V] (t : Term) (init : σ) (pre : Term → V → σ → m (FoldPre σ) := fun (x : Term) (x_1 : V) (s : σ) => pure (FoldPre.descend s)) (post : Term → V → σ → m (FoldPost σ) := fun (x : Term) (x_1 : V) (s : σ) => pure (FoldPost.continue s)) :
    m σ

    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.

      Instances For
        structure Cvc.Untyped.ZipperOf [Ω] (P : Type) :

        A position in a term, each node carrying a payload P.

        Instances For
          def Cvc.Untyped.ZipperOf.ofTerm [Ω] {P : Type} (t : Term) (payload : P) :

          A zipper focused on a term's root.

          Equations
          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
                  def Cvc.Untyped.ZipperOf.downWith [Ω] {m : Type → Type u_1} {P : Type} [Monad m] (pay : Term → m P) (z : ZipperOf P) (i : Nat) :

                  Focuses on the i-th kid, if there is one, computing its payload.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    def Cvc.Untyped.ZipperOf.rightWith [Ω] {m : Type → Type u_1} {P : Type} [Monad m] (pay : Term → m P) (z : ZipperOf P) :

                    Focuses on the next sibling, if there is one, computing its payload.

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For
                      def Cvc.Untyped.ZipperOf.leftWith [Ω] {m : Type → Type u_1} {P : Type} [Monad m] (pay : Term → m P) (z : ZipperOf P) :

                      Focuses on the previous sibling, if there is one, computing its payload.

                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For

                        Focuses on the parent, if there is one, rebuilding it if anything below it was replaced.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For
                          partial def Cvc.Untyped.ZipperOf.root [Ω] {P : Type} (z : ZipperOf P) :

                          The whole term, with every replacement made.

                          Replaces the focus, unchecked: the replacement must have the focus's sort.

                          Equations
                          Instances For
                            def Cvc.Untyped.ZipperOf.walkWith [Ω] {m : Type → Type u_1} {P σ : Type} [Monad m] [MonadLiftT Env m] (pay : Term → m P) (z₀ : ZipperOf P) (init : σ) (pre : ZipperOf P → σ → m (WalkPre σ Term)) (post : ZipperOf P → σ → m (WalkPost σ Term)) :
                            m (Term × σ)

                            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 #

                              @[reducible, inline]

                              A position in a sort-erased term.

                              Equations
                              Instances For

                                A sort-erased zipper focused on a term's root.

                                Equations
                                Instances For

                                  Focuses on the i-th kid, if there is one.

                                  Equations
                                  Instances For

                                    Focuses on the next sibling, if there is one.

                                    Equations
                                    Instances For

                                      Focuses on the previous sibling, if there is one.

                                      Equations
                                      Instances For

                                        Fails unless a replacement has the sort of what it replaces.

                                        Equations
                                        • One or more equations did not get rendered due to their size.
                                        Instances For

                                          Replaces the focus, checking that the replacement has the focus's sort.

                                          Equations
                                          Instances For
                                            def Cvc.Untyped.Term.walk [Ω] {m : Type → Type u_1} {V σ : Type} [Monad m] [MonadLiftT Env m] [TermView V] (t : Term) (init : σ) (pre : Zipper → V → σ → m (WalkPre σ Term) := fun (x : Zipper) (x_1 : V) (s : σ) => pure (WalkPre.descend s)) (post : Zipper → V → σ → m (WalkPost σ Term) := fun (x : Zipper) (x_1 : V) (s : σ) => pure (WalkPost.continue s)) :
                                            m (Term × σ)

                                            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.
                                            Instances For