Documentation

Lean.Meta.ExprLens

Expression Lenses #

Functions for manipulating subexpressions using SubExpr.Pos.

def Lean.Meta.replaceSubexpr {M : TypeType} [Monad M] [MonadLiftT MetaM M] [MonadControlT MetaM M] [MonadError M] (replace : ExprM Expr) (p : SubExpr.Pos) (root : Expr) :

Run the given replace function to replace the expression at the subexpression position. If the subexpression is below a binder the bound variables will be appropriately instantiated with free variables and reabstracted after the replacement. If the subexpression is invalid or points to a type then this will throw.

Equations
Instances For
    def Lean.Meta.viewSubexpr {M : TypeType} [Monad M] [MonadLiftT MetaM M] [MonadControlT MetaM M] [MonadError M] {α : Type} (visit : Array ExprExprM α) (p : SubExpr.Pos) (root : Expr) :
    M α

    view visit p e runs visit fvars s where s : Expr is the subexpression of e at p. and fvars are the free variables for the binders that s is under. s is already instantiated with respect to these. The role of the visit function is analogous to the k function in Lean.Meta.forallTelescope.

    Equations
    Instances For
      def Lean.Meta.foldAncestors {M : TypeType} [Monad M] [MonadLiftT MetaM M] [MonadControlT MetaM M] [MonadError M] {α : Type} (k : Array ExprExprNatαM α) (init : α) (p : SubExpr.Pos) (e : Expr) :
      M α

      foldAncestors k init p e folds over the strict ancestor subexpressions of the given expression e above position p, starting at the root expression and working down. The fold function k is given the newly instantiated free variables, the ancestor subexpression, and the coordinate that will be explored next.

      Equations
      Instances For
        def Lean.Core.viewSubexpr {M : TypeType} [Monad M] [MonadError M] (p : SubExpr.Pos) (root : Expr) :

        Given a valid SubExpr, return the raw current expression without performing any instantiation. If the given SubExpr has a type subexpression coordinate, then throw an error.

        This is a cheaper version of Lean.Meta.viewSubexpr and can be used to quickly view the subexpression at a position. Note that because the resulting expression may contain loose bound variables it can't be used in any MetaM methods.

        Equations
        Instances For
          def Lean.Core.viewBinders {M : TypeType} [Monad M] [MonadError M] (p : SubExpr.Pos) (root : Expr) :

          viewBinders p e returns a list of all of the binders (name, type) above the given position p in the root expression e

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            def Lean.Core.numBinders {M : TypeType} [Monad M] [MonadError M] (p : SubExpr.Pos) (e : Expr) :
            M Nat

            Returns the number of binders above a given subexpr position.

            Equations
            Instances For