(* * Copyright (c) 2009 Robert Dockins and Aquinas Hobor. * *)
Definition unary_primop (f:nat -> nat) : expr :=
Lam (prim (v_Nat oo f) (Var 0)).
Program Definition bin_primop (f:nat -> nat -> nat) : expr :=
Lam (prim (fun n1 => Lam (prim (fun n2 => v_Nat (f n1 n2)) (Var 0))) (Var 0)).
Next Obligation.
compute; split; auto.
Qed.
Definition ty_bool := ALL a:pred world, ty_lam a (ty_lam a a).
Definition e_true := Lam (Lam (Var 1)).
Definition e_false := Lam (Lam (Var 0)).
Definition e_if b t f :=
(App (App (App b (Lam t)) (Lam f)) (Nat 0)).
Program Definition isZ : expr -> expr :=
prim (fun n => if beq_nat n 0 then e_true else e_false).
Solve Obligations using (compute; split; auto).
Definition e_let (def body:expr) :=
(App (Lam body) def).
Definition option (a:pred world) :=
ALL b:pred world, ty_lam b (ty_lam (ty_lam a b) b).
Definition none : expr := Lam (Lam (Var 1)).
Definition some : expr := Lam (Lam (Lam (App (Var 0) (Var 2)))).
Definition out  : expr := Lam (Lam (App (App (Var 0) (Var 1)) (Lam (Var 0)))).
Definition W := (Lam (App (Var 0) (Var 0))).
Definition diverge := App W W.
Definition W_ty Z := fun X => ty_lam X Z.

Lemma W_ty_cont : forall Z, contractive (W_ty Z).