mirror of
https://github.com/anoma/juvix.git
synced 2025-01-05 22:46:08 +03:00
336a934d18
* Closes #2032. * Adds the `juvix dev core normalize` command. * Adds the `:n` command in JuvixCore REPL. * Adds the `--normalize` flag to `juvix dev core read` and `juvix dev core from-concrete`. * Adds `pipeline-normalize` which denotes pipeline steps necessary before normalization. * Adds normalization tests in `tests/VampIR/positive/Core`.
51 lines
1.2 KiB
Plaintext
51 lines
1.2 KiB
Plaintext
-- letrec
|
|
|
|
def sum : Int -> Int := letrec sum : Int -> Int := \(x : Int) if x = 0 then 0 else x + sum (x - 1) in sum;
|
|
|
|
def fact : Int -> Int := \(x : Int)
|
|
letrec fact' : Int -> Int -> Int := \(x : Int) \(acc : Int) if x = 0 then acc else fact' (x - 1) (acc * x)
|
|
in fact' x 1;
|
|
|
|
def fib : Int -> Int :=
|
|
letrec fib' : Int -> Int -> Int -> Int := \(n : Int) \(x : Int) \(y : Int) if n = 0 then x else fib' (n - 1) y (x + y)
|
|
in \(n : Int) fib' n 0 1;
|
|
|
|
def mutrec : Int -> Int -> Int := \(x5 : Int) \(x10 : Int)
|
|
let two : Int := 2 in
|
|
let one : Int := 1 in
|
|
letrec[f g h]
|
|
f : Int -> Int := \(x : Int) {
|
|
if x < one then
|
|
one
|
|
else
|
|
g (x - one) + two * x
|
|
};
|
|
g : Int -> Int := \(x : Int) {
|
|
if x < one then
|
|
one
|
|
else
|
|
x + h (x - one)
|
|
};
|
|
h : Int -> Int := \(x : Int) letrec z : Int := {
|
|
if x < one then
|
|
one
|
|
else
|
|
x * f (x - one)
|
|
} in z;
|
|
in f x5 + f x10 + g x5 + h x5;
|
|
|
|
\(x3 : Int) \(x5 : Int) \(x10 : Int) \(x100 : Int)
|
|
letrec x : Int := x3
|
|
in
|
|
x +
|
|
sum x100 +
|
|
fact x5 +
|
|
fib x10 +
|
|
mutrec x5 x10 +
|
|
letrec x : Int := 1 in
|
|
letrec x' : Int := x + letrec x : Int := 2 in x in
|
|
letrec x : Int := x' * x' in
|
|
letrec y : Int := x + 2 in
|
|
letrec z : Int := x + y in
|
|
x + y + z
|