1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-06 00:16:14 +03:00
juvix/tests/Rust/Compilation/positive/test035.juvix
Paul Cadman b8cd84170b
Update juvix-stdlib to remove non-ASCII indentifiers (#2857)
This PR updates the juvix-stdlib to the current main commit which
includes:

* https://github.com/anoma/juvix-stdlib/issues/59
* https://github.com/anoma/juvix-stdlib/issues/101

All the Juvix test suite files and examples in this repo have been
updated to be compatible with the new stdlib.
2024-06-26 10:23:35 +02:00

59 lines
1.1 KiB
Plaintext

-- pattern matching
module test035;
import Stdlib.Prelude open;
lgen : Nat → List Nat
| zero := nil
| (suc n) := suc n :: lgen n;
sum2 : List Nat → List Nat
| (x :: y :: xs) := x + y :: sum2 (y :: xs)
| xs := xs;
type Tree :=
| leaf : Tree
| node : Tree -> Tree -> Tree;
gen : Nat → Tree
| zero := leaf
| (suc zero) := node leaf leaf
| (suc (suc n)) := node (gen n) (gen (suc n));
terminating
f : Tree → Nat
| leaf := 1
| (node l r) :=
case g l, g r of {
| leaf, leaf := 3
| node l r, leaf := mod ((f l + f r) * 2) 20000
| node l1 r1, node l2 r2 :=
mod ((f l1 + f r1) * (f l2 + f r2)) 20000
| _, node l r := mod (f l + f r) 20000
};
g : Tree → Tree
| leaf := leaf
| (node (node _ _) r) := r
| (node l r) := node r l;
h : Nat -> Nat
| (suc (suc (suc (suc n)))) := n
| _ := 0;
printListNatLn : List Nat → IO
| nil := printStringLn "nil"
| (x :: xs) :=
printNat x >>> printString " :: " >>> printListNatLn xs;
main : Nat :=
head 0 (sum2 (lgen 5))
+ f (gen 10)
+ f (gen 15)
+ f (gen 16)
+ f (gen 17)
+ f (gen 18)
+ f (gen 20)
+ h 5
+ h 3;