저는 Y Combinator를 연구 해왔고, 어떻게 종이에서 작동 하는지를 알았지 만, 프로그래밍 언어로 어떻게 구현할 수 있는지 아직 모르겠습니다. 이 페이지에 따르면 javascript와 elixir에서 Y- 결합 자 구현
: http://matt.might.net/articles/implementation-of-recursive-fixed-point-y-combinator-in-javascript-for-memoization/Y 연결자의 유도가 간다 :
Y(F) = F(Y(F))
# Of course, if we tried to use it, it would never work because the function Y immediately calls itself, leading to infinite recursion.
# Using a little λ-calculus, however, we can wrap the call to Y in a λ-term:
Y(F) = F(λ x.(Y(F))(x))
# Using another construct called the U combinator, we can eliminate the recursive call inside the Y combinator, which, with a couple more transformations gets us to:
Y = (λh.λF.F(λ x.((h(h))(F))(x))) (λh.λF.F(λ x.((h(h))(F))(x)))
그는 어떻게 λ x.(Y(F))(x)
을 할 Y(F)
확장 할 수 있습니다? U Combinator는 어떻게 사용할 수 있습니까? 이런 식이면
# javascript
var Y = function (F) {
return (function (x) {
return F(function (y) { return (x(x))(y);});
})(function (x) {
return F(function (y) { return (x(x))(y);});
});
};
# elixir
defmodule Combinator do
def fix(f) do
(fn x ->
f.(fn y -> (x.(x)).(y) end)
end).(fn x ->
f.(fn y -> (x.(x)).(y) end)
end)
end
end
: Y = \f.(\x.f(x x))(\x.f(x x))
, F의 관계 람다 식 (X), 및 F, X 무엇 Y는로, 여기
y
은 무엇입니까? 특히
x x
에 해당하는 람다가
y
을 사용하는 함수로 래핑되는 이유는 무엇입니까?
y
은 함수의 인수와 비슷합니다.
당신은 Jim Weirich의 Ruby 기능성 프로그래밍에서이 비디오를 시청해야합니다. 이야기하는 동안 그는 Y Combinator를 단계별로 파생시킵니다. 매우 인상적이고 교육적이며 재미있는 영화입니다! https://www.youtube.com/watch?v=FITJMJjASUs –