
$ $ % % CCC vs. Cartesian closed categories - 139 - category theory typed lambda-calculi ' ' & & ''typed functional programming $$ vs. category theory && %% Andrzej Tarlecki: Category Theory, 2018 Cartesian categories Definition: A category K is Cartesian if it comes equipped with finite products. Equivalently: • 1 2 jKj | a terminal object • A × B | a product of A and B, for every A; B 2 jKj op Examples: Set, Pfn, Cpo, semilattices, Cat, TΣ;Φ,... Recall the definitions of these categories and the constructions of products in each of them Andrzej Tarlecki: Category Theory, 2018 - 140 - Cartesian closed categories Definition: A Cartesian category K is closed if for all B; C 2 jKj we indicate [B!C] 2 jK and "B;C :[B!C] × B ! C such that for all A 2 jKj and f : A × B ! C there is a unique Λ(f): A ! [B!C] satisfying (Λ(f) × idB );"B;C = f × B KK - "B;C [B!C] [B!C] × B - C ¨* 6 6 ¨¨ ¨ 9! Λ(f)Λ( f) × idB ¨¨ ¨ f ¨¨ A A × B Examples: Set, Cpo, Cat,... Heyting semilattices (b ( c is such that for all a, a ^ b ≤ c iff a ≤ (b ( c) op Non-examples: Pfn, TΣ;Φ. Andrzej Tarlecki: Category Theory, 2018 - 141 - Summing up A category K is a Cartesian closed category (CCC) if: • C : K ! 1 has a right adjoint C1 : 1 ! K, yielding 1 2 jKj. • ∆: K ! K × K has a right adjoint × : K × K ! K with counit given by 0 πA;B : A × B ! A and πA;B : A × B ! B for A; B 2 jKj. • for each B 2 jKj, × B : K ! K has right adjoint [B! ]: K ! K, with counit given by "B;C :[B!C] × B ! C, for C 2 jKj. Andrzej Tarlecki: Category Theory, 2018 - 142 - Spelling this out • 1 2 jKj − for A 2 jKj: hiA : A ! 1 such that hiA = f for all f : A ! 1. 0 • for A; B 2 jKj, A × B 2 jKj, πA;B : A × B ! A, πA;B : A × B ! B: − for C 2 jKj, for f : C ! A, g : C ! B: hf; gi: C ! A × B such that 0 −h f; gi;πA;B = f and hf; gi;πA;B = g 0 − for h: C ! A × B, h = hh;πA;B; h;πA;Bi • for B; C 2 jKj, [B!C] 2 jKj, "B;C :[B!C] × B ! C: − for A 2 jKj, for f : A × B ! C: Λ(f): A ! [B!C] such that − (Λ(f) × idB );"B;C = f − for h: A ! [B!C], Λ((h × idB );"B;C ) = h. Andrzej Tarlecki: Category Theory, 2018 - 143 - Typed λ-calculus with products Types The set T of types τ 2 T is such that • 1 2 T • τ×τ 0 2 T , for all τ; τ 0 2 T T need not be the least such that. • τ!τ 0 2 T , for all τ; τ 0 2 T Note: Contexts Contexts Γ are of the form: • x1:τ1; : : : ; xn:τn, where n ≥ 0, x1; : : : ; xn are distinct variables, and τ1; : : : ; τn 2 T Andrzej Tarlecki: Category Theory, 2018 - 144 - Typed terms in contexts Γ ` t: τ Typing/formation rules coming next Omitting the usual definitions, like: • free variables FV (M), Same for the usual simple properties, like: • substitution M[N=x], etc. • weakening | context extension; • subject reduction; • uniqueness of types; • removing unused variables from contexts; etc Andrzej Tarlecki: Category Theory, 2018 - 145 - Typing rules x1:τ1; : : : ; xn:τn ` xi : τi x1:τ1; : : : ; xn:τn ` M : τ x1:τ1; : : : ; xi−1:τi−1; xi+1:τi+1; : : : ; xn:τn ` λxi:τi:M : τi!τ Γ ` M : τ!τ 0 Γ ` N : τ Γ ` MN : τ 0 Γ ` M : τ Γ ` N : τ 0 Γ ` hi: 1 Γ ` hM; Ni: τ×τ 0 0 0 0 0 Γ ` πτ,τ 0 : τ×τ !τ Γ ` πτ,τ 0 : τ×τ !τ Andrzej Tarlecki: Category Theory, 2018 - 146 - Semantics Let K be an arbitrary but fixed CCC. • Types denote objects, [[τ]] 2 jKj, satisfying: − [[1]] = 1 − [[τ×τ 0]] = [[τ]] × [[τ 0]] − [[τ!τ 0]] = [[[τ]]![[τ 0]]] • So do contexts: − [[x1:τ1; : : : ; xn:τn]] = [[τ1]] × ::: × [[τn]] • Terms denote morphisms: [[M]]: [[Γ]] ! [[τ]] defined by induction on the derivation of Γ ` M : τ (coming next). Andrzej Tarlecki: Category Theory, 2018 - 147 - Semantics of λ-terms − [[xi]] = πi : [[Γ]] ! [[τi]] for Γ = x1:τ1; : : : ; xn:τn, where πi is the obvious projection. 0 − [[λxi:τi:M]] = Λ(ρ;[[M]]): [[Γ ]] ! [[[τi]]![[τ]]] for Γ = x1:τ1; : : : ; xn:τn, 0 Γ = x1:τ1; : : : ; xi−1:τi−1; xi+1:τi+1; : : : ; xn:τn, and Γ ` M : τ, where 0 ρ: [[Γ ]] × [[τi]] ! [[Γ]] is the obvious isomorphism. 0 0 − [[MN]] = h[[M]]; [[N]]i;"[[τ]];[[τ 0]] : [[Γ]] ! [[τ ]] for Γ ` M : τ!τ and Γ ` N : τ. − [[hi]] = hi[[Γ]] : [[Γ]] ! 1 − [[hM; Ni]] = h[[M]]; [[N]]i: [[Γ]] ! [[τ]] × [[τ 0]] for Γ ` M : τ and Γ ` N : τ 0. 0 0 − [[πτ,τ 0 ]] = Λ(π[[Γ]];[[τ]]×[[τ 0]];π[[τ]];[[τ 0]]): [[Γ]] ! [[[τ]] × [[τ ]]![[τ]]] and 0 0 0 0 0 [[πτ,τ 0 ]] = Λ(π[[Γ]];[[τ]]×[[τ 0]];π[[τ]];[[τ 0]]): [[Γ]] ! [[[τ]] × [[τ ]]![[τ ]]] Andrzej Tarlecki: Category Theory, 2018 - 148 - Equational β; η-calculus Judgements: Γ ` M = N : τ for τ 2 T , Γ ` M : τ, Γ ` N : τ Axioms: (β)Γ ` (λx:τ:M)N = M[N=x]: τ 0, for Γ ` λx:τ:M : τ!τ 0, Γ ` N : τ (η)Γ ` λx:τ:Mx = M : τ!τ 0, for Γ ` M : τ!τ 0, x 62 dom(Γ) • Γ ` M = hi: 1, for γ ` M : 1 0 0 • Γ ` πτ,τ 0 hM; Ni = M : τ and Γ ` πτ,τ 0 hM; Ni = N : τ , for Γ ` M : τ, Γ ` N : τ 0 0 0 0 • Γ ` M = hπτ,τ 0 M; πτ,τ 0 Mi: τ×τ , for Γ ` M : τ×τ Rules: reflexivity, symmetry, transitivity, congruence. Andrzej Tarlecki: Category Theory, 2018 - 149 - Soundness Given Γ ` M : τ and Γ ` N : τ if Γ ` M = N : τ then [[M]] = [[N]] Proof: :-) Just check that the axioms and rules of the equational β; η-calculus are sound w.r.t. the semantics in any CCC. For example: (η) for Γ ` M : τ!τ 0, x 62 dom(Γ), given the isomorphism ρ: [[Γ]] × [[τ]] ! [[Γ; x:τ]]: [[λx:τ:Mx]] = Λ(ρ;[[Mx]]) = Λ(ρ;(h[[M]]; [[x]]i;"[[τ]];[[τ 0]])) = Λ(hρ;[[M]]; ρ;[[x]]i;"[[τ]];[[τ 0]]) = Λ(([[M]] × id[[τ]]);"[[τ]];[[τ 0]]) = [[M]]. Warning: The \real work" is in the proof of soundess for (β), where induction on the structure of terms is needed. Andrzej Tarlecki: Category Theory, 2018 - 150 - Completeness Given Γ ` M : τ and Γ ` N : τ, if in every CCC, [[M]] = [[N]] then Γ ` M = N : τ Proof: It is enough to prove this for terms in the empty context. Define a CCC λλ: • Category λλ: − objects are all types: jλλj = T − morphisms are λ-terms modulo equality: λλ(τ; τ 0) = fM j ` M : τ!τ 0g=≈, where M ≈ N iff ` M = N : τ 0!τ 0 0 00 − composition: [M]≈;[N]≈ = [λx:τ:N(Mx)]≈, for ` M : τ!τ , ` N : τ !τ − identities: idτ = [λx:τ:x]≈. Andrzej Tarlecki: Category Theory, 2018 - 151 - • Products in λλ: − terminal object 1 2 jλλj, with hiτ = [λx:τ:hi]≈ 0 0 0 − binary product τ×τ , with πτ,τ 0 = [πτ,τ 0 ]≈, πτ,τ 0 = [πτ,τ 0 ]≈ and pairing 0 h[M]≈; [N]≈i = [hM; Ni]≈ for ` M : τ, ` N : τ . 0 0 0 • Exponent in λλ: τ!τ , with "τ,τ 0 = [λx:(τ!τ )×τ:(πτ!τ 0,τ x)(πτ!τ 0,τ x)]≈ and 0 0 00 Λ([M]≈) = [λx:τ.λy:τ :Mhx; yi]≈, for ` M : τ×τ !τ . Now: if in every CCC, [[M]] = [[N]], then this holds in particular in λλ, and so Γ ` M = N : τ. To wrap this up: add constants of arbitrary types SUMMING UP: CCCs coincide with λ-calculi Andrzej Tarlecki: Category Theory, 2018 - 152 -.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages14 Page
-
File Size-