@@ -13,6 +13,7 @@ Set Implicit Arguments.
1313Set Strict Implicit .
1414Set Asymmetric Patterns.
1515
16+ (** Core Type and Functions * *)
1617Section hlist.
1718 Context {iT : Type}.
1819 Variable F : iT -> Type.
@@ -103,7 +104,7 @@ Section hlist.
103104
104105 (** TODO: I need hlist_rev_cons * *)
105106
106-
107+ (* * Equivalence * *)
107108 Section equiv.
108109 Variable eqv : forall x, relation (F x).
109110
@@ -156,6 +157,57 @@ Section hlist.
156157 eapply H3. simpl in *. eassumption. }
157158 Qed .
158159
160+ Lemma equiv_hlist_Hcons
161+ : forall ls i a b (c : hlist ls) d,
162+ equiv_hlist (Hcons a c) (@Hcons i ls b d) ->
163+ (@eqv i a b /\ equiv_hlist c d).
164+ Proof .
165+ clear. intros.
166+ refine
167+ match H in @equiv_hlist ls' l r
168+ return match ls' as ls' return hlist ls' -> hlist ls' -> _ with
169+ | nil => fun _ _ => True
170+ | l :: ls => fun l r =>
171+ eqv (hlist_hd l) (hlist_hd r) /\
172+ equiv_hlist (hlist_tl l) (hlist_tl r)
173+ end l r
174+ with
175+ | hlist_eqv_nil => I
176+ | hlist_eqv_cons _ _ _ _ _ _ pf pf' => conj pf pf'
177+ end.
178+ Defined .
179+
180+ Lemma equiv_hlist_app
181+ : forall a b (c c' : hlist a) (d d' : hlist b),
182+ (equiv_hlist c c' /\ equiv_hlist d d')
183+ <->
184+ equiv_hlist (hlist_app c d) (hlist_app c' d').
185+ Proof .
186+ clear. split.
187+ - destruct 1.
188+ induction H.
189+ + assumption.
190+ + simpl. constructor; auto.
191+ - induction c.
192+ + rewrite (hlist_eta c').
193+ simpl; intros; split; auto. constructor.
194+ + rewrite (hlist_eta c'); simpl.
195+ specialize (IHc (hlist_tl c')).
196+ intro.
197+ eapply equiv_hlist_Hcons in H. intuition.
198+ constructor; auto.
199+ Qed .
200+
201+ Global Instance Injection_equiv_hlist_cons ls i a b (c : hlist ls) d
202+ : Injective (equiv_hlist (Hcons a c) (@Hcons i ls b d)) :=
203+ { result := @eqv i a b /\ equiv_hlist c d
204+ ; injection := @equiv_hlist_Hcons _ _ _ _ _ _ }.
205+
206+ Global Instance Injection_equiv_hlist_app a b (c c' : hlist a) (d d' : hlist b)
207+ : Injective (equiv_hlist (hlist_app c d) (hlist_app c' d')) :=
208+ { result := equiv_hlist c c' /\ equiv_hlist d d'
209+ ; injection := fun x => proj2 (@equiv_hlist_app _ _ _ _ _ _) x }.
210+
159211 End equiv.
160212
161213 Lemma hlist_nil_eta : forall (h : hlist nil), h = Hnil.
@@ -513,6 +565,7 @@ End hlist.
513565
514566Arguments Hnil {_ _}.
515567Arguments Hcons {_ _ _ _} _ _.
568+ Arguments equiv_hlist {_ F} R {_} _ _ : rename.
516569
517570Section hlist_map.
518571 Variable A : Type.
@@ -528,4 +581,4 @@ Section hlist_map.
528581 end .
529582End hlist_map.
530583
531- Arguments hlist_map {_ _ _} _ {_} _.
584+ Arguments hlist_map {_ _ _} _ {_} _.
0 commit comments