Section list_Enumerable_Section.
Variables (X: Type) (enumX: Enumerable X).
Fixpoint encode (L: list X) : nat :=
if L is x :: L then 1+nat2_Enumerable.encode (1 + to_nat x, encode L) else 1+nat2_Enumerable.encode (0, 0).
Fixpoint decode (i: nat) (n: nat) : list X :=
if i is S i then match nat2_Enumerable.decode (n-1) with | (0, _) => [] | (S n1, n2) => (of_nat n1) :: decode i n2 end else [].
Opaque nat2_Enumerable.encode nat2_Enumerable.decode.

Lemma decode_encode {L: list X} : decode (encode L) (encode L) = L.