# Expression Lenses #

Functions for manipulating subexpressions using SubExpr.Pos.

def Lean.Meta.replaceSubexpr {M : } [] [] [] (replace : ) (p : Lean.SubExpr.Pos) (root : Lean.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 : } [] [] [] {α : Type} (visit : Lean.ExprM α) (p : Lean.SubExpr.Pos) (root : Lean.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 : } [] [] [] {α : Type} (k : Lean.ExprNatαM α) (init : α) (p : Lean.SubExpr.Pos) (e : Lean.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 : } [] [] (p : Lean.SubExpr.Pos) (root : Lean.Expr) :

Given a valid SubExpr, will return the raw current expression without performing any instantiation. If the SubExpr has a type subexpression coordinate then will 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 will contain loose bound variables it can't be used in any MetaM methods.

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

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 : } [] [] (p : Lean.SubExpr.Pos) (e : Lean.Expr) :
M Nat

Returns the number of binders above a given subexpr position.

Equations
Instances For