(** 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.

(* Specifications: *)
Lemma hlist_gen_member_hlist_gen : forall ls, hlist_gen_member (fun a _ => f a) = hlist_gen ls.
Lemma hlist_gen_member_ext : forall ls (f g : forall a, member a ls -> F a), (forall x M, f x M = g x M) -> hlist_gen_member f = hlist_gen_member g.
Lemma hlist_gen_member_hlist_map : forall A (F G : A -> Type) (ff : forall t, F t -> G t) ls f, hlist_map ff (hlist_gen_member F (ls := ls) f) = hlist_gen_member G (fun a M => ff _ (f _ M)).
Lemma hlist_gen_hlist_map : forall A (F G : A -> Type) (ff : forall t, F t -> G t) f ls, hlist_map ff (hlist_gen f ls) = hlist_gen (fun a => ff _ (f a)) ls.
Lemma hlist_gen_ext : forall A F (f g : forall a, F a), (forall x, f x = g x) -> forall ls : list A, hlist_gen f ls = hlist_gen g ls.