-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector.v
More file actions
59 lines (51 loc) · 1.71 KB
/
vector.v
File metadata and controls
59 lines (51 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
Require Coq.Vectors.Vector.
Import Vector.VectorNotations.
Check Vector.t.
Print Vector.t.
Check Vector.cons.
Definition hd {A : Type} {n : nat} (v : Vector.t A (S n)) : A :=
match v with
| a :: _ => a
end.
Check hd.
Print hd.
Definition tl {A : Type} {n : nat} (v : Vector.t A (S n)) : Vector.t A n :=
match v with
| _ :: v' => v'
end.
Check tl.
Print tl.
Check IDProp.
Print IDProp.
Check Vector.map.
Fixpoint my_map {A B : Type} (f : A -> B) {n : nat} (v : Vector.t A n) : Vector.t B n :=
match v with
| [] => []
| a::v' => f a :: my_map f v'
end.
(*Section Zip.*)
(* Context {A B C : Type}.*)
(* Context {f : A -> B -> C}.*)
(* Fixpoint zip {n : nat} (u : Vector.t A n) (v : Vector.t B n) : Vector.t C n :=*)
(* match u, v with*)
(* | x::xs, y::ys => f x y :: zip xs ys*)
(* | [], _ => []*)
(* end.*)
(*End Zip.*)
(* The elaborator is not able to translate the above definition like it did in the case of the hd function and Gallina rejects it as all cases are not exhaustively matched *)
(* In general, looking at the types and deducing the possible branches is undecidable (higher order unification problem). The elaborator just takes care of a few simple cases *)
Section Zip.
Context {A B C : Type}.
Context {f : A -> B -> C}.
Fixpoint zip {n : nat} (u : Vector.t A n) : Vector.t B n -> Vector.t C n :=
(*refine (match u with*)
(* | [] => fun _ => []*)
(* | x::xs => fun v: Vector.t B (S _) => f x (hd v) :: zip xs (tl v)*)
(* end).*)
match u with
| [] => fun _ => []
| x::xs => fun v => f x (hd v) :: zip xs (tl v)
end.
Check zip.
Print zip.
End Zip.