11Require Import ExtLib.Structures.Functor.
22Require Import ExtLib.Structures.Applicative.
33Require Import ExtLib.Data.POption.
4+ Require Import ExtLib.Data.PPair.
45Require Import ExtLib.Core.RelDec.
56Require Import ExtLib.Tactics.Consider.
67
@@ -66,7 +67,7 @@ Section plist.
6667 Polymorphic Fixpoint allb (p : T -> bool) (lst : plist) : bool :=
6768 match lst with
6869 | pnil => true
69- | pcons l ls => if p l then anyb p ls else false
70+ | pcons l ls => if p l then allb p ls else false
7071 end .
7172
7273 Polymorphic Fixpoint nodup {RelDecA : RelDec (@eq T)} (lst : plist) :=
@@ -104,6 +105,7 @@ End plist.
104105
105106Arguments pnil {_}.
106107Arguments pcons {_} _ _.
108+ Arguments app {_} _ _.
107109Arguments pIn {_} _ _.
108110Arguments pNoDup {_} _.
109111Arguments anyb {_} _ _.
@@ -116,12 +118,44 @@ Arguments nth_error {_} _ _.
116118
117119
118120Section plistFun.
119- Polymorphic Fixpoint split {A B : Type } (lst : plist ((A * B)%type )) :=
121+ Polymorphic Fixpoint split {A B : Type } (lst : plist (ppair A B )) :=
120122 match lst with
121123 | pnil => (pnil, pnil)
122- | pcons (x, y) tl => let (left, right) := split tl in (pcons x left, pcons y right)
124+ | pcons (pprod x y) tl => let (left, right) := split tl in (pcons x left, pcons y right)
123125 end .
124126
127+ Lemma pIn_split_l {A B : Type } (lst : plist (ppair A B)) (p : ppair A B) (H : pIn p lst) :
128+ (pIn (pfst p) (fst (split lst))).
129+ Proof .
130+ destruct p; simpl.
131+ induction lst; simpl in *.
132+ + destruct H.
133+ + destruct t; simpl.
134+ destruct (split lst); simpl.
135+ destruct H as [H | H]; [
136+ inversion H; left; reflexivity |
137+ right; apply IHlst; apply H].
138+ Qed .
139+
140+ Lemma pIn_split_r {A B : Type } (lst : plist (ppair A B)) (p : ppair A B) (H : pIn p lst) :
141+ (pIn (psnd p) (snd (split lst))).
142+ Proof .
143+ destruct p; simpl.
144+ induction lst; simpl in *.
145+ + destruct H.
146+ + destruct t; simpl.
147+ destruct (split lst); simpl.
148+ destruct H as [H | H]; [
149+ inversion H; left; reflexivity |
150+ right; apply IHlst; apply H].
151+ Qed .
152+
153+ Lemma pIn_app_iff (A : Type ) (l l' : plist A) (a : A) :
154+ pIn a (app l l') <-> pIn a l \/ pIn a l'.
155+ Proof .
156+ induction l; simpl; intuition congruence.
157+ Qed .
158+
125159End plistFun.
126160
127161Section plistOk.
@@ -192,7 +226,7 @@ Section applicative.
192226 : plist@{j} U :=
193227 match fs with
194228 | pnil => pnil
195- | pcons f fs => app@{j} _ (fmap_plist@{i j} f xs) (ap_plist fs xs)
229+ | pcons f fs => app@{j} (fmap_plist@{i j} f xs) (ap_plist fs xs)
196230 end .
197231End applicative.
198232
@@ -202,10 +236,11 @@ Polymorphic Definition Applicative_plist@{i} : Applicative@{i i} plist@{i} :=
202236 |}.
203237
204238Section PListEq.
205- Variable T : Type.
239+ Polymorphic Universe i.
240+ Variable T : Type@{i}.
206241 Variable EDT : RelDec (@eq T).
207242
208- Fixpoint plist_eqb (ls rs : plist T) : bool :=
243+ Polymorphic Fixpoint plist_eqb (ls rs : plist T) : bool :=
209244 match ls , rs with
210245 | pnil , pnil => true
211246 | pcons l ls , pcons r rs =>
@@ -214,12 +249,12 @@ Section PListEq.
214249 end .
215250
216251 (** Specialization for equality * *)
217- Global Instance RelDec_eq_plist : RelDec (@eq (plist T)) :=
252+ Global Polymorphic Instance RelDec_eq_plist : RelDec (@eq (plist T)) :=
218253 { rel_dec := plist_eqb }.
219254
220255 Variable EDCT : RelDec_Correct EDT.
221256
222- Global Instance RelDec_Correct_eq_plist : RelDec_Correct RelDec_eq_plist.
257+ Global Polymorphic Instance RelDec_Correct_eq_plist : RelDec_Correct RelDec_eq_plist.
223258 Proof .
224259 constructor; induction x; destruct y; split; simpl in *; intros;
225260 repeat match goal with
0 commit comments