quox/examples/pair.quox

56 lines
1.9 KiB
Plaintext
Raw Normal View History

2023-04-18 18:42:40 -04:00
namespace pair {
2023-05-21 14:33:42 -04:00
def0 Σ : 0.(A : ★) → 0.(0.A → ★) → ★ = λ A B ⇒ (x : A) × B x;
2023-04-18 18:42:40 -04:00
2023-05-21 14:33:42 -04:00
def fst : 0.(A : ★) → 0.(B : 0.A → ★) → ω.(Σ A B) → A =
2023-04-18 18:42:40 -04:00
λ A B p ⇒ caseω p return A of { (x, _) ⇒ x };
2023-05-21 14:33:42 -04:00
def snd : 0.(A : ★) → 0.(B : 0.A → ★) → ω.(p : Σ A B) → B (fst A B p) =
2023-04-18 18:42:40 -04:00
λ A B p ⇒ caseω p return p' ⇒ B (fst A B p') of { (_, y) ⇒ y };
def uncurry :
2023-05-21 14:33:42 -04:00
0.(A : ★) → 0.(B : 0.A → ★) → 0.(C : 0.(x : A) → 0.(B x) → ★) →
2023-04-18 18:42:40 -04:00
1.(f : 1.(x : A) → 1.(y : B x) → C x y) →
1.(p : Σ A B) → C (fst A B p) (snd A B p) =
λ A B C f p ⇒
case1 p return p' ⇒ C (fst A B p') (snd A B p') of { (x, y) ⇒ f x y };
def uncurry' :
2023-05-21 14:33:42 -04:00
0.(A B C : ★) → 1.(1.A → 1.B → C) → 1.(A × B) → C =
λ A B C ⇒ uncurry A (λ _ ⇒ B) (λ _ _ ⇒ C);
2023-04-18 18:42:40 -04:00
def curry :
2023-05-21 14:33:42 -04:00
0.(A : ★) → 0.(B : 0.A → ★) → 0.(C : 0.(Σ A B) → ★) →
2023-04-18 18:42:40 -04:00
1.(f : 1.(p : Σ A B) → C p) → 1.(x : A) → 1.(y : B x) → C (x, y) =
λ A B C f x y ⇒ f (x, y);
def curry' :
2023-05-21 14:33:42 -04:00
0.(A B C : ★) → 1.(1.(A × B) → C) → 1.A → 1.B → C =
λ A B C ⇒ curry A (λ _ ⇒ B) (λ _ ⇒ C);
2023-04-18 18:42:40 -04:00
def0 fst-snd :
2023-05-21 14:33:42 -04:00
0.(A : ★) → 0.(B : 0.A → ★) →
2023-04-18 18:42:40 -04:00
1.(p : Σ A B) → p ≡ (fst A B p, snd A B p) : Σ A B =
λ A B p ⇒
case1 p
return p' ⇒ p' ≡ (fst A B p', snd A B p') : Σ A B
of { (x, y) ⇒ δ 𝑖 ⇒ (x, y) };
def map :
2023-05-21 14:33:42 -04:00
0.(A A' : ★) →
0.(B : 0.A → ★) → 0.(B' : 0.A' → ★) →
2023-04-18 18:42:40 -04:00
1.(f : 1.A → A') → 1.(g : 0.(x : A) → 1.(B x) → B' (f x)) →
1.(Σ A B) → Σ A' B' =
λ A A' B B' f g p ⇒
case1 p return Σ A' B' of { (x, y) ⇒ (f x, g x y) };
2023-05-21 14:33:42 -04:00
def map' : 0.(A A' B B' : ★) →
1.(1.A → A') → 1.(1.B → B') → 1.(A × B) → A' × B' =
2023-04-18 18:42:40 -04:00
λ A A' B B' f g ⇒ map A A' (λ _ ⇒ B) (λ _ ⇒ B') f (λ _ ⇒ g);
}
def0 Σ = pair.Σ;
def fst = pair.fst;
def snd = pair.snd;