Ltac solve_exprD := solve_exprD.solve_exprD tbl.
Opaque type_cast.
Ltac destruct_as_list :=
repeat
match goal with
| [ H : context [ match as_list ?x with _ => _ end] |- _] => destruct (as_list x) eqn:?
| [ |- context [ match as_list ?x with _ => _ end]] => destruct (as_list x) eqn:?
| [ H : as_list _ = Some (inr _) |- _ ] => apply as_list_nil in H
| [ H : as_list _ = Some (inl (_ , _, _)) |- _ ] => apply as_list_cons in H
| [ H : as_list _ = Some (inl (?p, _)) |- _ ] => destruct p
| [ H : as_list _ = Some (inl ?p) |- _ ] => destruct p
| [ H : as_list _ = Some ?p |- _ ] => destruct p
end;
subst.

Lemma rnth_error_eq2 :
forall typ xs n tus tvs val,
exprD' tus tvs (tylist typ) xs = Some val ->
exprD' tus tvs (tyoption typ) (App (Inj (inr (Data (fnth_error typ n)))) xs)  =
exprD' tus tvs (tyoption typ) (rnth_error typ xs n).