Skip to content

Instantly share code, notes, and snippets.

@t-katsushima
Created August 10, 2017 11:16
Show Gist options
  • Save t-katsushima/4488ebcca3df571ef143c57ab98cc3e3 to your computer and use it in GitHub Desktop.
Save t-katsushima/4488ebcca3df571ef143c57ab98cc3e3 to your computer and use it in GitHub Desktop.
type nat = Z | S of nat
let rec nat_of_int = function
| 0 -> Z
| n -> S (nat_of_int (n-1))
let rec plus n m =
match n with
| Z -> m
| S n' -> plus n' (S m)
let times n m =
let rec calc n res =
match n with
| Z -> res
| S n' -> calc n' (plus m res)
in calc n Z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment