diff options
author | Gryfenfer97 | 2025-02-01 19:55:25 +0100 |
---|---|---|
committer | Gryfenfer97 | 2025-02-01 19:55:25 +0100 |
commit | 3d7b2ecc046b1c8c57766eef325590fd66cb5032 (patch) | |
tree | 19803855f640b756fe4d0f149f680e6df4423dd6 /languages | |
parent | 982fed7f0e1e52479151c3e43d78d6cf35684250 (diff) |
add pred function
Diffstat (limited to 'languages')
-rw-r--r-- | languages/c/c++/lambda-core.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/languages/c/c++/lambda-core.cpp b/languages/c/c++/lambda-core.cpp index 3c1ae20..a6ce614 100644 --- a/languages/c/c++/lambda-core.cpp +++ b/languages/c/c++/lambda-core.cpp @@ -39,6 +39,16 @@ constexpr auto succ = [](const auto &n) { constexpr auto one = succ(zero); +constexpr auto pred(const auto &n) { + return [&n](const auto &f) { + return [&n, &f](auto x) { + return n([&f](const auto &g) { + return [&f, g](const auto &h) { return h(g(f)); }; + })([x](const auto &u) { return x; })([](const auto &a) { return a; }); + }; + }; +} + namespace test { constexpr unsigned int convert(const auto &n) { return n([](const auto &x) { return x + 1; })(0); @@ -62,6 +72,6 @@ int main() { static_assert(church::test::convert(zero) == 0); static_assert(church::test::convert(succ(zero)) == 1); - // static_assert(church::test::convert(pred(succ(one))) == 1); + static_assert(church::test::convert(pred(succ(one))) == 1); church::test::print(one); } |