Section hlist_gen.
Variable A : Type.
Variable F : A -> Type.
Variable f : forall a, F a.
Fixpoint hlist_gen ls : hlist F ls :=
match ls with
| nil => Hnil
| cons x ls' => Hcons (f x) (hlist_gen ls')
end.
(** This function is a generalisation of [hlist_gen] in which the function [f] takes the additional parameter [member a ls]. **)
Fixpoint hlist_gen_member ls : (forall a, member a ls -> F a) -> hlist F ls :=
match ls as ls return ((forall a : A, member a ls -> F a) -> hlist F ls) with
| nil => fun _ => Hnil
| a :: ls' => fun fm =>
Hcons (fm a (MZ a ls'))
(hlist_gen_member (fun a' (M : member a' ls') => fm a' (MN a M)))
end.
End hlist_gen.
Arguments hlist_gen {A F} f ls.
Global Instance Proper_hlist_gen : forall A F,
Proper (forall_relation (fun _ => eq) ==> forall_relation (fun _ => eq))
(@hlist_gen A F).
Global Instance Proper_equiv_hlist_gen : forall A (F : A -> Type) R,
Proper (forall_relation R ==> forall_relation (@equiv_hlist _ _ R))
(@hlist_gen A F).
Fixpoint hlist_erase {A B} {ls : list A} (hs : hlist (fun _ => B) ls) : list B :=
match hs with
| Hnil => nil
| Hcons _ _ x hs' => cons x (hlist_erase hs')
end.

Lemma hlist_erase_hlist_gen : forall A B ls (f : A -> B),
hlist_erase (hlist_gen f ls) = map f ls.