Section INSTANCES.
#[global]
Instance vector_hasEqDec {A : Type} {n : nat}
(A_hasEqDec : hasEqDec A)
: hasEqDec (Vector.t A n).
#[local]
Instance vec_isSetoid (n : nat) (A : Type) `(SETOID : isSetoid A) : isSetoid (vec n A) :=
{ eqProp (lhs : vec n A) (rhs : vec n A) := forall i : Fin.t n, lhs !! i == rhs !! i
; eqProp_Equivalence := relation_on_image_liftsEquivalence (pi_isSetoid (fun _ => SETOID)).(eqProp_Equivalence) nth
}.
#[local]
Instance vec_isSetoid1 {n : nat} : isSetoid1 (vec n) :=
vec_isSetoid n.
#[global]
Instance vec_satisfiesMonadLaws {n : nat}
: @MonadLaws (vec n) vec_isSetoid1 vec_isMonad.
End INSTANCES.
Fixpoint foldr {A : Type} {B : Type} {n : nat} (f : A -> B -> B) (z : B) (xs : Vector.t A n) : B :=
match xs with
| [] => z
| x :: xs => f x (foldr f z xs)
end.
Fixpoint from_list (xs : list A) {struct xs} : Vector.t A (L.length xs) :=
match xs with
| L.nil => []
| L.cons x xs => x :: from_list xs
end.
Inductive vec_heq (n : nat) (xs : Vector.t A n) : forall m : nat, Vector.t A m -> Prop :=
| vec_ext_heq_refl
: vec_heq n xs n xs.
#[local] Notation " xs =~= xs' " := (vec_heq _ xs _ xs') : type_scope.
#[local] Hint Constructors vec_heq : core.
End HEQ.
Fixpoint snoc {A : Type} {n : nat} (xs : Vector.t A n) (x : A) {struct xs} : Vector.t A (S n) :=
match xs with
| [] => [x]
| x' :: xs' => x' :: snoc xs' x
end.
Fixpoint rev {A : Type} {n : nat} (xs : Vector.t A n) {struct xs} : Vector.t A n :=
match xs with
| [] => []
| x :: xs => snoc (rev xs) x
end.

Lemma to_list_rev {A : Type} {n : nat} (xs : Vector.t A n)
: to_list (rev xs) = L.rev (to_list xs).