Skip to content

Commit

Permalink
Add SKI combinator calculus example
Browse files Browse the repository at this point in the history
  • Loading branch information
skius committed May 13, 2021
1 parent 7ab7e0a commit cd2b19e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions stringlang_programs/ski_combinator.stringlang
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* The Calculus */
I = fun(x) { x };
K = fun(x) { fun(y) { x } };
S = fun(x) { fun(y) { fun(z) { x(z)(y(z)) } } };

/* Booleans */
T = K;
F = S(K);

/* I am unsure how safe this comparison of lambdas is */
bool_str = fun(b) { b == T };

/* Boolean operators */
NOT = S(S(I)(K(F)))(K(T));
OR = S(I)(K(T));
AND = S(S)(K(K(F)));

other_k = S(K)(S)(K);

I("Identity") + "\n" +
K("Always Me")("Never Me") + "\n" +
other_k("also Always Me")("also Never Me") + "\n\n" +

"NOT T = " + bool_str(NOT(T)) + ", NOT F = " + bool_str(NOT(F)) + "\n" +
"T AND F = " + bool_str(AND(T)(F)) + ", T AND T = " + bool_str(AND(T)(T)) + "\n" +
"F OR T = " + bool_str(OR(F)(T)) + ", F OR F = " + bool_str(OR(F)(F))

0 comments on commit cd2b19e

Please sign in to comment.