1 (*********************************************************************************************************************************)
2 (* ProgrammingLanguage *)
4 (* Basic assumptions about programming languages. *)
6 (*********************************************************************************************************************************)
8 Generalizable All Variables.
9 Require Import Preamble.
10 Require Import General.
11 Require Import Categories_ch1_3.
12 Require Import InitialTerminal_ch2_2.
13 Require Import Functors_ch1_4.
14 Require Import Isomorphisms_ch1_5.
15 Require Import ProductCategories_ch1_6_1.
16 Require Import OppositeCategories_ch1_6_2.
17 Require Import Enrichment_ch2_8.
18 Require Import Subcategories_ch7_1.
19 Require Import NaturalTransformations_ch7_4.
20 Require Import NaturalIsomorphisms_ch7_5.
21 Require Import MonoidalCategories_ch7_8.
22 Require Import Coherence_ch7_8.
23 Require Import Enrichment_ch2_8.
24 Require Import RepresentableStructure_ch7_2.
25 Require Import FunctorCategories_ch7_7.
27 Require Import NaturalDeduction.
28 Require Import NaturalDeductionCategory.
30 Section Programming_Language.
32 Context {T : Type}. (* types of the language *)
34 Context (Judg : Type).
35 Context (sequent : Tree ??T -> Tree ??T -> Judg).
36 Notation "cs |= ss" := (sequent cs ss) : pl_scope.
38 Context {Rule : Tree ??Judg -> Tree ??Judg -> Type}.
40 Notation "H /⋯⋯/ C" := (ND Rule H C) : pl_scope.
46 Class ProgrammingLanguage :=
47 { pl_eqv : @ND_Relation Judg Rule where "pf1 === pf2" := (@ndr_eqv _ _ pl_eqv _ _ pf1 pf2)
48 ; pl_tsr :> @TreeStructuralRules Judg Rule T sequent
49 ; pl_sc :> @SequentCalculus Judg Rule _ sequent
50 ; pl_subst :> @CutRule Judg Rule _ sequent pl_eqv pl_sc
51 ; pl_sequent_join :> @SequentExpansion Judg Rule T sequent pl_eqv pl_sc pl_subst
53 Notation "pf1 === pf2" := (@ndr_eqv _ _ pl_eqv _ _ pf1 pf2) : temporary_scope3.
55 Section LanguageCategory.
57 Context (PL:ProgrammingLanguage).
59 (* category of judgments in a fixed type/coercion context *)
60 Definition Judgments_cartesian := @Judgments_Category_CartesianCat _ Rule pl_eqv.
62 Definition JudgmentsL := Judgments_cartesian.
64 Definition identityProof t : [] ~~{JudgmentsL}~~> [t |= t].
66 apply nd_seq_reflexive.
69 Definition cutProof a b c : [a |= b],,[b |= c] ~~{JudgmentsL}~~> [a |= c].
74 Definition TypesL : ECategory JudgmentsL (Tree ??T) (fun x y => [x|=y]).
76 {| eid := identityProof
79 apply MonoidalCat_all_central.
80 apply MonoidalCat_all_central.
81 unfold identityProof; unfold cutProof; simpl.
82 apply nd_cut_left_identity.
83 unfold identityProof; unfold cutProof; simpl.
84 apply nd_cut_right_identity.
85 unfold identityProof; unfold cutProof; simpl.
87 apply nd_cut_associativity.
90 Definition Types_first c : EFunctor TypesL TypesL (fun x => x,,c ).
91 refine {| efunc := fun x y => (@se_expand_right _ _ _ _ _ _ _ (@pl_sequent_join PL) c x y) |}.
92 intros; apply MonoidalCat_all_central.
93 intros. unfold ehom. unfold hom. unfold identityProof. unfold eid. simpl. unfold identityProof.
94 apply se_reflexive_right.
95 intros. unfold ehom. unfold comp. simpl. unfold cutProof.
96 rewrite <- (@ndr_prod_preserves_comp _ _ pl_eqv _ _ (se_expand_right _ c) _ _ (nd_id1 (b|=c0))
97 _ (nd_id1 (a,,c |= b,,c)) _ (se_expand_right _ c)).
98 setoid_rewrite (@ndr_comp_right_identity _ _ pl_eqv _ [a,, c |= b,, c]).
99 setoid_rewrite (@ndr_comp_left_identity _ _ pl_eqv [b |= c0]).
103 Definition Types_second c : EFunctor TypesL TypesL (fun x => c,,x).
104 eapply Build_EFunctor.
105 instantiate (1:=(fun x y => ((@se_expand_left _ _ _ _ _ _ _ (@pl_sequent_join PL) c x y)))).
106 intros; apply MonoidalCat_all_central.
107 intros. unfold ehom. unfold hom. unfold identityProof. unfold eid. simpl. unfold identityProof.
108 apply se_reflexive_left.
109 intros. unfold ehom. unfold comp. simpl. unfold cutProof.
110 rewrite <- (@ndr_prod_preserves_comp _ _ pl_eqv _ _ (se_expand_left _ c) _ _ (nd_id1 (b|=c0))
111 _ (nd_id1 (c,,a |= c,,b)) _ (se_expand_left _ c)).
112 setoid_rewrite (@ndr_comp_right_identity _ _ pl_eqv _ [c,,a |= c,,b]).
113 setoid_rewrite (@ndr_comp_left_identity _ _ pl_eqv [b |= c0]).
117 Definition Types_binoidal : BinoidalCat TypesL (@T_Branch _).
119 {| bin_first := Types_first
120 ; bin_second := Types_second
124 Definition Types_assoc a b : Types_second a >>>> Types_first b <~~~> Types_first b >>>> Types_second a.
128 Definition Types_cancelr : Types_first [] <~~~> functor_id _.
132 Definition Types_cancell : Types_second [] <~~~> functor_id _.
136 Definition Types_assoc_ll a b : Types_second (a,,b) <~~~> Types_second b >>>> Types_second a.
140 Definition Types_assoc_rr a b : Types_first (a,,b) <~~~> Types_first a >>>> Types_first b.
144 Instance Types_PreMonoidal : PreMonoidalCat Types_binoidal [] :=
145 { pmon_assoc := Types_assoc
146 ; pmon_cancell := Types_cancell
147 ; pmon_cancelr := Types_cancelr
148 ; pmon_assoc_rr := Types_assoc_rr
149 ; pmon_assoc_ll := Types_assoc_ll
151 admit. (* pentagon law *)
152 admit. (* triangle law *)
153 admit. (* assoc_rr/assoc coherence *)
154 admit. (* assoc_ll/assoc coherence *)
157 Definition TypesEnrichedInJudgments : Enrichment.
158 refine {| enr_c := TypesL |}.
161 Structure HasProductTypes :=
165 Lemma CartesianEnrMonoidal (e:Enrichment) `(C:CartesianCat(Ob:= _)(Hom:= _)(C:=Underlying (enr_c e))) : MonoidalEnrichment e.
169 (* need to prove that if we have cartesian tuples we have cartesian contexts *)
170 Definition LanguagesWithProductsAreSMME : HasProductTypes -> SurjectiveMonicMonoidalEnrichment TypesEnrichedInJudgments.
174 End LanguageCategory.
176 End Programming_Language.
178 Structure ProgrammingLanguageSMME :=
181 ; plsmme_sequent : Tree ??plsmme_t -> Tree ??plsmme_t -> plsmme_judg
182 ; plsmme_rule : Tree ??plsmme_judg -> Tree ??plsmme_judg -> Type
183 ; plsmme_pl : @ProgrammingLanguage plsmme_t plsmme_judg plsmme_sequent plsmme_rule
184 ; plsmme_smme : SurjectiveMonicMonoidalEnrichment (TypesEnrichedInJudgments _ _ plsmme_pl)
186 Coercion plsmme_pl : ProgrammingLanguageSMME >-> ProgrammingLanguage.
187 Coercion plsmme_smme : ProgrammingLanguageSMME >-> SurjectiveMonicMonoidalEnrichment.
189 Implicit Arguments ND [ Judgment ].