Last active
January 4, 2016 00:39
-
-
Save simodima/8543017 to your computer and use it in GitHub Desktop.
Natural numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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