1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-04 17:07:28 +03:00
juvix/tests/Core/positive/test041.jvc

54 lines
992 B
Plaintext
Raw Normal View History

-- match
type list {
cons : Any -> list -> list;
nil : list;
};
def lgen := \n if n = 0 then nil else cons n (lgen (n - 1));
def sum2 := \x {
match x with {
cons x y@(cons z _) := cons (x + z) (sum2 y);
_ := x
}
};
type tree {
leaf : tree;
node : tree -> tree -> tree;
};
def gen := \n if n <= 0 then leaf else node (gen (n - 2)) (gen (n - 1));
def g;
def f := \t match t with {
leaf := 1;
node l r :=
match g l, g r with {
leaf, leaf := 0 - 6;
node l r, leaf := ((f l + f r) * 2) % 20000;
node l1 r1, node l2 r2 := ((f l1 + f r1) * (f l2 + f r2)) % 20000;
_, node l r := ((f l + f r) * (0 - 3)) % 20000;
}
};
def g := \t {
match t with {
leaf := t;
node (node _ _) r := r;
node l r := node r l;
}
};
def writeLn := \x write x >> write "\n";
writeLn (sum2 (lgen 5)) >>
writeLn (f (gen 10)) >>
writeLn (f (gen 15)) >>
writeLn (f (gen 16)) >>
writeLn (f (gen 17)) >>
writeLn (f (gen 18)) >>
writeLn (f (gen 20))