1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-03 09:41:10 +03:00
juvix/tests/Compilation/positive/test015.juvix
2024-07-02 10:03:06 +02:00

39 lines
650 B
Plaintext

-- local functions with free variables
module test015;
import Stdlib.Prelude open;
terminating
f : Nat → Nat → Nat
| x :=
let
g (y : Nat) : Nat := x + y;
in if
| x == 0 := f 10
| else := ite (x < 10) λ {y := g (f (sub x 1) y)} g;
g (x : Nat) (h : Nat → Nat) : Nat := x + h x;
terminating
h : Nat → Nat
| zero := 0
| (suc x) := g x h;
main : IO :=
printNatLn (f 100 500)
>>> -- 600
printNatLn
(f 5 0)
>>> -- 25
printNatLn
(f 5 5)
>>> -- 30
printNatLn
(h 10)
>>> -- 45
printNatLn
(g 10 h)
>>> -- 55
printNatLn
(g 3 (f 10));