Skip to content

Instantly share code, notes, and snippets.

@pedrominicz
Last active March 15, 2020 21:59
Show Gist options
  • Save pedrominicz/92269ea64ee503064cf7c5240beea74c to your computer and use it in GitHub Desktop.
Save pedrominicz/92269ea64ee503064cf7c5240beea74c to your computer and use it in GitHub Desktop.
Software Foundations: Functional Programming in Coq
Inductive bin : Type :=
| bz
| b0 (b : bin)
| b1 (b : bin).
Fixpoint increment (b : bin) : bin :=
match b with
| bz => b1 bz
| b0 b => b1 b
| b1 b => b0 (increment b)
end.
Fixpoint bin_to_nat (b : bin) : nat :=
match b with
| bz => O
| b0 b => 2 * bin_to_nat b
| b1 b => 1 + 2 * bin_to_nat b
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment