(*Realizer [e:env][n:nat] Cases (list_item decl e n) of (inleft d) => (inl ? type_error (pa_lift the_algos (S n) (typ_of_decl d))) | _          => (inr term ? (Db_error n)) end. *)
intros.
case (list_item e n).
intros (d, itd).
left.
elim (pa_lift the_algos (S n) (typ_of_decl d)); intros.
exists x; subst x.
split; intros.
constructor; trivial.
split with d; trivial.
Inversion_typ H0.
elim fun_item with (1 := H1) (2 := itd); trivial.
right.
exists (Db_error n); auto with pts.
constructor; trivial.
generalize n n0.
elim e; simpl in |- *; trivial with arith.
simple destruct n1; intros.
elim n2 with a; trivial.
cut (length l <= n2); auto with arith.
apply H0; red in |- *; intros.
elim n3 with t; auto.
Qed.
End Infer_Ref.
Section Infer_Application.
Let le_type_prod_l := inv_prod_l _ (pa_inv_prod the_algos).
Let le_type_prod_r := inv_prod_r _ (pa_inv_prod the_algos).
Definition app_chk_err (u tu : term) (e : type_error) :=
match e with
| Expected_type v tv _ => Apply_err u tu v tv
| e => e
end.
(* Lemma app_chk_expln: (e:env)(u,a,b:term)(err:type_error) (typ_ppal e u (Prod a b))->(expln e err) ->(expln e (app_chk_err u (Prod a b) err)). Intros. (Inversion_clear H0; Simpl; Try Constructor; Trivial). Apply (pp_ok H).  Intros. Apply (pp_least H) with 1:=H0.  Simpl. *)

(* Specifications: *)
Theorem infer_app :
forall (e : env) (u v : term), wf e -> infer_ppal_type e (App u v).