src/CTT/ex/Typechecking.thy
changeset 58972 5b026cfc5f04
parent 58963 26bf09b95dda
child 58974 cbc2ac19d783
equal deleted inserted replaced
58971:8c9a319821b3 58972:5b026cfc5f04
    32 
    32 
    33 
    33 
    34 subsection {* Multi-step proofs: Type inference *}
    34 subsection {* Multi-step proofs: Type inference *}
    35 
    35 
    36 lemma "PROD w:N. N + N type"
    36 lemma "PROD w:N. N + N type"
    37 apply (tactic "form_tac @{context}")
    37 apply form
    38 done
    38 done
    39 
    39 
    40 schematic_lemma "<0, succ(0)> : ?A"
    40 schematic_lemma "<0, succ(0)> : ?A"
    41 apply (tactic "intr_tac @{context} []")
    41 apply intr
    42 done
    42 done
    43 
    43 
    44 schematic_lemma "PROD w:N . Eq(?A,w,w) type"
    44 schematic_lemma "PROD w:N . Eq(?A,w,w) type"
    45 apply (tactic "typechk_tac @{context} []")
    45 apply typechk
    46 done
    46 done
    47 
    47 
    48 schematic_lemma "PROD x:N . PROD y:N . Eq(?A,x,y) type"
    48 schematic_lemma "PROD x:N . PROD y:N . Eq(?A,x,y) type"
    49 apply (tactic "typechk_tac @{context} []")
    49 apply typechk
    50 done
    50 done
    51 
    51 
    52 text "typechecking an application of fst"
    52 text "typechecking an application of fst"
    53 schematic_lemma "(lam u. split(u, %v w. v)) ` <0, succ(0)> : ?A"
    53 schematic_lemma "(lam u. split(u, %v w. v)) ` <0, succ(0)> : ?A"
    54 apply (tactic "typechk_tac @{context} []")
    54 apply typechk
    55 done
    55 done
    56 
    56 
    57 text "typechecking the predecessor function"
    57 text "typechecking the predecessor function"
    58 schematic_lemma "lam n. rec(n, 0, %x y. x) : ?A"
    58 schematic_lemma "lam n. rec(n, 0, %x y. x) : ?A"
    59 apply (tactic "typechk_tac @{context} []")
    59 apply typechk
    60 done
    60 done
    61 
    61 
    62 text "typechecking the addition function"
    62 text "typechecking the addition function"
    63 schematic_lemma "lam n. lam m. rec(n, m, %x y. succ(y)) : ?A"
    63 schematic_lemma "lam n. lam m. rec(n, m, %x y. succ(y)) : ?A"
    64 apply (tactic "typechk_tac @{context} []")
    64 apply typechk
    65 done
    65 done
    66 
    66 
    67 (*Proofs involving arbitrary types.
    67 (*Proofs involving arbitrary types.
    68   For concreteness, every type variable left over is forced to be N*)
    68   For concreteness, every type variable left over is forced to be N*)
    69 ML {* val N_tac = TRYALL (rtac @{thm NF}) *}
    69 method_setup N = {*
       
    70   Scan.succeed (fn _ => SIMPLE_METHOD (TRYALL (resolve_tac @{thms NF})))
       
    71 *}
    70 
    72 
    71 schematic_lemma "lam w. <w,w> : ?A"
    73 schematic_lemma "lam w. <w,w> : ?A"
    72 apply (tactic "typechk_tac @{context} []")
    74 apply typechk
    73 apply (tactic N_tac)
    75 apply N
    74 done
    76 done
    75 
    77 
    76 schematic_lemma "lam x. lam y. x : ?A"
    78 schematic_lemma "lam x. lam y. x : ?A"
    77 apply (tactic "typechk_tac @{context} []")
    79 apply typechk
    78 apply (tactic N_tac)
    80 apply N
    79 done
    81 done
    80 
    82 
    81 text "typechecking fst (as a function object)"
    83 text "typechecking fst (as a function object)"
    82 schematic_lemma "lam i. split(i, %j k. j) : ?A"
    84 schematic_lemma "lam i. split(i, %j k. j) : ?A"
    83 apply (tactic "typechk_tac @{context} []")
    85 apply typechk
    84 apply (tactic N_tac)
    86 apply N
    85 done
    87 done
    86 
    88 
    87 end
    89 end