Program Fixpoint nat2string (n:nat) {measure n}: string :=
match NPeano.Nat.ltb n modulus as x return NPeano.Nat.ltb n modulus = x -> string with
| true => fun _ => String (digit2ascii n) EmptyString
| false => fun pf =>
let m := NPeano.Nat.div n modulus in
append (nat2string m) (String (digit2ascii (n - modulus * m)) EmptyString)
end (@Logic.eq_refl _ (NPeano.Nat.ltb n modulus)).
Next Obligation.
eapply NPeano.Nat.div_lt; auto.
consider (NPeano.Nat.ltb n modulus); try congruence. intros.
eapply _xxx; eassumption.
Defined.
End Program_Scope.
Definition nat2string10 : nat -> string.
refine (@nat2string 10 _).
repeat constructor.
Defined.
Definition nat2string2 : nat -> string.
refine (@nat2string 2 _).
repeat constructor.
Defined.
Definition nat2string8 : nat -> string.
refine (@nat2string 8 _).
repeat constructor.
Defined.
Definition nat2string16 : nat -> string.
refine (@nat2string 16 _).
repeat constructor.
Defined.
Global Instance Foldable_string : Foldable string ascii :=
fun _ f base =>
fix go ls :=
match ls with
| EmptyString => base
| String l ls =>
f l (go ls)
end.
Section string.
Inductive R_string_len : string -> string -> Prop :=
| R_s_len : forall n m, length n < length m -> R_string_len n m.

(* Specifications: *)
Theorem wf_R_string_len : well_founded R_string_len.