Last active
November 27, 2021 17:47
-
-
Save Camilotk/25570b8047a4a24c4c7aaf2cd874af93 to your computer and use it in GitHub Desktop.
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
parse = n => ( | |
n = n.name, | |
(n == "K") ? true : | |
(n == "KI") ? false : false | |
) // parsing to unpack meaning from the lambda calculus. | |
I = a => a // λa.a - Idiot - Identity | |
K = a => b => a // λab.a - Kestrel - first, const | |
KI = a => b => b // λab.b - Kite - second | |
M = f => f(f) // λf.ff - Mockingbird - self-application | |
// Combinator - functions with no free variables. e.g. λabc.ab , not λa.b | |
C = f => a => b => f(b)(a) // λfab.fba - flip arguments | |
// Church encodings - Booleans/Logic | |
const T = K // true behaves like Kestrel. | |
const F = KI // false behaves like Kite. | |
not = f => f(F)(T) // Kestral will pick the fst, Kite the snd | |
and = f => q => f(q)(F) | |
or = f => q => f(T)(q) | |
beq = f => q => f(q)(not(q)) | |
// e.g. | |
parse(beq(T)(T)) // true | |
S = a => b => c => a(c)(b(c)) // λabc.ac(bc) - Starling | |
S(K)(K)(2) // 2 | |
add = n1 => n2 => f => a => n2(f)(n1(f)(a)) | |
num = x => x(y => y + 1)(0) | |
n0 = f => a => a // Exactly like the Kite. Zero is false in lambda calculus. | |
n1 = f => a => f(a) // Exactly like Identity, except it is refered to as I* (Identity once removed). | |
n2 = f => a => f(f(a)) // An additional f is added. | |
n3 = f => a => f(f(f(a))) // And so on.. | |
n4 = f => a => f(n3(f)(a)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the way I understand the generic add function, I believe it should be something like
add = n1 => n2 => f => a => n2(f)(n1(f)(a))
at least to work with the "num" function.