aboutsummaryrefslogtreecommitdiff
path: root/test-suite
diff options
context:
space:
mode:
authorcoqbot-app[bot]2021-03-16 23:10:59 +0000
committerGitHub2021-03-16 23:10:59 +0000
commitf9c6308caa4211aefe571f72c5704edb90e2d0a3 (patch)
treec0ff49ac14f24c338bf0953c53959d41b950fb0c /test-suite
parent1bae837106baedcdaf96bae121616c53f55b25d9 (diff)
parent22be1892ee1b6030cfe9406bf72bb320dbe68be7 (diff)
Merge PR #13920: Adding an Ltac2 API to manipulate inductive types.
Reviewed-by: JasonGross Ack-by: jfehrle
Diffstat (limited to 'test-suite')
-rw-r--r--test-suite/ltac2/ind.v25
1 files changed, 25 insertions, 0 deletions
diff --git a/test-suite/ltac2/ind.v b/test-suite/ltac2/ind.v
new file mode 100644
index 0000000000..6f7352d224
--- /dev/null
+++ b/test-suite/ltac2/ind.v
@@ -0,0 +1,25 @@
+Require Import Ltac2.Ltac2.
+Require Import Ltac2.Option.
+
+Ltac2 Eval
+ let nat := Option.get (Env.get [@Coq; @Init; @Datatypes; @nat]) in
+ let nat := match nat with
+ | Std.IndRef nat => nat
+ | _ => Control.throw Not_found
+ end in
+ let data := Ind.data nat in
+ (* Check that there is only one inductive in the block *)
+ let ntypes := Ind.nblocks data in
+ let () := if Int.equal ntypes 1 then () else Control.throw Not_found in
+ let nat' := Ind.repr (Ind.get_block data 0) in
+ (* Check it corresponds *)
+ let () := if Ind.equal nat nat' then () else Control.throw Not_found in
+ let () := if Int.equal (Ind.index nat) 0 then () else Control.throw Not_found in
+ (* Check the number of constructors *)
+ let nconstr := Ind.nconstructors data in
+ let () := if Int.equal nconstr 2 then () else Control.throw Not_found in
+ (* Create a fresh instance *)
+ let s := Ind.get_constructor data 1 in
+ let s := Env.instantiate (Std.ConstructRef s) in
+ constr:($s 0)
+.