Skip to content

Commit 334cfab

Browse files
committed
made Vector.nth substructural
added test-case
1 parent 31e3587 commit 334cfab

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- **Changed:**
2+
implementation of :g:`Vector.nth` to follow OCaml and compute strict subterms
3+
(`#16731 <https://github.com/coq/coq/pull/16731>`_,
4+
fixes `#16738 <https://github.com/coq/coq/issues/16738>`_,
5+
by Andrej Dudenhefner).

test-suite/bugs/bug_16738.v

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Require Vector.
2+
3+
Inductive container : Type :=
4+
| container_v : Vector.t container 2 -> container
5+
| container_0 : container.
6+
7+
Fixpoint test (c : container) : unit :=
8+
match c with
9+
| container_0 => tt
10+
| container_v v => test (Vector.nth v (Fin.FS Fin.F1))
11+
end.

theories/Vectors/VectorDef.v

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,15 @@ Definition const {A} (a:A) := nat_rect _ [] (fun n x => cons _ a n x).
106106
Computational behavior of this function should be the same as
107107
ocaml function. *)
108108
Definition nth {A} :=
109-
fix nth_fix {m} (v' : t A m) (p : Fin.t m) {struct v'} : A :=
110-
match p in Fin.t m' return t A m' -> A with
111-
|Fin.F1 => caseS (fun n v' => A) (fun h n t => h)
112-
|Fin.FS p' => fun v => (caseS (fun n v' => Fin.t n -> A)
113-
(fun h n t p0 => nth_fix t p0) v) p'
114-
end v'.
109+
fix nth_fix {n : nat} (v : t A n) {struct v} : Fin.t n -> A :=
110+
match v with
111+
| nil _ => fun p => False_rect A (Fin.case0 _ p)
112+
| cons _ x m v' => fun p =>
113+
match p in (Fin.t m') return t A (pred m') -> A with
114+
| Fin.F1 => fun _ => x
115+
| Fin.FS p' => fun v' => nth_fix v' p'
116+
end v'
117+
end.
115118

116119
(** An equivalent definition of [nth]. *)
117120
Definition nth_order {A} {n} (v: t A n) {p} (H: p < n) :=

0 commit comments

Comments
 (0)