Section Reflection.
Variables (K : ordType) (T : Type) (U : union_map_class K T).
Implicit Type i : ctx U.
Inductive term := Pts of nat & T | Var of nat.
(* interpretation function for elements *)
Definition interp' i t :=
match t with
Pts n v => if onth (keyx i) n is Some k then pts k v else um_undef
| Var n => if onth (varx i) n is Some f then f else um_undef
end.
(* main interpretation function *)
Notation fx i := (fun t f => interp' i t \+ f).
Definition interp i ts := foldr (fx i) Unit ts.
(* we also need a pretty-printer, which works the same as interp *)
(* but removes trailing Unit's *)
Fixpoint pprint i ts :=
if ts is t :: ts' then
if ts' is [::] then interp' i t else interp' i t \+ pprint i ts'
else Unit.

Lemma pp_interp i ts : pprint i ts = interp i ts.