Created
August 11, 2021 09:30
-
-
Save howardlau1999/9ef6060a2c5a8f7072ccda0f5bee487c to your computer and use it in GitHub Desktop.
Y Combinator in C++20
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
#include <iostream> | |
int main() { | |
auto result = [](auto&& g) { | |
return [](auto&& f) { | |
return f(f); | |
}([&g](auto&& f) { return g([&f](auto&& x) { return f(f)(x); }); }); | |
}([](auto&& f) { | |
return [&f](auto&& x) -> int { return x == 0 ? 1 : x * f(x - 1); }; | |
})(5); | |
std::cout << result << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment