From 232bd65809399b2b5934e49e6d5048ec970d62ff Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Mon, 24 Jul 2023 23:02:43 -0700 Subject: [PATCH] Add uniqueness preservation proof for merge Signed-off-by: Danila Fedorin --- Map.agda | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Map.agda b/Map.agda index 06aad7c..24f2577 100644 --- a/Map.agda +++ b/Map.agda @@ -106,6 +106,10 @@ insert-preserves-unique f k v l u with (∈k-dec k l) ... | yes k∈kl rewrite insert-keys-∈ f k v l k∈kl = u ... | no k∉kl rewrite sym (insert-keys-∉ f k v l k∉kl) = Unique-append k∉kl u +merge-preserves-unique : ∀ (f : B → B → B) (l₁ l₂ : List (A × B)) → Unique (keys l₂) → Unique (keys (merge f l₁ l₂)) +merge-preserves-unique f [] l₂ u₂ = u₂ +merge-preserves-unique f ((k₁ , v₁) ∷ xs₁) l₂ u₂ = insert-preserves-unique f k₁ v₁ (merge f xs₁ l₂) (merge-preserves-unique f xs₁ l₂ u₂) + Map-functional : ∀ (k : A) (v v' : B) (xs : List (A × B)) → Unique (keys ((k , v) ∷ xs)) → Data.List.Membership.Propositional._∈_ (k , v') ((k , v) ∷ xs) → v ≡ v' Map-functional k v v' _ _ (here k,v'≡k,v) = sym (cong proj₂ k,v'≡k,v) Map-functional k v v' xs (push k≢ _) (there k,v'∈xs) = absurd (unique-not-in xs v' (k≢ , k,v'∈xs))