mirror of
https://github.com/anoma/juvix.git
synced 2024-12-04 06:23:13 +03:00
98b1daec7d
Print JuvixCore InfoTable in such a way that it can be parsed back by the JuvixCore parser. * Depends on PR #1832 * Depends on PR #1862 * Closes #1841 * Adds "JuvixCore print" tests which read the files from Core/positive/*.jvc, print them, read them back and check if the evaluation results are preserved. --------- Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
54 lines
992 B
Plaintext
54 lines
992 B
Plaintext
-- 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))
|