Section tbled.
Variable tbl : SymEnv.functions RType_typ.
Let RSym_sym := RSym_sym tbl.
Existing Instance RSym_sym.
Let RSym_sym_ok :  RSymOk RSym_sym := _.
Existing Instance RSym_sym_ok.
Let Expr_expr_fs := Expr_expr_fs tbl.
Existing Instance Expr_expr_fs.
Let Expr_ok_fs := Expr_ok_fs tbl.
Existing Instance Expr_ok_fs.
Existing Instance MA.
Definition reflect tus tvs e (ty : typ)
:= @exprD _ _ _ Expr_expr_fs tus tvs e ty.
intros. congruence.
Qed.
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).