+ (* 5.1.3 *)
+ Instance PCF n Γ Δ : @ProgrammingLanguage _ _ (@mkUJudg Γ Δ) (OrgR false n Γ Δ) :=
+ { pl_eqv := OrgNDR false n Γ Δ
+ ; pl_tsr := _ (*@TreeStructuralRules Judg Rule T sequent*)
+ ; pl_sc := _
+ ; pl_subst := _
+ ; pl_sequent_join := _
+ }.
+ apply Build_TreeStructuralRules; intros; unfold eqv; unfold hom; simpl.
+ apply nd_rule; apply org_pcf; simpl; exists (RCossa _ a b c); apply (PCF_RURule [_>>_>_|-_] [_>>_>_|-_]).
+ apply nd_rule; apply org_pcf; simpl; exists (RAssoc _ a b c); apply (PCF_RURule [_>>_>_|-_] [_>>_>_|-_]).
+ apply nd_rule; apply org_pcf; simpl; exists (RCanL _ a ); apply (PCF_RURule [_>>_>_|-_] [_>>_>_|-_]).
+ apply nd_rule; apply org_pcf; simpl; exists (RCanR _ a ); apply (PCF_RURule [_>>_>_|-_] [_>>_>_|-_]).
+ apply nd_rule; apply org_pcf; simpl; exists (RuCanL _ a ); apply (PCF_RURule [_>>_>_|-_] [_>>_>_|-_]).
+ apply nd_rule; apply org_pcf; simpl; exists (RuCanR _ a ); apply (PCF_RURule [_>>_>_|-_] [_>>_>_|-_]).
+ Admitted.
+
+ (* gathers a tree of guest-language types into a single host-language types via the tensor *)
+ Definition tensorizeType {Γ} (lt:Tree ??(LeveledHaskType Γ ★)) : HaskType Γ ★.
+ admit.
+ Defined.
+
+ Definition mkGA {Γ} : HaskType Γ ★ -> HaskType Γ ★ -> HaskType Γ ★.
+ admit.
+ Defined.
+
+ Definition guestJudgmentAsGArrowType {Γ}{Δ} (lt:UJudg Γ Δ) : LeveledHaskType Γ ★ :=
+ match lt with
+ mkUJudg x y =>
+ (mkGA (tensorizeType x) (tensorizeType y)) @@ nil
+ end.
+
+ Fixpoint obact n {Γ}{Δ}(X:Tree ??(UJudg Γ Δ)) : Tree ??(LeveledHaskType Γ ★) :=
+ match n with
+ | 0 => mapOptionTree guestJudgmentAsGArrowType X
+ | S n' => let t := obact n' X
+ in [guestJudgmentAsGArrowType (Γ >> Δ > [] |- t )]
+ end.
+
+(* Definition *)
+
+
+ Definition magic {Γ}{Δ} h c n x :
+Rule_PCF Γ Δ (mapOptionTree (@UJudg2judg Γ Δ) h) (mapOptionTree (@UJudg2judg Γ Δ) c) x
+-> ND (OrgR true n Γ Δ) []
+ [Γ >> Δ > mapOptionTree guestJudgmentAsGArrowType h
+ |- mapOptionTree guestJudgmentAsGArrowType c].
+ admit.
+ Defined.
+
+ (*
+ * Here it is, what you've all been waiting for! When reading this,
+ * it might help to have the definition for "Inductive ND" (see
+ * NaturalDeduction.v) handy as a cross-reference.
+ *)
+ Definition FlatteningFunctor_fmor {Γ}{Δ}
+ : forall h c,
+ (h~~{JudgmentsL _ _ (PCF 0 Γ Δ)}~~>c) ->
+ ((obact 0 h)~~{TypesL _ _ (SystemFC Γ Δ)}~~>(obact 0 c)).
+ unfold hom; unfold ob; unfold ehom; simpl; unfold mon_i; unfold obact; intros.
+
+ induction X; simpl.
+
+ (* the proof from no hypotheses of no conclusions (nd_id0) becomes REmptyGroup *)
+ apply nd_rule; apply org_fc; simpl. apply nd_rule. apply REmptyGroup.
+
+ (* the proof from hypothesis X of conclusion X (nd_id1) becomes RVar *)
+ apply nd_rule; apply org_fc; simpl. apply nd_rule. destruct (guestJudgmentAsGArrowType h). apply RVar.
+
+ (* the proof from hypothesis X of no conclusions (nd_weak) becomes RWeak;;REmptyGroup *)
+ apply nd_rule; apply org_fc; simpl.
+ eapply nd_comp; [ idtac | apply (nd_rule (RURule _ _ _ _ (RWeak _ _))) ].
+ apply nd_rule. apply REmptyGroup.
+
+ (* the proof from hypothesis X of two identical conclusions X,,X (nd_copy) becomes RVar;;RBindingGroup;;RCont *)
+ eapply nd_comp; [ idtac | eapply nd_rule; eapply org_fc; apply (nd_rule (RURule _ _ _ _ (RCont _ _))) ].
+ eapply nd_comp; [ apply nd_llecnac | idtac ].
+ set (nd_seq_reflexive(SequentCalculus:=@pl_sc _ _ _ _ (SystemFC Γ Δ)) (mapOptionTree guestJudgmentAsGArrowType h)) as q.
+ eapply nd_comp.
+ eapply nd_prod.
+ apply q.
+ apply q.
+ apply nd_rule; eapply org_fc.
+ simpl.
+ apply nd_rule.
+ apply RBindingGroup.
+
+ (* nd_prod becomes nd_llecnac;;nd_prod;;RBindingGroup *)
+ eapply nd_comp.
+ apply (nd_llecnac ;; nd_prod IHX1 IHX2).
+ apply nd_rule; apply org_fc; simpl.
+ eapply nd_rule. apply RBindingGroup.
+
+ (* nd_comp becomes pl_subst (aka nd_cut) *)
+ eapply nd_comp.
+ apply (nd_llecnac ;; nd_prod IHX1 IHX2).
+ clear IHX1 IHX2 X1 X2.
+ apply (@nd_cut _ _ _ _ _ _ (@pl_subst _ _ _ _ (SystemFC Γ Δ))).
+
+ (* nd_cancell becomes RVar;;RuCanL *)
+ eapply nd_comp;
+ [ idtac | eapply nd_rule; apply org_fc; simpl; apply nd_rule; apply (RURule _ _ _ _ (RuCanL _ _)) ].
+ apply (nd_seq_reflexive(SequentCalculus:=@pl_sc _ _ _ _ (SystemFC Γ Δ))).
+
+ (* nd_cancelr becomes RVar;;RuCanR *)
+ eapply nd_comp;
+ [ idtac | eapply nd_rule; apply org_fc; simpl; apply nd_rule; apply (RURule _ _ _ _ (RuCanR _ _)) ].
+ apply (nd_seq_reflexive(SequentCalculus:=@pl_sc _ _ _ _ (SystemFC Γ Δ))).
+
+ (* nd_llecnac becomes RVar;;RCanL *)
+ eapply nd_comp;
+ [ idtac | eapply nd_rule; apply org_fc; simpl; apply nd_rule; apply (RURule _ _ _ _ (RCanL _ _)) ].
+ apply (nd_seq_reflexive(SequentCalculus:=@pl_sc _ _ _ _ (SystemFC Γ Δ))).
+
+ (* nd_rlecnac becomes RVar;;RCanR *)
+ eapply nd_comp;
+ [ idtac | eapply nd_rule; apply org_fc; simpl; apply nd_rule; apply (RURule _ _ _ _ (RCanR _ _)) ].
+ apply (nd_seq_reflexive(SequentCalculus:=@pl_sc _ _ _ _ (SystemFC Γ Δ))).
+
+ (* nd_assoc becomes RVar;;RAssoc *)
+ eapply nd_comp;
+ [ idtac | eapply nd_rule; apply org_fc; simpl; apply nd_rule; apply (RURule _ _ _ _ (RAssoc _ _ _ _)) ].
+ apply (nd_seq_reflexive(SequentCalculus:=@pl_sc _ _ _ _ (SystemFC Γ Δ))).
+
+ (* nd_coss becomes RVar;;RCossa *)
+ eapply nd_comp;
+ [ idtac | eapply nd_rule; apply org_fc; simpl; apply nd_rule; apply (RURule _ _ _ _ (RCossa _ _ _ _)) ].
+ apply (nd_seq_reflexive(SequentCalculus:=@pl_sc _ _ _ _ (SystemFC Γ Δ))).
+
+ (* now, the interesting stuff: the inference rules of Judgments(PCF) become GArrow-parameterized terms *)
+ refine (match r as R in OrgR B N G D H C return
+ match N with
+ | S _ => True
+ | O => if B then True
+ else ND (OrgR true 0 G D)
+ []
+ [G >> D > mapOptionTree guestJudgmentAsGArrowType H |- mapOptionTree guestJudgmentAsGArrowType C]
+ end with
+ | org_pcf n Γ Δ h c b r => _
+ | org_fc n Γ Δ h c r => _
+ | org_nest n Γ Δ h c b v q => _
+ end); destruct n; try destruct b; try apply I.
+ destruct r0.
+
+ clear r h c Γ Δ.
+ rename r0 into r; rename h0 into h; rename c0 into c; rename Γ0 into Γ; rename Δ0 into Δ.
+
+ refine (match r as R in Rule_PCF G D H C with
+ | PCF_RURule h c r => let case_RURule := tt in _
+ | PCF_RLit Σ τ => let case_RLit := tt in _
+ | PCF_RNote Σ τ l n => let case_RNote := tt in _
+ | PCF_RVar σ l=> let case_RVar := tt in _
+ | PCF_RLam Σ tx te q => let case_RLam := tt in _
+ | PCF_RApp Σ tx te p l=> let case_RApp := tt in _
+ | PCF_RLet Σ σ₁ σ₂ p l=> let case_RLet := tt in _
+ | PCF_RBindingGroup q a b c d e => let case_RBindingGroup := tt in _
+ | PCF_RCase T κlen κ θ l x => let case_RCase := tt in _
+ | PCF_REmptyGroup q a => let case_REmptyGroup := tt in _
+ | PCF_RLetRec Σ₁ τ₁ τ₂ lev => let case_RLetRec := tt in _
+ end).
+ rename Γ
+
+ apply (magic _ _ _ _ r0).
+ Defined.
+
+ Instance FlatteningFunctor {n}{Γ}{Δ} : Functor (JudgmentsL _ _ (PCF n Γ Δ)) (TypesL _ _ (SystemFCa n Γ Δ)) obact :=
+ { fmor := FlatteningFunctor_fmor }.
+ unfold hom; unfold ob; unfold ehom; intros; simpl.
+
+
+ Definition productifyType {Γ} (lt:Tree ??(LeveledHaskType Γ ★)) : LeveledHaskType Γ ★.
+ admit.
+ Defined.
+
+ Definition exponent {Γ} : LeveledHaskType Γ ★ -> LeveledHaskType Γ ★ -> LeveledHaskType Γ ★.
+ admit.
+ Defined.
+
+ Definition brakify {Γ}(Σ τ:Tree ??(LeveledHaskType Γ ★)) := exponent (productifyType Σ) (productifyType τ).
+
+ Definition brakifyJudg (j:Judg) : Judg :=
+ match j with
+ Γ > Δ > Σ |- τ =>
+ Γ > Δ > [] |- [brakify Σ τ]
+ end.
+
+ Definition brakifyUJudg (j:Judg) : Judg :=
+ match j with
+ Γ > Δ > Σ |- τ =>
+ Γ > Δ > [] |- [brakify Σ τ]
+ end.
+ *)