Section ENUMERATION.
Context {L : language}.
Let rank : Set := nat.
Fixpoint trm_depth (t : trm L) : rank :=
match t with
| Var_trm x => 0
| Fun_trm f ts => 1 + trms_depth ts
| Con_trm c => 1
end
with trms_depth {n : nat} (ts : trms L n) : rank :=
match ts with
| O_trms => 0
| S_trms n t ts => 1 + max (trm_depth t) (trms_depth ts)
end.
Definition enum_trm (x : nat) : trm L :=
let rk := fst (cp x) in
let seed := snd (cp x) in
gen_trm seed rk.
Definition enum_trms {n : nat} (x : nat) : trms L n :=
let rk := fst (cp x) in
let seed := snd (cp x) in
gen_trms seed rk.

Theorem trms_is_enumerable n (ts : trms L n)
: { x : nat | enum_trms x = ts }.