Erlang 中的 S 组合器
我开始学习 lambda 演算,我需要在 Erlang 中实现 I、S、K 组合器。 当然,S、K、I代表:
S = λxyz.xz(yz) K = λxy.x I = λx.x
我可以毫无问题地理解纸上的 I=SKK 变换(如下所示:为了证明 SKK 和 II 是 beta 等价的,lambda 演算)但似乎当涉及到函数式语言和高阶函数时,我不明白它......
我设法做到了 I 和 K (可以说在模块 test
中):
i(X) -> X.
k(X) -> fun(Y) -> X end.
我也知道如何运行 K x (K x) (SKK x = K x (K x))
kxk(X) -> (k(X))(k(X)).
但我无法编写 S 组合器。我尝试过:
s(X) -> fun (Y) -> fun(Z) -> X,Z (Y,Z) end end.
但是,我仍然无法将 SKK x 转换为 x
我尝试像这样运行它:
skkx(X) -> s((k((k(X))))).
任何帮助将不胜感激,因为我完全迷失了。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 Erlang shell:
或者作为模块中的函数:
From the Erlang shell:
Or as functions in a module: