- Context (flat_dynamic_semantics : @ND_Relation _ Rule).
- Context (ml_dynamic_semantics : @ND_Relation _ Rule).
-
- Section SystemFC_Category.
- Context (encodeTypeTree_reduce : @LeveledHaskType V -> @LeveledHaskType V -> @LeveledHaskType V).
- Context (encodeTypeTree_empty : @LeveledHaskType V).
- Context (encodeTypeTree_flat_empty : @CoreType V).
- Context (encodeTypeTree_flat_reduce : @CoreType V -> @CoreType V -> @CoreType V).
-
- Definition encodeTypeTree :=
- @treeReduce _ _ (fun x => match x with None => encodeTypeTree_empty | Some q => q end) encodeTypeTree_reduce.
- Definition encodeTypeTree_flat :=
- @treeReduce _ _ (fun x => match x with None => encodeTypeTree_flat_empty | Some q => q end) encodeTypeTree_flat_reduce.
- (* the full category of judgments *)
- Definition ob2judgment past :=
- fun q:Tree ??(@LeveledHaskType V) * Tree ??(@LeveledHaskType V) =>
- let (a,s):=q in (Γ > past : a |- (encodeTypeTree s) ).
- Definition SystemFC_Cat past :=
- @Judgments_Category_monoidal _ Rule
- (@ml_dynamic_semantics V)
- (Tree ??(@LeveledHaskType V) * Tree ??(@LeveledHaskType V))
- (ob2judgment past).
-
- (* the category of judgments with no variables or succedents in the "future" –- still may have code types *)
- (* technically this should be a subcategory of SystemFC_Cat *)
- Definition ob2judgment_flat past :=
- fun q:Tree ??(@CoreType V) * Tree ??(@CoreType V) =>
- let (a,s):=q in (Γ > past : ``a |- `(encodeTypeTree_flat s) ).
- Definition SystemFC_Cat_Flat past :=
- @Judgments_Category_monoidal _ Rule
- (@flat_dynamic_semantics V)
- (Tree ??(@CoreType V) * Tree ??(@CoreType V))
- (ob2judgment_flat past).
-
- Section EscBrak_Functor.
- Context
- (past:@Past V)
- (n:V)
- (Σ₁:Tree ??(@LeveledHaskType V)).
-
- Definition EscBrak_Functor_Fobj
- : SystemFC_Cat_Flat ((Σ₁,n)::past) -> SystemFC_Cat past
- := mapOptionTree (fun q:Tree ??(@CoreType V) * Tree ??(@CoreType V) =>
- let (a,s):=q in (Σ₁,,(``a)^^^n,[`<[ n |- encodeTypeTree_flat s ]>])).
-
- Definition append_brak
- : forall {c}, ND_ML
- (mapOptionTree (ob2judgment_flat ((⟨Σ₁,n⟩) :: past)) c )
- (mapOptionTree (ob2judgment past ) (EscBrak_Functor_Fobj c)).
- intros.
- unfold ND_ML.
- unfold EscBrak_Functor_Fobj.
- rewrite mapOptionTree_comp.
- simpl in *.
- apply nd_replicate.
- intro o; destruct o.
- apply nd_rule.
- apply MLRBrak.
- Defined.
+ Context (ndr_systemfc:@ND_Relation _ Rule).
+
+ Inductive PCFJudg Γ (Δ:CoercionEnv Γ) (ec:HaskTyVar Γ ★) :=
+ pcfjudg : Tree ??(HaskType Γ ★) -> Tree ??(HaskType Γ ★) -> PCFJudg Γ Δ ec.
+ Implicit Arguments pcfjudg [ [Γ] [Δ] [ec] ].
+
+ (* given an PCFJudg at depth (ec::depth) we can turn it into an PCFJudg
+ * from depth (depth) by wrapping brackets around everything in the
+ * succedent and repopulating *)
+ Definition brakify {Γ}{Δ}{ec} (j:PCFJudg Γ Δ ec) : Judg :=
+ match j with
+ pcfjudg Σ τ => Γ > Δ > (Σ@@@(ec::nil)) |- (mapOptionTree (fun t => HaskBrak ec t) τ @@@ nil)
+ end.
+
+ Definition pcf_vars {Γ}(ec:HaskTyVar Γ ★)(t:Tree ??(LeveledHaskType Γ ★)) : Tree ??(HaskType Γ ★)
+ := mapOptionTreeAndFlatten (fun lt =>
+ match lt with t @@ l => match l with
+ | ec'::nil => if eqd_dec ec ec' then [t] else []
+ | _ => []
+ end
+ end) t.
+
+ Inductive MatchingJudgments {Γ}{Δ}{ec} : Tree ??(PCFJudg Γ Δ ec) -> Tree ??Judg -> Type :=
+ | match_nil : MatchingJudgments [] []
+ | match_branch : forall a b c d, MatchingJudgments a b -> MatchingJudgments c d -> MatchingJudgments (a,,c) (b,,d)
+ | match_leaf :
+ forall Σ τ lev,
+ MatchingJudgments
+ [pcfjudg (pcf_vars ec Σ) τ ]
+ [Γ > Δ > Σ |- (mapOptionTree (HaskBrak ec) τ @@@ lev)].
+
+ Definition fc_vars {Γ}(ec:HaskTyVar Γ ★)(t:Tree ??(LeveledHaskType Γ ★)) : Tree ??(HaskType Γ ★)
+ := mapOptionTreeAndFlatten (fun lt =>
+ match lt with t @@ l => match l with
+ | ec'::nil => if eqd_dec ec ec' then [] else [t]
+ | _ => []
+ end
+ end) t.
+
+ Definition pcfjudg2judg {Γ}{Δ:CoercionEnv Γ} ec (cj:PCFJudg Γ Δ ec) :=
+ match cj with pcfjudg Σ τ => Γ > Δ > (Σ @@@ (ec::nil)) |- (τ @@@ (ec::nil)) end.
+
+ (* Rules allowed in PCF; i.e. rules we know how to turn into GArrows *)
+ (* Rule_PCF consists of the rules allowed in flat PCF: everything except *)
+ (* AppT, AbsT, AppC, AbsC, Cast, Global, and some Case statements *)
+ Inductive Rule_PCF {Γ}{Δ:CoercionEnv Γ} (ec:HaskTyVar Γ ★)
+ : forall (h c:Tree ??(PCFJudg Γ Δ ec)), Rule (mapOptionTree (pcfjudg2judg ec) h) (mapOptionTree (pcfjudg2judg ec) c) -> Type :=
+ | PCF_RArrange : ∀ x y t a, Rule_PCF ec [pcfjudg _ _ ] [ pcfjudg _ _ ] (RArrange Γ Δ (x@@@(ec::nil)) (y@@@(ec::nil)) (t@@@(ec::nil)) a)
+ | PCF_RLit : ∀ lit , Rule_PCF ec [ ] [ pcfjudg [] [_] ] (RLit Γ Δ lit (ec::nil))
+ | PCF_RNote : ∀ Σ τ n , Rule_PCF ec [pcfjudg _ [_]] [ pcfjudg _ [_] ] (RNote Γ Δ (Σ@@@(ec::nil)) τ (ec::nil) n)
+ | PCF_RVar : ∀ σ , Rule_PCF ec [ ] [ pcfjudg [_] [_] ] (RVar Γ Δ σ (ec::nil) )
+ | PCF_RLam : ∀ Σ tx te , Rule_PCF ec [pcfjudg (_,,[_]) [_] ] [ pcfjudg _ [_] ] (RLam Γ Δ (Σ@@@(ec::nil)) tx te (ec::nil) )
+
+ | PCF_RApp : ∀ Σ Σ' tx te ,
+ Rule_PCF ec ([pcfjudg _ [_]],,[pcfjudg _ [_]]) [pcfjudg (_,,_) [_]]
+ (RApp Γ Δ (Σ@@@(ec::nil))(Σ'@@@(ec::nil)) tx te (ec::nil))
+
+ | PCF_RLet : ∀ Σ Σ' σ₂ p,
+ Rule_PCF ec ([pcfjudg _ [_]],,[pcfjudg (_,,[_]) [_]]) [pcfjudg (_,,_) [_]]
+ (RLet Γ Δ (Σ@@@(ec::nil)) (Σ'@@@(ec::nil)) σ₂ p (ec::nil))
+
+ | PCF_REmptyGroup : Rule_PCF ec [ ] [ pcfjudg [] [] ] (REmptyGroup Γ Δ )
+(*| PCF_RLetRec : ∀ Σ₁ τ₁ τ₂ , Rule_PCF (ec::nil) _ _ (RLetRec Γ Δ Σ₁ τ₁ τ₂ (ec::nil) )*)
+ | PCF_RBindingGroup : ∀ Σ₁ Σ₂ τ₁ τ₂, Rule_PCF ec ([pcfjudg _ _],,[pcfjudg _ _]) [pcfjudg (_,,_) (_,,_)]
+ (RBindingGroup Γ Δ (Σ₁@@@(ec::nil)) (Σ₂@@@(ec::nil)) (τ₁@@@(ec::nil)) (τ₂@@@(ec::nil))).
+ (* need int/boolean case *)
+ Implicit Arguments Rule_PCF [ ].
+
+ Definition PCFRule Γ Δ lev h c := { r:_ & @Rule_PCF Γ Δ lev h c r }.
+
+ (* An organized deduction has been reorganized into contiguous blocks whose
+ * hypotheses (if any) and conclusion have the same Γ and Δ and a fixed nesting depth. The boolean
+ * indicates if non-PCF rules have been used *)
+ Inductive OrgR : Tree ??Judg -> Tree ??Judg -> Type :=
+
+ | org_fc : forall h c (r:Rule h c),
+ Rule_Flat r ->
+ OrgR h c
+
+ | org_pcf : forall Γ Δ ec h h' c c',
+ MatchingJudgments h h' ->
+ MatchingJudgments c c' ->
+ ND (PCFRule Γ Δ ec) h c ->
+ OrgR h' c'.
+
+ Definition mkEsc {Γ}{Δ}{ec}(h:Tree ??(PCFJudg Γ Δ ec))
+ : ND Rule
+ (mapOptionTree brakify h)
+ (mapOptionTree (pcfjudg2judg ec) h).
+ apply nd_replicate; intros.
+ destruct o; simpl in *.
+ induction t0.
+ destruct a; simpl.
+ apply nd_rule.
+ apply REsc.
+ apply nd_id.
+ apply (Prelude_error "mkEsc got multi-leaf succedent").
+ Defined.
+
+ Definition mkBrak {Γ}{Δ}{ec}(h:Tree ??(PCFJudg Γ Δ ec))
+ : ND Rule
+ (mapOptionTree (pcfjudg2judg ec) h)
+ (mapOptionTree brakify h).
+ apply nd_replicate; intros.
+ destruct o; simpl in *.
+ induction t0.
+ destruct a; simpl.
+ apply nd_rule.
+ apply RBrak.
+ apply nd_id.
+ apply (Prelude_error "mkBrak got multi-leaf succedent").
+ Defined.
+
+ (*
+ Definition Partition {Γ} ec (Σ:Tree ??(LeveledHaskType Γ ★)) :=
+ { vars:(_ * _) |
+ fc_vars ec Σ = fst vars /\
+ pcf_vars ec Σ = snd vars }.
+ *)
+
+ Definition pcfToND : forall Γ Δ ec h c,
+ ND (PCFRule Γ Δ ec) h c -> ND Rule (mapOptionTree (pcfjudg2judg ec) h) (mapOptionTree (pcfjudg2judg ec) c).
+ intros.
+ eapply (fun q => nd_map' _ q X).
+ intros.
+ destruct X0.
+ apply nd_rule.
+ apply x.
+ Defined.