(* This program is free software; you can redistribute it and/or      *)
(* modify it under the terms of the GNU Lesser General Public License *)
(* as published by the Free Software Foundation; either version 2.1   *)
(* of the License, or (at your option) any later version.             *)
(*                                                                    *)
(* This program is distributed in the hope that it will be useful,    *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of     *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      *)
(* GNU General Public License for more details.                       *)
(*                                                                    *)
(* You should have received a copy of the GNU Lesser General Public   *)
(* License along with this program; if not, write to the Free         *)
(* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *)
(* 02110-1301 USA                                                     *)
(* Contribution to the Coq Library   V6.3 (July 1999)                    *)
(****************************************************************)
(*           The Calculus of Inductive Constructions            *)
(*                       COQ v5.10                              *)
(*                                                              *)
(* Laurent Arditi.  Laboratoire I3S. CNRS ura 1376.             *)
(* Universite de Nice - Sophia Antipolis                        *)
(* arditi@unice.fr, http://wwwi3s.unice.fr/~arditi/lolo.html    *)
(*                                                              *)
(* date: june 1995                                              *)
(* file: Lists_replace                                          *)
(* contents: definition of replace for polymorphic lists        *)
(*                                                              *)
(****************************************************************)
Require Export Lists_field.
Section Lists_replace.
Variable A : Set.
(* Remplace l'element de l a la position par new *)
Fixpoint replace (l : list A) : nat -> A -> list A :=
fun (position : nat) (new : A) =>
match l return (list A) with
| nil =>
(* nil *)  nil | x :: l' => (* (cons x l') *)
match position return (list A) with
| O =>
(* O *)  new :: l' (* (S n') *)
| S n' => x :: replace l' n' new
end
end.

(* Specifications: *)
Lemma replace_ok :
forall (l : list A) (i : nat) (x : A),
i < length l -> elemlist A (replace l i x) i = x :: nil.