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