|
1 | 1 | Require Import ExtLib.Structures.Functor. |
2 | 2 | Require Import ExtLib.Structures.Applicative. |
3 | 3 | Require Import ExtLib.Data.POption. |
| 4 | +Require Import ExtLib.Core.RelDec. |
| 5 | +Require Import ExtLib.Tactics.Consider. |
4 | 6 |
|
5 | 7 | Set Universe Polymorphism. |
6 | 8 |
|
@@ -125,3 +127,38 @@ Polymorphic Definition Applicative_plist@{i} : Applicative@{i i} plist@{i} := |
125 | 127 | {| pure := fun _ val => pcons val pnil |
126 | 128 | ; ap := @ap_plist |
127 | 129 | |}. |
| 130 | + |
| 131 | +Section PListEq. |
| 132 | + Variable T : Type. |
| 133 | + Variable EDT : RelDec (@eq T). |
| 134 | + |
| 135 | + Fixpoint plist_eqb (ls rs : plist T) : bool := |
| 136 | + match ls , rs with |
| 137 | + | pnil , pnil => true |
| 138 | + | pcons l ls , pcons r rs => |
| 139 | + if l ?[ eq ] r then plist_eqb ls rs else false |
| 140 | + | _ , _ => false |
| 141 | + end. |
| 142 | + |
| 143 | + (** Specialization for equality **) |
| 144 | + Global Instance RelDec_eq_plist : RelDec (@eq (plist T)) := |
| 145 | + { rel_dec := plist_eqb }. |
| 146 | + |
| 147 | + Variable EDCT : RelDec_Correct EDT. |
| 148 | + |
| 149 | + Global Instance RelDec_Correct_eq_plist : RelDec_Correct RelDec_eq_plist. |
| 150 | + Proof. |
| 151 | + constructor; induction x; destruct y; split; simpl in *; intros; |
| 152 | + repeat match goal with |
| 153 | + | [ H : context [ rel_dec ?X ?Y ] |- _ ] => |
| 154 | + consider (rel_dec X Y); intros; subst |
| 155 | + | [ |- context [ rel_dec ?X ?Y ] ] => |
| 156 | + consider (rel_dec X Y); intros; subst |
| 157 | + end; try solve [ auto | exfalso; clear - H; inversion H ]. |
| 158 | + - f_equal. eapply IHx. eapply H0. |
| 159 | + - inversion H. subst. eapply IHx. reflexivity. |
| 160 | + - inversion H. exfalso. eapply H0. assumption. |
| 161 | + Qed. |
| 162 | + |
| 163 | +End PListEq. |
| 164 | + |
0 commit comments