mirror of
https://github.com/anoma/juvix.git
synced 2024-11-30 05:42:26 +03:00
3030196fdd
* Closes #2968 * Implements detection of function-like definitions, which either: - have some arguments on the left of `:`, or - have at least one clause. * Only function-like definitions are recursive. * Non-recursive definitions are not mutually recursive either, and can be used only after their definition. This necessitates rearranging some definitions in existing Juvix code. * Changes the scoping of identifiers in record updates. Now field names on the right side don't refer to the old values of the record fields but to identifiers in scope defined outside the record update. To refer to old values, one needs to explicitly use record projections, e.g. ``` r@Rec{x := Rec.x r} ```
43 lines
811 B
Plaintext
43 lines
811 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 := ite x false true;
|
|
|
|
{-# inline: false #-}
|
|
h (x : Bool) : Bool := ite (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 (dummy : Nat) : Nat := loop dummy;
|
|
|
|
{-# inline: false #-}
|
|
even' : Nat -> Bool := even;
|
|
|
|
main : Nat :=
|
|
sum 3
|
|
+ case even' 6 || g true || h true of {
|
|
| true := ite (g false) (f 1 2 + sum 7 + j 0) 0
|
|
| false := f (3 + 4) (f 0 8) + loop 0
|
|
};
|