I'm starting to learn lambda calculus and I need to implement I, S, K combinators in Erlang. Of course, S, K, I stands for:
S = λxyz.xz(yz) K = λxy.x I = λx.x
I have no problem understanding I=SKK transformation on paper (like presented here: To prove SKK and II are beta equivalent, lambda calculus) but it seems that I don't understand it when it comes to functional languages and high-order functions...
I managed to do I and K (lets say in module test
):
i(X) -> X.
k(X) -> fun(Y) -> X end.
Also I know how to run K x (K x) (SKK x = K x (K x))
kxk(X) -> (k(X))(k(X)).
But I can't get it around to write S combinator. I tried:
s(X) -> fun (Y) -> fun(Z) -> X,Z (Y,Z) end end.
But still, I'm not able to transform SKK x into x
I try to run it like this:
skkx(X) -> s((k((k(X))))).
Any help would be appreciated, as I'm completely lost.