lean4-htt/tests/lean/run/generalizeTelescope.lean
Leonardo de Moura 17b6957f6c chore: fix tests
2020-05-26 15:05:01 -07:00

59 lines
1.5 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Lean
open Lean
open Lean.Meta
inductive Vec (α : Type) : Nat → Type
| nil : Vec 0
| cons {n} : α → Vec n → Vec (n+1)
set_option trace.Meta.debug true
def nat := mkConst `Nat
def succ := mkConst `Nat.succ
def tst1 : MetaM Unit :=
withLocalDecl `n nat BinderInfo.default $ fun n => do
let n1 := mkApp succ n;
let vecN1 := mkApp2 (mkConst `Vec) nat n1;
withLocalDecl `xs vecN1 BinderInfo.default $ fun xs => do
generalizeTelescope #[n1, xs] `aux $ fun ys => do
t ← mkLambda ys ys.back;
trace! `Meta.debug t;
pure ()
#eval tst1
set_option pp.all true
def tst2 : MetaM Unit :=
withLocalDecl `n nat BinderInfo.default $ fun n => do
let n1 := mkApp succ n;
let vecN1 := mkApp2 (mkConst `Vec) nat n1;
withLocalDecl `xs vecN1 BinderInfo.default $ fun xs => do
e ← mkEqRefl xs;
generalizeTelescope #[n1, xs, e] `aux $ fun ys => do
t ← mkLambda ys ys.back;
trace! `Meta.debug t;
pure ()
#eval tst2
def failIfSuccess (x : MetaM Unit) : MetaM Unit :=
whenM (catch (x *> pure true) (fun _ => pure false)) $
throw $ Exception.other "unexpected success"
def tst3 : MetaM Unit :=
withLocalDecl `n nat BinderInfo.default $ fun n => do
let n1 := mkApp succ n;
let vecN1 := mkApp2 (mkConst `Vec) nat n1;
withLocalDecl `xs vecN1 BinderInfo.default $ fun xs => do
e ← mkEqRefl xs;
failIfSuccess $ do {
generalizeTelescope #[n1, e] `aux $ fun ys => do
t ← mkLambda ys ys.back;
trace! `Meta.debug t;
pure ()
};
trace! `Meta.debug "failed as expected"
#eval tst3