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>
25 lines
778 B
Plaintext
25 lines
778 B
Plaintext
-- Church numerals with pattern matching
|
|
|
|
def czero : Π A : Type, (A → A) → A → A :=
|
|
λ(A : Type) λ(f : A → A) λ(x : A) x;
|
|
|
|
def csuc : (Π A : Type, (A → A) → A → A) → Π A : Type, (A → A) → A → A :=
|
|
λ(n : Π A : Type, (A → A) → A → A) λ(A : Type) λ(f : A → A) λ(x : A) f (n A f x);
|
|
|
|
def num : Nat → Π A : Type, (A → A) → A → A :=
|
|
λ(n : Nat) match n : Nat with : Π A : Type, (A → A) → A → A {
|
|
zero := czero;
|
|
suc (n : Nat) := csuc (num n);
|
|
};
|
|
|
|
def toNat : (Π A : Type, (A → A) → A → A) → Nat :=
|
|
λ(n : Π A : Type, (A → A) → A → A) n Nat suc zero;
|
|
|
|
def toInt : Nat → Int :=
|
|
λ(n : Nat) case n of {
|
|
zero := 0;
|
|
suc n := toInt n + 1;
|
|
};
|
|
|
|
toInt (toNat (num (suc (suc (suc zero)))))
|