Polymorphic Fixpoint nth_error_get_hlist_nth (ls : list iT) (n : nat) {struct ls} :
option {t : iT & hlist ls -> F t} :=
match
ls as ls0
return option {t : iT & hlist ls0 -> F t}
with
| nil => None
| l :: ls0 =>
match
n as n0
return option {t : iT & hlist (l :: ls0) -> F t}
with
| 0 =>
Some (@existT _ (fun t => hlist (l :: ls0) -> F t)
l (@hlist_hd _ _))
| S n0 =>
match nth_error_get_hlist_nth ls0 n0 with
| Some (existT x f) =>
Some (@existT _ (fun t => hlist _ -> F t)
x (fun h : hlist (l :: ls0) => f (hlist_tl h)))
| None => None
end
end
end.

Lemma nth_error_get_hlist_nth_appL
: forall tvs' tvs n,
n < length tvs ->
exists x,
nth_error_get_hlist_nth (tvs ++ tvs') n = Some x /\
exists y,
nth_error_get_hlist_nth tvs n = Some (@existT _ _ (projT1 x) y) /\
forall vs vs',
(projT2 x) (hlist_app vs vs') = y vs.