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 typeof_rreplace_nth: forall t xs x n tus tvs,
typeof_expr tus tvs xs = Some (tylist t) ->
typeof_expr tus tvs x = Some t ->
typeof_expr tus tvs (rreplace_nth t n xs x) = Some (tylist t).