(* Realizer [e:env][t:term] Cases (fix_inference t e) of (inl T)  => Cases (pa_least_sort the_algos e T) of (inleft s) => Dcl_ok | _          => (Dcl_fail (Not_a_type t T)) end | (inr err) => (Dcl_fail err) end. *)
intros.
case (fix_inference t e); trivial;
[ intros (T, ppty_t) | intros (err, expl, is_err) ].
case (pa_least_sort the_algos e T); intros.
apply type_correctness with (1 := pp_ok ppty_t).
apply Dcl_ok.
inversion_clear s.
apply wf_var with x.
apply typ_conv_wf with T; auto with pts.
apply (pp_ok ppty_t).
apply (pp_least ppty_t).
apply type_conv_srt with (1 := pp_ok ppty_t).
apply (pp_ok H0).
apply Dcl_fail with (Not_a_type t T); auto with pts.
constructor; trivial.
apply (pp_ok ppty_t).
red in |- *; intros.
elim n with s.
apply (pp_least ppty_t) with (1 := H0).
apply Dcl_fail with err; auto with pts.
Defined.
Section Infer_Ref.

Theorem infer_ref :
forall (e : env) (n : nat), wf e -> infer_ppal_type e (Ref n).