1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-12 04:43:18 +03:00
juvix/tests/Core/positive/test050.jvc

25 lines
778 B
Plaintext
Raw Normal View History

-- 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)))))