Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 31 lines (22 sloc) 0.681 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
data O 0
data S 1

fun plus(x, y) = case x of {
                     O => y
                   | S(k) => S (plus(k, y))
                 }

fun natToInt(x) = case x of {
                     O => 0
                   | S(k) => let y = natToInt(k) in y + 1
                  }

fun adder(arity, acc) = case arity of {
                           O => acc
                         | S(k) => adderAux(k, acc)
                        }

fun adderAux(k, acc, n) = adder(k, plus(acc, n))

fun zero() = O
fun one() = S(zero)
fun two() = S(one)
fun three() = S(two)
fun four() = S(three)
fun five() = S(four)

fun main() = %WriteInt(natToInt(adder(three, two, three, four, five)))


Something went wrong with that request. Please try again.