Skip to content

Commit 4e308bc

Browse files
authored
Add higher kinded types (#9)
1 parent 0a630fa commit 4e308bc

File tree

7 files changed

+176
-128
lines changed

7 files changed

+176
-128
lines changed

Defs.thy

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ begin
55
nominal_function isin :: "binder \<Rightarrow> \<Gamma> \<Rightarrow> bool" (infixr "\<in>" 80) where
66
"isin _ [] = False"
77
| "isin (BVar x t) (BVar y t'#xs) = (if x = y then t = t' else isin (BVar x t) xs)"
8-
| "isin (BVar x t) (BTyVar a#xs) = isin (BVar x t) xs"
9-
| "isin (BTyVar a) (BVar x t#xs) = isin (BTyVar a) xs"
10-
| "isin (BTyVar a) (BTyVar b#xs) = (if a = b then True else isin (BTyVar a) xs)"
8+
| "isin (BVar x t) (BTyVar _ _#xs) = isin (BVar x t) xs"
9+
| "isin (BTyVar a k) (BVar _ _#xs) = isin (BTyVar a k) xs"
10+
| "isin (BTyVar a k1) (BTyVar b k2#xs) = (if a = b then k1 = k2 else isin (BTyVar a k1) xs)"
1111
proof goal_cases
1212
case (3 P x)
1313
then obtain t ys where P: "x = (t, ys)" by (metis prod.exhaust)
@@ -32,7 +32,7 @@ is_value :: "term => bool"
3232
where
3333
"is_value (Var x) = False"
3434
| "is_value (\<lambda> x : \<tau> . e) = True"
35-
| "is_value (\<Lambda> a . e) = True"
35+
| "is_value (\<Lambda> a : k . e) = True"
3636
| "is_value (App e1 e2) = False"
3737
| "is_value (TyApp e \<tau>) = False"
3838
| "is_value Unit = True"
@@ -45,7 +45,7 @@ nominal_termination (eqvt) by lexicographic_order
4545
nominal_function subst_term :: "term => var => term => term" where
4646
"subst_term e x (Var y) = (if x=y then e else Var y)"
4747
| "atom y \<sharp> (e, x) \<Longrightarrow> subst_term e x (\<lambda> y : \<tau> . e2) = (Lam y \<tau> (subst_term e x e2))"
48-
| "atom y \<sharp> (e, x) \<Longrightarrow> subst_term e x (\<Lambda> y . e2) = (\<Lambda> y . subst_term e x e2)"
48+
| "atom y \<sharp> (e, x) \<Longrightarrow> subst_term e x (\<Lambda> y : k . e2) = (\<Lambda> y : k . subst_term e x e2)"
4949
| "subst_term e x (App e1 e2) = (App (subst_term e x e1) (subst_term e x e2))"
5050
| "subst_term e x (TyApp e1 \<tau>) = (TyApp (subst_term e x e1) \<tau>)"
5151
| "subst_term _ _ Unit = Unit"
@@ -73,25 +73,26 @@ nominal_function subst_type :: "\<tau> \<Rightarrow> tyvar \<Rightarrow> \<tau>
7373
"subst_type _ _ TyUnit = TyUnit"
7474
| "subst_type \<tau> a (TyVar b) = (if a=b then \<tau> else TyVar b)"
7575
| "subst_type \<tau> a (TyArrow \<tau>1 \<tau>2) = TyArrow (subst_type \<tau> a \<tau>1) (subst_type \<tau> a \<tau>2)"
76-
| "atom b \<sharp> (\<tau>, a) \<Longrightarrow> subst_type \<tau> a (TyForall b \<sigma>) = TyForall b (subst_type \<tau> a \<sigma>)"
76+
| "subst_type \<tau> a (TyConApp \<tau>1 \<tau>2) = TyConApp (subst_type \<tau> a \<tau>1) (subst_type \<tau> a \<tau>2)"
77+
| "atom b \<sharp> (\<tau>, a) \<Longrightarrow> subst_type \<tau> a (TyForall b k \<sigma>) = TyForall b k (subst_type \<tau> a \<sigma>)"
7778
proof goal_cases
7879
case (3 P x)
7980
then obtain \<tau> a t where P: "x = (\<tau>, a, t)" by (metis prod.exhaust)
8081
then show ?case
8182
apply (cases t rule: \<tau>.strong_exhaust[of _ _ "(\<tau>, a)"])
8283
apply (auto simp: 3)
83-
using 3(4) P fresh_star_def by blast
84+
using 3(5) P fresh_star_def by blast
8485
next
85-
case (13 b \<tau> a \<sigma> b' \<tau>' a' \<sigma>')
86-
then show ?case using Abs_sumC[OF 13(5) 13(6) 13(1) 13(2)] by fastforce
86+
case (18 b \<tau> a k \<sigma> b' \<tau>' a' k' \<sigma>')
87+
then show ?case using Abs_sumC[OF 18(5) 18(6) 18(1) 18(2)] by fastforce
8788
qed (auto simp: eqvt_def subst_type_graph_aux_def)
8889
nominal_termination (eqvt) by lexicographic_order
8990

9091
nominal_function subst_term_type :: "\<tau> \<Rightarrow> tyvar \<Rightarrow> term \<Rightarrow> term" where
9192
"subst_term_type _ _ (Var x) = Var x"
9293
| "subst_term_type _ _ Unit = Unit"
9394
| "atom y \<sharp> (\<tau>, a) \<Longrightarrow> subst_term_type \<tau> a (\<lambda> y : \<tau>' . e2) = (Lam y (subst_type \<tau> a \<tau>') (subst_term_type \<tau> a e2))"
94-
| "atom b \<sharp> (\<tau>, a) \<Longrightarrow> subst_term_type \<tau> a (\<Lambda> b . e2) = (TyLam b (subst_term_type \<tau> a e2))"
95+
| "atom b \<sharp> (\<tau>, a) \<Longrightarrow> subst_term_type \<tau> a (\<Lambda> b : k . e2) = (TyLam b k (subst_term_type \<tau> a e2))"
9596
| "subst_term_type \<tau> a (App e1 e2) = App (subst_term_type \<tau> a e1) (subst_term_type \<tau> a e2)"
9697
| "subst_term_type \<tau> a (TyApp e \<tau>2) = TyApp (subst_term_type \<tau> a e) (subst_type \<tau> a \<tau>2)"
9798
| "atom y \<sharp> (\<tau>, a) \<Longrightarrow> subst_term_type \<tau> a (Let y \<tau>' e1 e2) = Let y (subst_type \<tau> a \<tau>') (subst_term_type \<tau> a e1) (subst_term_type \<tau> a e2)"

Lemmas.thy

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ proof (nominal_induct e avoiding: c x e' rule: term.strong_induct)
1717
then show ?case by (smt flip_fresh_fresh fresh_Pair fresh_at_base(2) list.set(1) list.set(2) no_vars_in_ty singletonD subst_term.simps(7) term.fresh(7) term.perm_simps(7))
1818
qed (auto simp: flip_fresh_fresh fresh_at_base)
1919
lemma subst_type_var_name: "atom c \<sharp> \<sigma> \<Longrightarrow> subst_type \<tau> a \<sigma> = subst_type \<tau> c ((a \<leftrightarrow> c) \<bullet> \<sigma>)"
20-
by (nominal_induct \<sigma> avoiding: c a \<tau> rule: \<tau>.strong_induct) (auto simp: fresh_at_base)
20+
proof (nominal_induct \<sigma> avoiding: c a \<tau> rule: \<tau>.strong_induct)
21+
case (TyForall b k \<sigma>)
22+
then have 1: "atom c \<sharp> \<sigma>" by (simp add: fresh_at_base)
23+
have "subst_type \<tau> a \<sigma> = subst_type \<tau> c ((a \<leftrightarrow> c) \<bullet> \<sigma>)" by (rule TyForall(4)[OF 1])
24+
then show ?case
25+
by (smt TyForall.hyps(1) TyForall.hyps(2) TyForall.hyps(3) \<tau>.perm_simps(5) flip_fresh_fresh fresh_Pair fresh_at_base(2) no_tyvars_in_kinds subst_type.simps(5))
26+
qed (auto simp: fresh_at_base)
27+
2128
lemma subst_term_type_var_name: "atom c \<sharp> e \<Longrightarrow> subst_term_type \<tau> a e = subst_term_type \<tau> c ((a \<leftrightarrow> c) \<bullet> e)"
2229
proof (nominal_induct e avoiding: c a \<tau> rule: term.strong_induct)
2330
case (Lam x \<tau>1 e)
@@ -38,7 +45,7 @@ lemma subst_term_type_same: "[[atom a]]lst. e = [[atom a']]lst. e' \<Longrightar
3845
by (metis Abs1_eq_iff(3) flip_commute subst_term_type_var_name)
3946

4047
(* atom x \<sharp> \<Gamma> \<Longrightarrow> \<not>isin (B x _) \<Gamma> *)
41-
lemma fresh_not_isin_tyvar: "atom a \<sharp> \<Gamma> \<Longrightarrow> \<not>isin (BTyVar a) \<Gamma>"
48+
lemma fresh_not_isin_tyvar: "atom a \<sharp> \<Gamma> \<Longrightarrow> \<not>isin (BTyVar a k) \<Gamma>"
4249
apply (induction \<Gamma>) apply simp
4350
by (metis binder.fresh(2) binder.strong_exhaust fresh_Cons fresh_at_base(2) isin.simps(4) isin.simps(5))
4451
lemma fresh_not_isin_var: "atom x \<sharp> \<Gamma> \<Longrightarrow> \<not>isin (BVar x \<tau>) \<Gamma>"
@@ -57,7 +64,7 @@ qed auto
5764

5865
lemma fresh_subst_type_same: "atom a \<sharp> \<sigma> \<Longrightarrow> subst_type \<tau> a \<sigma> = \<sigma>"
5966
proof (induction \<tau> a \<sigma> rule: subst_type.induct)
60-
case (4 b \<tau> a \<sigma>)
67+
case (5 b \<tau> a k \<sigma>)
6168
then show ?case
6269
using fresh_Pair fresh_at_base(2) fresh_def list.set(1) list.set(2) subst_type.simps(4) by fastforce
6370
qed auto
@@ -79,8 +86,7 @@ case (TyVar x)
7986
then show ?case using fresh_at_base(2) fresh_subst_type_same by auto
8087
next
8188
case (TyForall x1 x2a)
82-
then show ?case
83-
by (smt flip_at_simps(1) flip_at_simps(2) flip_commute fresh_Pair fresh_subst_type fresh_subst_type_same subst_type.eqvt subst_type.simps(4) subst_type_var_name)
89+
then show ?case using fresh_subst_type subst_type_var_name by auto
8490
qed (auto simp: fresh_subst_type)
8591

8692
end

Semantics.thy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ inductive Step :: "term \<Rightarrow> term \<Rightarrow> bool" ("_ \<longrightar
1212

1313
| ST_SubstI: "Let x \<tau> v e \<longrightarrow> subst_term v x e"
1414

15-
| ST_BetaTI: "TyApp (\<Lambda> a . e) \<tau> \<longrightarrow> subst_term_type \<tau> a e"
15+
| ST_BetaTI: "TyApp (\<Lambda> a : k . e) \<tau> \<longrightarrow> subst_term_type \<tau> a e"
1616

1717
| ST_AppTI: "e1 \<longrightarrow> e2 \<Longrightarrow> TyApp e1 \<tau> \<longrightarrow> TyApp e2 \<tau>"
1818
equivariance Step

0 commit comments

Comments
 (0)