Skip to content

Commit 3bbe5bc

Browse files
authored
Remove premise from let (#10)
After asking questions on the GHC mailing list, this was one of Richard's comments. See https://mail.haskell.org/pipermail/ghc-devs/2020-November/019372.html
1 parent 4e308bc commit 3bbe5bc

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

Soundness.thy

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ next
7979
then have 1: "BVar x \<tau>1 # \<Gamma>' \<turnstile> e2 : \<tau>2" by auto
8080
from T_LetI have 2: "atom x \<sharp> (\<Gamma>', e1)" by auto
8181
from T_LetI have 3: "\<Gamma>' \<turnstile> e1 : \<tau>1" by force
82-
have 4: "\<Gamma>' \<turnstile>\<^sub>t\<^sub>y \<tau>1 : \<star>" using context_invariance_ty[OF T_LetI(4)] T_LetI(10) fv_supp_subset by (simp add: subset_eq)
83-
show ?case by (rule T.T_LetI[OF 2 4 1 3])
82+
show ?case by (rule T.T_LetI[OF 2 1 3])
8483
next
8584
case (T_AppTI \<Gamma> e a k \<sigma> \<tau>)
8685
then have 1: "\<Gamma>' \<turnstile> e : \<forall> a : k . \<sigma>" by simp
@@ -138,14 +137,13 @@ next
138137
next
139138
case (Let y \<tau>1 e1 e2)
140139
then have 1: "atom y \<sharp> BVar x \<tau>' # \<Gamma>" by (simp add: fresh_Cons)
141-
have P: "BVar x \<tau>' # \<Gamma> \<turnstile> e1 : \<tau>1" "BVar y \<tau>1 # BVar x \<tau>' # \<Gamma> \<turnstile> e2 : \<tau>" "BVar x \<tau>' # \<Gamma> \<turnstile>\<^sub>t\<^sub>y \<tau>1 : \<star>" using T_Let_Inv[OF Let(8) 1] by auto
140+
have P: "BVar x \<tau>' # \<Gamma> \<turnstile> e1 : \<tau>1" "BVar y \<tau>1 # BVar x \<tau>' # \<Gamma> \<turnstile> e2 : \<tau>" using T_Let_Inv[OF Let(8) 1] by auto
142141
have 2: "\<Gamma> \<turnstile> subst_term v x e1 : \<tau>1" by (rule Let(6)[OF P(1) Let(9)])
143142
have 3: "BVar x \<tau>' # BVar y \<tau>1 # \<Gamma> \<turnstile> e2 : \<tau>" using Let(4) P(2) context_invariance by auto
144143
have 4: "BVar y \<tau>1 # \<Gamma> \<turnstile> subst_term v x e2 : \<tau>" by (rule Let(7)[OF 3 Let(9)])
145-
have 5: "\<Gamma> \<turnstile>\<^sub>t\<^sub>y \<tau>1 : \<star>" using context_invariance_ty[OF P(3)] by auto
146144
have "atom y \<sharp> subst_term v x e1" using "2" Let(1) fresh_term_var by blast
147145
then have 6: "atom y \<sharp> (\<Gamma>, subst_term v x e1)" using Let(1) by auto
148-
show ?case using T.T_LetI[OF 6 5 4 2] Let by auto
146+
show ?case using T.T_LetI[OF 6 4 2] Let by auto
149147
qed
150148

151149
lemma type_substitution_ty: "\<lbrakk> BTyVar a k # \<Gamma> \<turnstile>\<^sub>t\<^sub>y \<tau> : k2 ; \<Gamma> \<turnstile>\<^sub>t\<^sub>y \<tau>' : k ; atom a \<sharp> \<Gamma> \<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile>\<^sub>t\<^sub>y subst_type \<tau>' a \<tau> : k2"
@@ -269,17 +267,17 @@ next
269267
next
270268
case (Let x \<tau>1 e1 e2)
271269
then have 1: "atom x \<sharp> BTyVar a k # \<Gamma>" by (simp add: fresh_Cons)
272-
have P: "BTyVar a k # \<Gamma> \<turnstile> e1 : \<tau>1" "BVar x \<tau>1 # BTyVar a k # \<Gamma> \<turnstile> e2 : \<sigma>" "BTyVar a k # \<Gamma> \<turnstile>\<^sub>t\<^sub>y \<tau>1 : \<star>" using T_Let_Inv[OF Let(9) 1] by auto
270+
have P: "BTyVar a k # \<Gamma> \<turnstile> e1 : \<tau>1" "BVar x \<tau>1 # BTyVar a k # \<Gamma> \<turnstile> e2 : \<sigma>" using T_Let_Inv[OF Let(9) 1] by auto
273271
have 2: "atom x \<sharp> e1" using "1" P(1) fresh_term_var by blast
274272
have "atom x \<sharp> subst_term_type \<tau>' a e1" using Let P(1) fresh_term_var by blast
275273
then have 3: "atom x \<sharp> (\<Gamma>', subst_term_type \<tau>' a e1)" using Let(4) by simp
276-
have 4: "\<Gamma>' \<turnstile>\<^sub>t\<^sub>y subst_type \<tau>' a \<tau>1 : \<star>" by (smt Let.prems(2) Let.prems(3) Let.prems(5) P(3) context_invariance_ty isin.simps(5) type_substitution_ty)
277-
have 5: "atom a \<sharp> BVar x (subst_type \<tau>' a \<tau>1) # \<Gamma>'" using "4" Let.prems(5) fresh_Cons ty_fresh_vars by fastforce
274+
have 5: "atom a \<sharp> BVar x (subst_type \<tau>' a \<tau>1) # \<Gamma>'"
275+
by (metis Let.hyps(1) Let.prems(2) Let.prems(3) Let.prems(5) binder.fresh(1) context_invariance_ty fresh_Cons fresh_at_base(2) fresh_subst_type ty_fresh_vars)
278276
have 6: "BTyVar a k # BVar x \<tau>1 # \<Gamma> \<turnstile> e2 : \<sigma>" using context_invariance[OF P(2)] by auto
279277
have 7: "BVar x \<tau>1 # \<Gamma> \<turnstile>\<^sub>t\<^sub>y \<tau>' : k" using Let.prems(2) context_invariance_ty isin.simps(4) by blast
280278

281279
have 9: "BVar x (subst_type \<tau>' a \<tau>1) # \<Gamma>' \<turnstile> subst_term_type \<tau>' a e2 : subst_type \<tau>' a \<sigma>" using Let(8)[OF 6 7 _ _ 5] Let(11) Let(12) by simp
282-
show ?case using T.T_LetI[OF 3 4 9] using Let P(1) by auto
280+
show ?case using T.T_LetI[OF 3 9] using Let P(1) by auto
283281
qed
284282

285283
theorem preservation: "\<lbrakk> [] \<turnstile> e : \<tau> ; e \<longrightarrow> e' \<rbrakk> \<Longrightarrow> [] \<turnstile> e' : \<tau>"
@@ -316,13 +314,13 @@ next
316314
then show ?thesis
317315
proof (cases "atom x = atom y")
318316
case True
319-
then show ?thesis
320-
by (metis T_LetI.hyps(4) T_LetI.hyps(5) local.ST_SubstI(1) local.ST_SubstI(2) subst_term_same substitution)
317+
then show ?thesis by (metis Abs1_eq(3) T_LetI.hyps(3) T_LetI.hyps(4) atom_eq_iff local.ST_SubstI(1) local.ST_SubstI(2) substitution)
321318
next
322319
case False
323320
then have 1: "atom y \<sharp> [(x, \<tau>1)]" by (simp add: fresh_Cons fresh_Nil)
324321
have "(x \<leftrightarrow> y) \<bullet> e2 = e" by (metis Abs1_eq_iff'(3) False flip_commute local.ST_SubstI(1))
325-
then have "[BVar y \<tau>1] \<turnstile> e : \<tau>2" using T.eqvt by (metis T_AbsI T_Abs_Inv T_LetI.hyps(3) T_LetI.hyps(4) \<tau>.eq_iff(3) fresh_Nil local.ST_SubstI(1) term.eq_iff(5))
322+
then have "[BVar y \<tau>1] \<turnstile> e : \<tau>2" using T.eqvt
323+
by (metis Cons_eqvt Nil_eqvt T_LetI.hyps(3) binder.perm_simps(1) flip_at_simps(1) flip_fresh_fresh no_vars_in_ty)
326324
then show ?thesis using T_LetI ST_SubstI substitution by auto
327325
qed
328326
qed

Typing.thy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ inductive T :: "\<Gamma> \<Rightarrow> term \<Rightarrow> \<tau> \<Rightarrow> b
2626

2727
| T_AppI: "\<lbrakk> \<Gamma> \<turnstile> e1 : (\<tau>1 \<rightarrow> \<tau>2) ; \<Gamma> \<turnstile> e2 : \<tau>1 \<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> App e1 e2 : \<tau>2"
2828

29-
| T_LetI: "\<lbrakk> atom x \<sharp> (\<Gamma>, e1) ; \<Gamma> \<turnstile>\<^sub>t\<^sub>y \<tau>1 : \<star> ; BVar x \<tau>1 # \<Gamma> \<turnstile> e2 : \<tau>2 ; \<Gamma> \<turnstile> e1 : \<tau>1 \<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> Let x \<tau>1 e1 e2 : \<tau>2"
29+
| T_LetI: "\<lbrakk> atom x \<sharp> (\<Gamma>, e1) ; BVar x \<tau>1 # \<Gamma> \<turnstile> e2 : \<tau>2 ; \<Gamma> \<turnstile> e1 : \<tau>1 \<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> Let x \<tau>1 e1 e2 : \<tau>2"
3030

3131
| T_AppTI: "\<lbrakk> \<Gamma> \<turnstile> e : (\<forall>a : k . \<sigma>) ; \<Gamma> \<turnstile>\<^sub>t\<^sub>y \<tau> : k \<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> TyApp e \<tau> : subst_type \<tau> a \<sigma>"
3232

Typing_Lemmas.thy

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ qed simp_all
3737

3838
lemma T_Let_Inv:
3939
assumes a: "\<Gamma> \<turnstile> Let x \<tau>1 e1 e2 : \<tau>" and b: "atom x \<sharp> \<Gamma>"
40-
shows "\<Gamma> \<turnstile> e1 : \<tau>1 \<and> BVar x \<tau>1 # \<Gamma> \<turnstile> e2 : \<tau> \<and> \<Gamma> \<turnstile>\<^sub>t\<^sub>y \<tau>1 : \<star>"
40+
shows "\<Gamma> \<turnstile> e1 : \<tau>1 \<and> BVar x \<tau>1 # \<Gamma> \<turnstile> e2 : \<tau>"
4141
proof (cases rule: T.cases[OF a])
4242
case (5 x' \<Gamma>' _ \<tau>1 e2' \<tau>2)
4343
have swap: "(x' \<leftrightarrow> x) \<bullet> e2' = e2"
@@ -49,10 +49,9 @@ proof (cases rule: T.cases[OF a])
4949
next
5050
case False
5151
then have 1: "atom x \<sharp> BVar x' \<tau>1 # \<Gamma>'" using b by (simp add: 5 fresh_Cons)
52-
have 2: "((x' \<leftrightarrow> x) \<bullet> (BVar x' \<tau>1#\<Gamma>)) \<turnstile> (x' \<leftrightarrow> x) \<bullet> e2' : \<tau>" using T.eqvt by (metis "5"(1) "5"(3) "5"(6) flip_fresh_fresh no_vars_in_ty)
52+
have 2: "((x' \<leftrightarrow> x) \<bullet> (BVar x' \<tau>1#\<Gamma>)) \<turnstile> (x' \<leftrightarrow> x) \<bullet> e2' : \<tau>" using 5(1) 5(3) T.eqvt[OF 5(5)] no_vars_in_ty flip_fresh_fresh by metis
5353
have 3: "((x' \<leftrightarrow> x) \<bullet> (BVar x' \<tau>1 # \<Gamma>)) = BVar x \<tau>1#\<Gamma>"
5454
by (metis "5"(1) "5"(4) Cons_eqvt b binder.perm_simps(1) flip_at_simps(1) flip_fresh_fresh fresh_PairD(1) no_vars_in_ty)
55-
5655
from 2 3 5 swap show ?thesis by auto
5756
qed
5857
qed simp_all

0 commit comments

Comments
 (0)