Skip to content

Commit 3ba620d

Browse files
author
Gregory Malecha
committed
Removing EqDec requirements from Hcons inversion.
1 parent 78d4433 commit 3ba620d

File tree

1 file changed

+80
-27
lines changed

1 file changed

+80
-27
lines changed

theories/Data/HList.v

Lines changed: 80 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ Require Import ExtLib.Data.Member.
88
Require Import ExtLib.Data.ListNth.
99
Require Import ExtLib.Data.Option.
1010
Require Import ExtLib.Tactics.Injection.
11-
Require Import ExtLib.Tactics.EqDep.
1211

1312
Set Implicit Arguments.
1413
Set Strict Implicit.
@@ -79,7 +78,7 @@ Section hlist.
7978
rewrite IHh at 1.
8079
unfold eq_trans. unfold f_equal. unfold eq_sym.
8180
clear. revert h.
82-
generalize dependent (app_nil_r_trans ls).
81+
generalize dependent (app_nil_r_trans ls).
8382
destruct e. reflexivity.
8483
Qed.
8584

@@ -170,32 +169,86 @@ Section hlist.
170169
intros; rewrite (hlist_eta h); reflexivity.
171170
Qed.
172171

173-
Section injection.
174-
Variable rd : RelDec (@eq iT).
175-
Variable rdc : RelDec_Correct rd.
172+
Lemma Hcons_inv
173+
: forall l ls a b c d,
174+
@eq (hlist (l :: ls)) (Hcons a b) (Hcons c d) ->
175+
a = c /\ b = d.
176+
Proof.
177+
intros.
178+
refine (
179+
match H as K in _ = Z
180+
return match Z in hlist LS
181+
return match LS with
182+
| nil => Prop
183+
| l :: ls => F l -> hlist ls -> Prop
184+
end
185+
with
186+
| Hcons X Y x y => fun a b => a = x /\ b = y
187+
| Hnil => True
188+
end a b
189+
with
190+
| eq_refl => conj eq_refl eq_refl
191+
end).
192+
Qed.
176193

177-
Global Instance Injection_hlist_cons ls t (a : F t) (b : hlist ls) c d
178-
: Injective (Hcons a b = Hcons c d) :=
179-
{ result := a = c /\ b = d }.
180-
Proof.
181-
abstract (inversion 1; eapply inj_pair2 in H2; eapply inj_pair2 in H1; auto).
182-
Defined.
194+
Global Instance Injection_hlist_cons ls t (a : F t) (b : hlist ls) c d
195+
: Injective (Hcons a b = Hcons c d) :=
196+
{ result := a = c /\ b = d
197+
; injection := @Hcons_inv t ls a b c d
198+
}.
183199

184-
Theorem equiv_eq_eq : forall ls (x y : hlist ls),
185-
equiv_hlist (fun x => @eq _) x y <-> x = y.
186-
Proof.
187-
induction x; simpl; intros.
188-
{ split. inversion 1. rewrite hlist_nil_eta. reflexivity.
189-
intros; subst; constructor. }
190-
{ split.
191-
{ inversion 1; subst.
192-
apply inj_pair2 in H2.
193-
apply inj_pair2 in H5.
194-
apply inj_pair2 in H4. subst. f_equal. eapply IHx. eauto. }
195-
{ intros; subst. constructor; auto.
196-
reflexivity. } }
197-
Qed.
198-
End injection.
200+
201+
Theorem equiv_eq_eq : forall ls (x y : hlist ls),
202+
equiv_hlist (fun x => @eq _) x y <-> x = y.
203+
Proof.
204+
induction x; simpl; intros.
205+
{ split. inversion 1. rewrite hlist_nil_eta. reflexivity.
206+
intros; subst; constructor. }
207+
{ split.
208+
{ intro. rewrite (hlist_eta y).
209+
specialize (IHx (hlist_tl y)).
210+
refine (match H in @equiv_hlist _ LS X Y
211+
return match X in hlist LS
212+
return F match LS with
213+
| nil => l
214+
| l :: _ => l
215+
end ->
216+
hlist match LS with
217+
| nil => ls
218+
| _ :: ls => ls
219+
end ->
220+
Prop
221+
with
222+
| Hnil => fun _ _ => True
223+
| Hcons a b c d => fun x y =>
224+
(equiv_hlist (fun x0 : iT => eq) d y <-> d = y) ->
225+
@Hcons a b c d = Hcons x y
226+
end (match LS as LS return hlist LS -> F match LS with
227+
| nil => l
228+
| l :: _ => l
229+
end
230+
with
231+
| nil => fun _ => f
232+
| l :: ls => hlist_hd
233+
end Y)
234+
(match LS as LS return hlist LS -> hlist match LS with
235+
| nil => ls
236+
| _ :: ls => ls
237+
end
238+
with
239+
| nil => fun _ => x
240+
| l :: ls => hlist_tl
241+
end Y)
242+
with
243+
| hlist_eqv_nil => I
244+
| hlist_eqv_cons l ls x y h1 h2 pf1 pf2 => _
245+
end IHx).
246+
simpl.
247+
subst. intros.
248+
f_equal. apply H0. assumption. }
249+
{ intros; subst. constructor; auto.
250+
reflexivity. } }
251+
Qed.
199252

200253
Fixpoint hlist_get ls a (m : member a ls) : hlist ls -> F a :=
201254
match m in member _ ls return hlist ls -> F a with
@@ -274,7 +327,7 @@ Section hlist.
274327
: forall (l' : list T) n v,
275328
nth_error l n = Some v -> Some v = nth_error (l ++ l') n.
276329
Proof.
277-
induction l. intros.
330+
induction l. intros.
278331
{ exfalso. destruct n; inversion H. }
279332
{ destruct n; simpl; intros; auto. }
280333
Defined.

0 commit comments

Comments
 (0)