mirror of
https://github.com/anoma/juvix.git
synced 2024-12-12 14:28:08 +03:00
19 lines
352 B
Plaintext
19 lines
352 B
Plaintext
|
-- tail recursion
|
||
|
module test009;
|
||
|
|
||
|
import Stdlib.Prelude open;
|
||
|
|
||
|
sum' (acc : Nat) : Nat → Nat
|
||
|
| zero := acc
|
||
|
| (suc x) := sum' (suc x + acc) x;
|
||
|
|
||
|
sum : Nat → Nat := sum' 0;
|
||
|
|
||
|
fact' (acc : Nat) : Nat → Nat
|
||
|
| zero := acc
|
||
|
| (suc x) := fact' (acc * suc x) x;
|
||
|
|
||
|
fact : Nat → Nat := fact' 1;
|
||
|
|
||
|
main : Nat := sum 10000 + fact 5 + fact 10 + fact 12;
|