src/HOL/IMP/Poly_Types.thy
author bulwahn
Fri Oct 21 11:17:14 2011 +0200 (2011-10-21)
changeset 45231 d85a2fdc586c
parent 45212 e87feee00a4c
child 52046 bc01725d7918
permissions -rw-r--r--
replacing code_inline by code_unfold, removing obsolete code_unfold, code_inline del now that the ancient code generator is removed
nipkow@43150
     1
theory Poly_Types imports Types begin
nipkow@43150
     2
nipkow@43150
     3
subsection "Type Variables"
nipkow@43150
     4
nipkow@43150
     5
datatype ty = Ity | Rty | TV nat
nipkow@43150
     6
nipkow@43150
     7
text{* Everything else remains the same. *}
nipkow@43150
     8
nipkow@45212
     9
type_synonym tyenv = "vname \<Rightarrow> ty"
nipkow@43150
    10
nipkow@43150
    11
inductive atyping :: "tyenv \<Rightarrow> aexp \<Rightarrow> ty \<Rightarrow> bool"
nipkow@43150
    12
  ("(1_/ \<turnstile>p/ (_ :/ _))" [50,0,50] 50)
nipkow@43150
    13
where
nipkow@43150
    14
"\<Gamma> \<turnstile>p Ic i : Ity" |
nipkow@43150
    15
"\<Gamma> \<turnstile>p Rc r : Rty" |
nipkow@43150
    16
"\<Gamma> \<turnstile>p V x : \<Gamma> x" |
nipkow@43150
    17
"\<Gamma> \<turnstile>p a1 : \<tau> \<Longrightarrow> \<Gamma> \<turnstile>p a2 : \<tau> \<Longrightarrow> \<Gamma> \<turnstile>p Plus a1 a2 : \<tau>"
nipkow@43150
    18
nipkow@43150
    19
inductive btyping :: "tyenv \<Rightarrow> bexp \<Rightarrow> bool" (infix "\<turnstile>p" 50)
nipkow@43150
    20
where
nipkow@45200
    21
"\<Gamma> \<turnstile>p Bc v" |
nipkow@43150
    22
"\<Gamma> \<turnstile>p b \<Longrightarrow> \<Gamma> \<turnstile>p Not b" |
nipkow@43150
    23
"\<Gamma> \<turnstile>p b1 \<Longrightarrow> \<Gamma> \<turnstile>p b2 \<Longrightarrow> \<Gamma> \<turnstile>p And b1 b2" |
nipkow@43150
    24
"\<Gamma> \<turnstile>p a1 : \<tau> \<Longrightarrow> \<Gamma> \<turnstile>p a2 : \<tau> \<Longrightarrow> \<Gamma> \<turnstile>p Less a1 a2"
nipkow@43150
    25
nipkow@43150
    26
inductive ctyping :: "tyenv \<Rightarrow> com \<Rightarrow> bool" (infix "\<turnstile>p" 50) where
nipkow@43150
    27
"\<Gamma> \<turnstile>p SKIP" |
nipkow@43150
    28
"\<Gamma> \<turnstile>p a : \<Gamma>(x) \<Longrightarrow> \<Gamma> \<turnstile>p x ::= a" |
nipkow@43150
    29
"\<Gamma> \<turnstile>p c1 \<Longrightarrow> \<Gamma> \<turnstile>p c2 \<Longrightarrow> \<Gamma> \<turnstile>p c1;c2" |
nipkow@43150
    30
"\<Gamma> \<turnstile>p b \<Longrightarrow> \<Gamma> \<turnstile>p c1 \<Longrightarrow> \<Gamma> \<turnstile>p c2 \<Longrightarrow> \<Gamma> \<turnstile>p IF b THEN c1 ELSE c2" |
nipkow@43150
    31
"\<Gamma> \<turnstile>p b \<Longrightarrow> \<Gamma> \<turnstile>p c \<Longrightarrow> \<Gamma> \<turnstile>p WHILE b DO c"
nipkow@43150
    32
nipkow@43150
    33
fun type :: "val \<Rightarrow> ty" where
nipkow@43150
    34
"type (Iv i) = Ity" |
nipkow@43150
    35
"type (Rv r) = Rty"
nipkow@43150
    36
nipkow@43150
    37
definition styping :: "tyenv \<Rightarrow> state \<Rightarrow> bool" (infix "\<turnstile>p" 50)
nipkow@43150
    38
where "\<Gamma> \<turnstile>p s  \<longleftrightarrow>  (\<forall>x. type (s x) = \<Gamma> x)"
nipkow@43150
    39
nipkow@43150
    40
fun tsubst :: "(nat \<Rightarrow> ty) \<Rightarrow> ty \<Rightarrow> ty" where
nipkow@43150
    41
"tsubst S (TV n) = S n" |
nipkow@43150
    42
"tsubst S t = t"
nipkow@43150
    43
nipkow@43150
    44
nipkow@43150
    45
subsection{* Typing is Preserved by Substitution *}
nipkow@43150
    46
nipkow@43150
    47
lemma subst_atyping: "E \<turnstile>p a : t \<Longrightarrow> tsubst S \<circ> E \<turnstile>p a : tsubst S t"
nipkow@45015
    48
apply(induction rule: atyping.induct)
nipkow@43150
    49
apply(auto intro: atyping.intros)
nipkow@43150
    50
done
nipkow@43150
    51
nipkow@43150
    52
lemma subst_btyping: "E \<turnstile>p (b::bexp) \<Longrightarrow> tsubst S \<circ> E \<turnstile>p b"
nipkow@45015
    53
apply(induction rule: btyping.induct)
nipkow@43150
    54
apply(auto intro: btyping.intros)
nipkow@43150
    55
apply(drule subst_atyping[where S=S])
nipkow@43150
    56
apply(drule subst_atyping[where S=S])
nipkow@43150
    57
apply(simp add: o_def btyping.intros)
nipkow@43150
    58
done
nipkow@43150
    59
nipkow@43150
    60
lemma subst_ctyping: "E \<turnstile>p (c::com) \<Longrightarrow> tsubst S \<circ> E \<turnstile>p c"
nipkow@45015
    61
apply(induction rule: ctyping.induct)
nipkow@43150
    62
apply(auto intro: ctyping.intros)
nipkow@43150
    63
apply(drule subst_atyping[where S=S])
nipkow@43150
    64
apply(simp add: o_def ctyping.intros)
nipkow@43150
    65
apply(drule subst_btyping[where S=S])
nipkow@43150
    66
apply(simp add: o_def ctyping.intros)
nipkow@43150
    67
apply(drule subst_btyping[where S=S])
nipkow@43150
    68
apply(simp add: o_def ctyping.intros)
nipkow@43150
    69
done
nipkow@43150
    70
nipkow@43150
    71
end