2023-04-18 18:42:40 -04:00
|
|
|
|
namespace pair {
|
|
|
|
|
|
2023-07-18 17:12:04 -04:00
|
|
|
|
def0 Σ : (A : ★) → (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-07-18 17:12:04 -04:00
|
|
|
|
(f : (x : A) → (y : B x) → C x y) →
|
|
|
|
|
(p : Σ A B) → C (fst A B p) (snd A B p) =
|
2023-04-18 18:42:40 -04:00
|
|
|
|
λ A B C f p ⇒
|
2023-07-18 17:12:04 -04:00
|
|
|
|
case p return p' ⇒ C (fst A B p') (snd A B p') of { (x, y) ⇒ f x y };
|
2023-04-18 18:42:40 -04:00
|
|
|
|
|
2023-04-19 15:36:57 -04:00
|
|
|
|
def uncurry' :
|
2023-07-18 17:12:04 -04:00
|
|
|
|
0.(A B C : ★) → (A → B → C) → (A × B) → C =
|
2023-04-19 15:36:57 -04:00
|
|
|
|
λ 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-07-18 17:12:04 -04:00
|
|
|
|
(f : (p : Σ A B) → C p) → (x : A) → (y : B x) → C (x, y) =
|
2023-04-18 18:42:40 -04:00
|
|
|
|
λ A B C f x y ⇒ f (x, y);
|
|
|
|
|
|
2023-04-19 15:36:57 -04:00
|
|
|
|
def curry' :
|
2023-07-18 17:12:04 -04:00
|
|
|
|
0.(A B C : ★) → ((A × B) → C) → A → B → C =
|
2023-04-19 15:36:57 -04:00
|
|
|
|
λ A B C ⇒ curry A (λ _ ⇒ B) (λ _ ⇒ C);
|
|
|
|
|
|
2023-04-18 18:42:40 -04:00
|
|
|
|
def0 fst-snd :
|
2023-07-18 17:12:04 -04:00
|
|
|
|
(A : ★) → (B : 0.A → ★) →
|
|
|
|
|
(p : Σ A B) → p ≡ (fst A B p, snd A B p) : Σ A B =
|
2023-04-18 18:42:40 -04:00
|
|
|
|
λ A B p ⇒
|
2023-07-18 17:12:04 -04:00
|
|
|
|
case p
|
2023-04-18 18:42:40 -04:00
|
|
|
|
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-07-18 17:12:04 -04:00
|
|
|
|
(f : A → A') → (g : 0.(x : A) → (B x) → B' (f x)) →
|
|
|
|
|
(Σ A B) → Σ A' B' =
|
2023-04-18 18:42:40 -04:00
|
|
|
|
λ A A' B B' f g p ⇒
|
2023-07-18 17:12:04 -04:00
|
|
|
|
case p return Σ A' B' of { (x, y) ⇒ (f x, g x y) };
|
2023-04-18 18:42:40 -04:00
|
|
|
|
|
2023-07-18 17:12:04 -04:00
|
|
|
|
def map' : 0.(A A' B B' : ★) → (A → A') → (B → B') → (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;
|