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.

Theorem nth_error_get_hlist_nth_None
: forall ls n,
nth_error_get_hlist_nth ls n = None <->
nth_error ls n = None.