Debian Codegraph @

src/Util/Tactics/CountBinders.v

raw
1 Require Export Crypto.Util.FixCoqMistakes.
2
3 Ltac count_binders_gen eval_tac v :=
4 let v := eval_tac v in
5 lazymatch v with
6 | fun x : ?T => ?F
7 => let x' := fresh in
8 lazymatch constr:(fun x' : T => ltac:(let f := constr:(match x' return _ with x => F end) in
9 let v := count_binders_gen eval_tac f in
10 exact (S v))) with
11 | fun _ => ?v => v
12 | ?val => fail 0 "Cannot eliminate functional dependencies of" val
13 end
14 | forall x, @?F x => count_binders_gen eval_tac F
15 | _ => O
16 end.
17
18 Ltac count_binders_hnf v := count_binders_gen ltac:(fun v => eval hnf in v) v.
19 Ltac count_binders v := count_binders_gen ltac:(fun v => v) v.