(* "replist" is an alternative to zlist, avoids mysterious typeclass *)
Fixpoint replist' {A: Type} {d: Inhabitant A} (lo: Z) (n: nat) (al: list A) :=
match n with
| O => nil
| S n' =>  Znth lo al :: replist' (Z.succ lo) n' al
end.
Definition replist {cs: compspecs} (t: type)  (lo hi: Z) (al: list (reptype t)) :=
replist'  lo (Z.to_nat (hi-lo)) al.
(* replist t lo hi al *)

(* Specifications: *)
Lemma replist_replist {cs: compspecs}:
forall t (lo hi lo' hi': Z) al,
0 <= lo <= hi ->
0 <= lo' <= hi' ->
lo'+hi <= hi'  ->
replist t lo hi (replist t lo' hi' al) =
replist t (lo+lo') (hi+lo') al.
Lemma replist'_succ:
forall {A} {d:Inhabitant A} lo n r al,
(lo>=0) -> replist' (Z.succ lo) n (r::al) = replist' lo n al.
Lemma replist_firstn_skipn {cs: compspecs}:
forall t lo hi al,
(lo <= hi <= length al)%nat ->
replist t (Z.of_nat lo) (Z.of_nat hi) al = firstn (hi-lo) (skipn lo al).
Lemma skipn_0:
forall A (al: list A) n,
(n=0)%nat -> skipn n al = al.
Lemma replist_elim {cs: compspecs}:
forall t lo hi al,
lo = 0 -> hi = Zlength al ->
replist t lo hi al = al.
Lemma replist_Zlength {cs: compspecs}:
forall t lo hi al,
lo <= hi ->
Zlength (replist t lo hi al) = hi-lo.
Lemma replist_length {cs: compspecs}:
forall t lo hi al,
lo <= hi ->
length (replist t lo hi al) = Z.to_nat (hi-lo).