Skip to content

Instantly share code, notes, and snippets.

@YuukiARIA
Created April 11, 2015 21:00
Show Gist options
  • Save YuukiARIA/e6b4d501d6be95029950 to your computer and use it in GitHub Desktop.
Save YuukiARIA/e6b4d501d6be95029950 to your computer and use it in GitHub Desktop.
work in progress
module Church
Z = -> (s) { -> (z) { z } }
SUCC = -> (x) { -> (s) { -> (z) { s[x[s][z]] } } }
ADD = -> (x) { -> (y) { -> (s) { -> (z) { y[s][x[s][z]] } } } }
def value(x, succ: -> (n) { n + 1 }, unit: 0)
x[succ][unit]
end
end
include Church
p value(SUCC[Z])
# ==> 1
p value(ADD[SUCC[SUCC[Z]]][SUCC[SUCC[SUCC[Z]]]])
# ==> 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment