Skip to content

Instantly share code, notes, and snippets.

@simodima
Last active January 4, 2016 00:39
Show Gist options
  • Save simodima/8543017 to your computer and use it in GitHub Desktop.
Save simodima/8543017 to your computer and use it in GitHub Desktop.
Natural numbers
abstype natural = next of natural | zero of unit
with
fun sum (zero(), n) = n
| sum (next(n), m) = next(sum(m ,n));
fun prod(zero(), n) = zero()
| prod(next(n),m) = sum(prod(n,m), m);
fun fact(zero()) = next(zero())
| fact(next(zero())) = fact(zero())
| fact(next(n)) = prod(next(n), fact(n));
val fact_3 = fact(next(next(next(zero()))));
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment