(* Copyright 2010 IMDEA Software Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *)
(******************************************************************************)
(* This file defines finitely supported maps with keys drawn from             *)
(* an ordered type and values from an arbitrary type.                         *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Section Def.
Variables (K : ordType) (V : Type).
Definition key (x : K * V) := x.1.
Definition value (x : K * V) := x.2.
Definition predk k := preim key (pred1 k).
Definition predCk k := preim key (predC1 k).
Record finMap := FinMap {
seq_of : seq (K * V);
_ : sorted ord (map key seq_of)}.
Definition finMap_for of phant (K -> V) := finMap.
Identity Coercion finMap_for_finMap : finMap_for >-> finMap.
End Def.
Notation "{ 'finMap' fT }" := (finMap_for (Phant fT))
(at level 0, format "{ 'finMap'  '[hv' fT ']' }") : type_scope.
Prenex Implicits key value predk predCk seq_of.
Section Ops.
Variables (K : ordType) (V : Type).
Notation fmap := (finMap K V).
Notation key := (@key K V).
Notation value := (@value K V).
Notation predk := (@predk K V).
Notation predCk := (@predCk K V).

Lemma fmapE (s1 s2 : fmap) : s1 = s2 <-> seq_of s1 = seq_of s2.