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.

Theorem trm_is_enumerable (t : trm L)
: { x : nat | enum_trm x = t }.