(************************************************************************)
(*  v      *   The Coq Proof Assistant  /  The Coq Development Team     *)
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
(*   \VV/  **************************************************************)
(*    //   *      This file is distributed under the terms of the       *)
(*         *       GNU Lesser General Public License Version 2.1        *)
(************************************************************************)
(*i 	$Id$	 i*)
(** Definition of finite sets as trees indexed by adresses *)
Global Set Asymmetric Patterns.
(* The type [ad] of addresses is now [N] in [BinNat]. *)
Definition ad := N.
(* a Notation or complete replacement would be nice, but that would changes hyps names *)
Section MapDefs.
(** We now define maps from ad to A. *)
Variable A : Type.
Inductive Map :=
| M0 : Map
| M1 : ad -> A -> Map
| M2 : Map -> Map -> Map.

Lemma option_sum : forall o:option A, {y : A | o = Some y} + {o = None}.
Fixpoint MapGet (m:Map) : ad -> option A :=
match m with
| M0 => fun a:ad => None
| M1 x y => fun a:ad => if Neqb x a then Some y else None
| M2 m1 m2 =>
fun a:ad =>
match a with
| N0 => MapGet m1 N0
| Npos xH => MapGet m2 N0
| Npos (xO p) => MapGet m1 (Npos p)
| Npos (xI p) => MapGet m2 (Npos p)
end
end.