update submodule pointer, account for changes upstream
[coq-hetmet.git] / src / ProgrammingLanguage.v
1 (*********************************************************************************************************************************)
2 (* ProgrammingLanguage                                                                                                           *)
3 (*                                                                                                                               *)
4 (*   Basic assumptions about programming languages.                                                                              *)
5 (*                                                                                                                               *)
6 (*********************************************************************************************************************************)
7
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.
28
29 Require Import NaturalDeduction.
30 Require Import NaturalDeductionCategory.
31
32 Section Programming_Language.
33
34   Context {T    : Type}.               (* types of the language *)
35
36   Context (Judg : Type).
37   Context (sequent : Tree ??T -> Tree ??T -> Judg).
38      Notation "cs |= ss" := (sequent cs ss) : pl_scope.
39
40   Context {Rule : Tree ??Judg -> Tree ??Judg -> Type}.
41
42   Notation "H /⋯⋯/ C" := (ND Rule H C) : pl_scope.
43
44   Open Scope pf_scope.
45   Open Scope nd_scope.
46   Open Scope pl_scope.
47
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
54   }.
55   Notation "pf1 === pf2" := (@ndr_eqv _ _ pl_eqv _ _ pf1 pf2) : temporary_scope3.
56
57   Section LanguageCategory.
58
59     Context (PL:ProgrammingLanguage).
60
61     (* category of judgments in a fixed type/coercion context *)
62     Definition Judgments_cartesian := @Judgments_Category_CartesianCat _ Rule pl_eqv.
63
64     Definition JudgmentsL          := Judgments_cartesian.
65
66     Definition identityProof t : [] ~~{JudgmentsL}~~> [t |= t].
67       unfold hom; simpl.
68       apply nd_seq_reflexive.
69       Defined.
70
71     Definition cutProof a b c : [a |= b],,[b |= c] ~~{JudgmentsL}~~> [a |= c].
72       unfold hom; simpl.
73       apply pl_subst.
74       Defined.
75
76     Definition TypesL : ECategory JudgmentsL (Tree ??T) (fun x y => [x|=y]).
77       refine
78       {| eid   := identityProof
79        ; ecomp := cutProof
80       |}; intros.
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.
88       symmetry.
89       apply nd_cut_associativity.
90       Defined.
91
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]).
102       apply se_cut_right.
103       Defined.
104
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]).
116       apply se_cut_left.
117       Defined.
118
119     Definition Types_binoidal : BinoidalCat TypesL (@T_Branch _).
120       refine
121         {| bin_first  := Types_first
122          ; bin_second := Types_second
123          |}.
124       Defined.
125
126     Definition Types_assoc a b : Types_second a >>>> Types_first b <~~~> Types_first b >>>> Types_second a.
127       admit.
128       Defined.
129
130     Definition Types_cancelr   : Types_first [] <~~~> functor_id _.
131       admit.
132       Defined.
133
134     Definition Types_cancell   : Types_second [] <~~~> functor_id _.
135       admit.
136       Defined.
137
138     Definition Types_assoc_ll a b : Types_second (a,,b) <~~~> Types_second b >>>> Types_second a.
139       admit.
140       Defined.
141
142     Definition Types_assoc_rr a b : Types_first (a,,b) <~~~> Types_first a >>>> Types_first b.
143       admit.
144       Defined.
145
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
152         }.
153         admit. (* pentagon law *)
154         admit. (* triangle law *)
155         admit. (* assoc_rr/assoc coherence *)
156         admit. (* assoc_ll/assoc coherence *)
157         Defined.
158
159     Definition TypesEnrichedInJudgments : Enrichment.
160       refine {| enr_c := TypesL |}.
161       Defined.
162
163     Structure HasProductTypes :=
164     {
165     }.
166
167     Lemma CartesianEnrMonoidal (e:Enrichment) `(C:CartesianCat(Ob:= _)(Hom:= _)(C:=Underlying (enr_c e))) : MonoidalEnrichment e.
168       admit.
169       Defined.
170
171     (* need to prove that if we have cartesian tuples we have cartesian contexts *)
172     Definition LanguagesWithProductsAreSMME : HasProductTypes -> SurjectiveMonicMonoidalEnrichment TypesEnrichedInJudgments.
173       admit.
174       Defined.
175
176   End LanguageCategory.
177
178 End Programming_Language.
179
180 Structure ProgrammingLanguageSMME :=
181 { plsmme_t       : Type
182 ; plsmme_judg    : Type
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)
187 }.
188 Coercion plsmme_pl   : ProgrammingLanguageSMME >-> ProgrammingLanguage.
189 Coercion plsmme_smme : ProgrammingLanguageSMME >-> SurjectiveMonicMonoidalEnrichment.
190  
191 Implicit Arguments ND [ Judgment ].