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 BinoidalCategories.
22 Require Import PreMonoidalCategories.
23 Require Import MonoidalCategories_ch7_8.
24 Require Import Coherence_ch7_8.
25 Require Import Enrichment_ch2_8.
26 Require Import RepresentableStructure_ch7_2.
27 Require Import FunctorCategories_ch7_7.
29 Require Import NaturalDeduction.
30 Require Import NaturalDeductionCategory.
32 Section Programming_Language.
34 Context {T : Type}. (* types of the language *)
36 Context (Judg : Type).
37 Context (sequent : Tree ??T -> Tree ??T -> Judg).
38 Notation "cs |= ss" := (sequent cs ss) : pl_scope.
40 Context {Rule : Tree ??Judg -> Tree ??Judg -> Type}.
42 Notation "H /⋯⋯/ C" := (ND Rule H C) : pl_scope.
48 Class ProgrammingLanguage :=
49 { pl_eqv : @ND_Relation Judg Rule where "pf1 === pf2" := (@ndr_eqv _ _ pl_eqv _ _ pf1 pf2)
50 ; pl_tsr :> @TreeStructuralRules Judg Rule T sequent
51 ; pl_sc :> @SequentCalculus Judg Rule _ sequent
52 ; pl_subst :> @CutRule Judg Rule _ sequent pl_eqv pl_sc
53 ; pl_sequent_join :> @SequentExpansion Judg Rule T sequent pl_eqv pl_sc pl_subst
55 Notation "pf1 === pf2" := (@ndr_eqv _ _ pl_eqv _ _ pf1 pf2) : temporary_scope3.
57 Section LanguageCategory.
59 Context (PL:ProgrammingLanguage).
61 (* category of judgments in a fixed type/coercion context *)
62 Definition Judgments_cartesian := @Judgments_Category_CartesianCat _ Rule pl_eqv.
64 Definition JudgmentsL := Judgments_cartesian.
66 Definition identityProof t : [] ~~{JudgmentsL}~~> [t |= t].
68 apply nd_seq_reflexive.
71 Definition cutProof a b c : [a |= b],,[b |= c] ~~{JudgmentsL}~~> [a |= c].
76 Definition TypesL : ECategory JudgmentsL (Tree ??T) (fun x y => [x|=y]).
78 {| eid := identityProof
81 apply MonoidalCat_all_central.
82 apply MonoidalCat_all_central.
83 unfold identityProof; unfold cutProof; simpl.
84 apply nd_cut_left_identity.
85 unfold identityProof; unfold cutProof; simpl.
86 apply nd_cut_right_identity.
87 unfold identityProof; unfold cutProof; simpl.
89 apply nd_cut_associativity.
92 Definition Types_first c : EFunctor TypesL TypesL (fun x => x,,c ).
93 refine {| efunc := fun x y => (@se_expand_right _ _ _ _ _ _ _ (@pl_sequent_join PL) c x y) |}.
94 intros; apply MonoidalCat_all_central.
95 intros. unfold ehom. unfold hom. unfold identityProof. unfold eid. simpl. unfold identityProof.
96 apply se_reflexive_right.
97 intros. unfold ehom. unfold comp. simpl. unfold cutProof.
98 rewrite <- (@ndr_prod_preserves_comp _ _ pl_eqv _ _ (se_expand_right _ c) _ _ (nd_id1 (b|=c0))
99 _ (nd_id1 (a,,c |= b,,c)) _ (se_expand_right _ c)).
100 setoid_rewrite (@ndr_comp_right_identity _ _ pl_eqv _ [a,, c |= b,, c]).
101 setoid_rewrite (@ndr_comp_left_identity _ _ pl_eqv [b |= c0]).
105 Definition Types_second c : EFunctor TypesL TypesL (fun x => c,,x).
106 eapply Build_EFunctor.
107 instantiate (1:=(fun x y => ((@se_expand_left _ _ _ _ _ _ _ (@pl_sequent_join PL) c x y)))).
108 intros; apply MonoidalCat_all_central.
109 intros. unfold ehom. unfold hom. unfold identityProof. unfold eid. simpl. unfold identityProof.
110 apply se_reflexive_left.
111 intros. unfold ehom. unfold comp. simpl. unfold cutProof.
112 rewrite <- (@ndr_prod_preserves_comp _ _ pl_eqv _ _ (se_expand_left _ c) _ _ (nd_id1 (b|=c0))
113 _ (nd_id1 (c,,a |= c,,b)) _ (se_expand_left _ c)).
114 setoid_rewrite (@ndr_comp_right_identity _ _ pl_eqv _ [c,,a |= c,,b]).
115 setoid_rewrite (@ndr_comp_left_identity _ _ pl_eqv [b |= c0]).
119 Definition Types_binoidal : BinoidalCat TypesL (@T_Branch _).
121 {| bin_first := Types_first
122 ; bin_second := Types_second
126 Definition Types_assoc a b : Types_second a >>>> Types_first b <~~~> Types_first b >>>> Types_second a.
130 Definition Types_cancelr : Types_first [] <~~~> functor_id _.
134 Definition Types_cancell : Types_second [] <~~~> functor_id _.
138 Definition Types_assoc_ll a b : Types_second (a,,b) <~~~> Types_second b >>>> Types_second a.
142 Definition Types_assoc_rr a b : Types_first (a,,b) <~~~> Types_first a >>>> Types_first b.
146 Instance Types_PreMonoidal : PreMonoidalCat Types_binoidal [] :=
147 { pmon_assoc := Types_assoc
148 ; pmon_cancell := Types_cancell
149 ; pmon_cancelr := Types_cancelr
150 ; pmon_assoc_rr := Types_assoc_rr
151 ; pmon_assoc_ll := Types_assoc_ll
153 admit. (* pentagon law *)
154 admit. (* triangle law *)
155 admit. (* assoc_rr/assoc coherence *)
156 admit. (* assoc_ll/assoc coherence *)
159 Definition TypesEnrichedInJudgments : Enrichment.
160 refine {| enr_c := TypesL |}.
163 Structure HasProductTypes :=
167 Lemma CartesianEnrMonoidal (e:Enrichment) `(C:CartesianCat(Ob:= _)(Hom:= _)(C:=Underlying (enr_c e))) : MonoidalEnrichment e.
171 (* need to prove that if we have cartesian tuples we have cartesian contexts *)
172 Definition LanguagesWithProductsAreSMME : HasProductTypes -> SurjectiveMonicMonoidalEnrichment TypesEnrichedInJudgments.
176 End LanguageCategory.
178 End Programming_Language.
180 Structure ProgrammingLanguageSMME :=
183 ; plsmme_sequent : Tree ??plsmme_t -> Tree ??plsmme_t -> plsmme_judg
184 ; plsmme_rule : Tree ??plsmme_judg -> Tree ??plsmme_judg -> Type
185 ; plsmme_pl : @ProgrammingLanguage plsmme_t plsmme_judg plsmme_sequent plsmme_rule
186 ; plsmme_smme : SurjectiveMonicMonoidalEnrichment (TypesEnrichedInJudgments _ _ plsmme_pl)
188 Coercion plsmme_pl : ProgrammingLanguageSMME >-> ProgrammingLanguage.
189 Coercion plsmme_smme : ProgrammingLanguageSMME >-> SurjectiveMonicMonoidalEnrichment.
191 Implicit Arguments ND [ Judgment ].