Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FMapAList: add alternative definition #115

Merged
merged 1 commit into from
Sep 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion theories/Data/Map/FMapAList.v
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ Require Import ExtLib.Structures.Maps.
Require Import ExtLib.Structures.Monad.
Require Import ExtLib.Structures.Reducible.
Require Import ExtLib.Structures.Functor.
From Coq Require Import
Basics.
From ExtLib Require Import
Extras
OptionMonad.
Import
FunNotation
FunctorNotation.
Open Scope program_scope.

Set Implicit Arguments.
Set Strict Implicit.
Expand Down Expand Up @@ -35,6 +44,20 @@ Section keyed.
alist_find k ms
end.

Definition alist_find' (k: K) : alist -> option V :=
fmap snd ∘ find (rel_dec k ∘ fst).

Lemma alist_find_alt (m: alist) : forall k: K,
alist_find k m = alist_find' k m.
Proof.
induction m; intuition.
unfold alist_find', compose.
simpl.
destruct (k ?[ R ] a0) eqn:Heq; intuition.
rewrite IHm.
reflexivity.
Qed.

Section fold.
Import MonadNotation.
Local Open Scope monad_scope.
Expand All @@ -49,6 +72,19 @@ Section keyed.
let acc := f k v acc in
fold_alist acc m
end.

Definition fold_alist' : T -> alist -> T :=
flip $ fold_left (flip $ uncurry f).

Lemma fold_alist_alt (map: alist) : forall acc: T,
fold_alist acc map = fold_alist' acc map.
Proof.
induction map; intuition.
simpl.
rewrite IHmap.
reflexivity.
Qed.

End fold.

Definition alist_union (m1 m2 : alist) : alist :=
Expand Down Expand Up @@ -208,4 +244,4 @@ Module TEST.
| S n => find_all n
end) 500.
End TEST.
*)
*)