mirror of
https://github.com/anoma/juvix.git
synced 2024-12-12 14:28:08 +03:00
14 lines
343 B
Plaintext
14 lines
343 B
Plaintext
-- tail recursion through higher-order functions
|
|
|
|
def sumb := \f \x \acc if x = 0 then acc else f (x - 1) acc;
|
|
def sum' := \x \acc sumb sum' x (x + acc);
|
|
def sum := \x sum' x 0;
|
|
|
|
def writeLn := \x write x >> write "\n";
|
|
|
|
writeLn (sum 10000) >>
|
|
writeLn (sum 100000) >>
|
|
writeLn (sum 1000000) >>
|
|
writeLn (sum 10000000) >>
|
|
writeLn (sum 100000000)
|