feat: add replaceFVars
This commit is contained in:
parent
bbc1f4d461
commit
0511b73d80
2 changed files with 20 additions and 0 deletions
|
|
@ -672,6 +672,10 @@ def replaceFVar (e : Expr) (fvar : Expr) (v : Expr) : Expr :=
|
|||
def replaceFVarId (e : Expr) (fvarId : FVarId) (v : Expr) : Expr :=
|
||||
replaceFVar e (mkFVar fvarId) v
|
||||
|
||||
/-- Replace occurrences of the free variables `fvars` in `e` with `vs` -/
|
||||
def replaceFVars (e : Expr) (fvars : Array Expr) (vs : Array Expr) : Expr :=
|
||||
(e.abstract fvars).instantiateRev vs
|
||||
|
||||
instance : HasToString Expr :=
|
||||
⟨Expr.dbgToString⟩
|
||||
|
||||
|
|
|
|||
|
|
@ -137,3 +137,19 @@ check (isDefEq m expected);
|
|||
pure ()
|
||||
|
||||
#eval tst6
|
||||
|
||||
def tst7 : MetaM Unit := do
|
||||
print "----- tst7 -----";
|
||||
let nat := mkConst `Nat;
|
||||
withLocalDeclD `x nat fun x =>
|
||||
withLocalDeclD `y nat fun y => do
|
||||
val ← mkAppM `HasAdd.add #[x, y];
|
||||
print val;
|
||||
let val := val.replaceFVars #[x, y] #[mkNatLit 0, mkNatLit 1];
|
||||
print val;
|
||||
expected ← mkAppM `HasAdd.add #[mkNatLit 0, mkNatLit 1];
|
||||
print expected;
|
||||
check (pure $ val == expected);
|
||||
pure ()
|
||||
|
||||
#eval tst7
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue