Solution like in Haskell is possible for any language that supports lambdas Like that: auto twice(auto f) { return [=](){f(); f();}; } // Somewhere else twice(twice(twice([](){cout
@ramnie69999 ай бұрын
The key trick of the Haskell solution is that you can pass one of your "repeater" functions to another (or the same) repeater function to get the effect of exponentiation. For example, (five five) is a function that repeats the given function 3125 times. For this to work, your repeater functions need to have the same return type as the argument type, which in turn requires the use of std::function or something similar when using a language that gives a different type to each lambda.
@ДмитрийСтрахаль9 ай бұрын
@@ramnie6999 Ok, i did a couple experiments, and: In dynamic languages it works easy, in Rust it refused to work until i moved functions into Box, in C++ it required std::function. Maybe Haskell being a static typed language allows such thing because of immutability
個人的にこれが割とシンプルで好きだったんだけどレギュ的にどうなんだろ ```c #define A puts("Hello, world! ); #define B A A A A A A A A A A // 10 回 #define C B B B B B B B B B B // 100 回 #define D C C C C C C C C C C // 1000 回 #define E D D D D D D D D D D // 10000 回 #define F E E E E E E E E E E // 100000 回 #define G F F F F F F F F F F // 1000000 回 int main(void) { G return 0; } ```