mirror of
https://github.com/anoma/juvix.git
synced 2025-01-07 08:08:44 +03:00
272b93e595
* Closes #2154 * Evaluates closed applications with value arguments when the result type is zero-order. For example, `3 + 4` is evaluated to `7`, and `id 3` is evaluated to `3`, but `id id` is not evaluated because the target type is not zero-order (it's a function type).
43 lines
801 B
Plaintext
43 lines
801 B
Plaintext
-- Constant folding
|
|
module test064;
|
|
|
|
import Stdlib.Prelude open;
|
|
import Stdlib.Debug.Fail as Debug;
|
|
|
|
{-# inline: false #-}
|
|
f (x y : Nat) : Nat := x + y;
|
|
|
|
{-# inline: false #-}
|
|
g (x : Bool) : Bool := if x (Debug.failwith "a") true;
|
|
|
|
{-# inline: false #-}
|
|
h (x : Bool) : Bool := if (g x) false true;
|
|
|
|
{-# inline: false, eval: false #-}
|
|
j (x : Nat) : Nat := x + 0;
|
|
|
|
sum : Nat -> Nat
|
|
| zero := 0
|
|
| k@(suc n) := k + sum n;
|
|
|
|
even : Nat -> Bool
|
|
| zero := true
|
|
| (suc n) := odd n;
|
|
|
|
odd : Nat -> Bool
|
|
| zero := false
|
|
| (suc n) := even n;
|
|
|
|
terminating
|
|
loop : Nat := loop;
|
|
|
|
{-# inline: false #-}
|
|
even' : Nat -> Bool := even;
|
|
|
|
main : Nat :=
|
|
sum 3
|
|
+ case even' 6 || g true || h true of {
|
|
| true := if (g false) (f 1 2 + sum 7 + j 0) 0
|
|
| false := f (3 + 4) (f 0 8) + loop
|
|
};
|