From 3d7b2ecc046b1c8c57766eef325590fd66cb5032 Mon Sep 17 00:00:00 2001 From: Gryfenfer97 Date: Sat, 1 Feb 2025 19:55:25 +0100 Subject: add pred function --- languages/c/c++/lambda-core.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'languages/c') 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); } -- cgit v1.2.3