Skip to content

Instantly share code, notes, and snippets.

@ComFreek
Created July 14, 2020 11:20
Show Gist options
  • Save ComFreek/300a7ca2fd11805c144b741f9f6b25cb to your computer and use it in GitHub Desktop.
Save ComFreek/300a7ca2fd11805c144b741f9f6b25cb to your computer and use it in GitHub Desktop.
How to convert nat to string in Coq

Every time I wanted to convert nat to string in the most obvious manner (i.e. decimal), I had to search >= 10min in the libraries for the right function calls!

Require Import Numbers.DecimalString.
Require Import Numbers.DecimalNat.

Definition nat_to_string (n: nat) := NilZero.string_of_uint (Decimal.rev (Unsigned.to_lu n)).
Compute (nat_to_string 0).   (*  "0" *)
Compute (nat_to_string 42).  (* "42" *)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment