src/HOL/Code_Evaluation.thy
changeset 60758 d8d85a8172b5
parent 59484 a130ae7a9398
child 61076 bdc1e2f0a86a
equal deleted inserted replaced
60757:c09598a97436 60758:d8d85a8172b5
     1 (*  Title:      HOL/Code_Evaluation.thy
     1 (*  Title:      HOL/Code_Evaluation.thy
     2     Author:     Florian Haftmann, TU Muenchen
     2     Author:     Florian Haftmann, TU Muenchen
     3 *)
     3 *)
     4 
     4 
     5 section {* Term evaluation using the generic code generator *}
     5 section \<open>Term evaluation using the generic code generator\<close>
     6 
     6 
     7 theory Code_Evaluation
     7 theory Code_Evaluation
     8 imports Typerep Limited_Sequence
     8 imports Typerep Limited_Sequence
     9 keywords "value" :: diag
     9 keywords "value" :: diag
    10 begin
    10 begin
    11 
    11 
    12 subsection {* Term representation *}
    12 subsection \<open>Term representation\<close>
    13 
    13 
    14 subsubsection {* Terms and class @{text term_of} *}
    14 subsubsection \<open>Terms and class @{text term_of}\<close>
    15 
    15 
    16 datatype (plugins only: code extraction) "term" = dummy_term
    16 datatype (plugins only: code extraction) "term" = dummy_term
    17 
    17 
    18 definition Const :: "String.literal \<Rightarrow> typerep \<Rightarrow> term" where
    18 definition Const :: "String.literal \<Rightarrow> typerep \<Rightarrow> term" where
    19   "Const _ _ = dummy_term"
    19   "Const _ _ = dummy_term"
    42 lemma valapp_code [code, code_unfold]:
    42 lemma valapp_code [code, code_unfold]:
    43   "valapp (f, tf) (x, tx) = (f x, \<lambda>u. App (tf ()) (tx ()))"
    43   "valapp (f, tf) (x, tx) = (f x, \<lambda>u. App (tf ()) (tx ()))"
    44   by (simp only: valapp_def fst_conv snd_conv)
    44   by (simp only: valapp_def fst_conv snd_conv)
    45 
    45 
    46 
    46 
    47 subsubsection {* Syntax *}
    47 subsubsection \<open>Syntax\<close>
    48 
    48 
    49 definition termify :: "'a \<Rightarrow> term" where
    49 definition termify :: "'a \<Rightarrow> term" where
    50   [code del]: "termify x = dummy_term"
    50   [code del]: "termify x = dummy_term"
    51 
    51 
    52 abbreviation valtermify :: "'a \<Rightarrow> 'a \<times> (unit \<Rightarrow> term)" where
    52 abbreviation valtermify :: "'a \<Rightarrow> 'a \<times> (unit \<Rightarrow> term)" where
    64 
    64 
    65 no_notation App (infixl "<\<cdot>>" 70)
    65 no_notation App (infixl "<\<cdot>>" 70)
    66   and valapp (infixl "{\<cdot>}" 70)
    66   and valapp (infixl "{\<cdot>}" 70)
    67 
    67 
    68 
    68 
    69 subsection {* Tools setup and evaluation *}
    69 subsection \<open>Tools setup and evaluation\<close>
    70 
    70 
    71 lemma eq_eq_TrueD:
    71 lemma eq_eq_TrueD:
    72   assumes "(x \<equiv> y) \<equiv> Trueprop True"
    72   assumes "(x \<equiv> y) \<equiv> Trueprop True"
    73   shows "x \<equiv> y"
    73   shows "x \<equiv> y"
    74   using assms by simp
    74   using assms by simp
    85 code_reserved Eval Code_Evaluation
    85 code_reserved Eval Code_Evaluation
    86 
    86 
    87 ML_file "~~/src/HOL/Tools/value.ML"
    87 ML_file "~~/src/HOL/Tools/value.ML"
    88 
    88 
    89 
    89 
    90 subsection {* @{text term_of} instances *}
    90 subsection \<open>@{text term_of} instances\<close>
    91 
    91 
    92 instantiation "fun" :: (typerep, typerep) term_of
    92 instantiation "fun" :: (typerep, typerep) term_of
    93 begin
    93 begin
    94 
    94 
    95 definition
    95 definition
   136 by(rule term_of_anything[THEN meta_eq_to_obj_eq])
   136 by(rule term_of_anything[THEN meta_eq_to_obj_eq])
   137 
   137 
   138 code_reserved Eval HOLogic
   138 code_reserved Eval HOLogic
   139 
   139 
   140 
   140 
   141 subsection {* Generic reification *}
   141 subsection \<open>Generic reification\<close>
   142 
   142 
   143 ML_file "~~/src/HOL/Tools/reification.ML"
   143 ML_file "~~/src/HOL/Tools/reification.ML"
   144 
   144 
   145 
   145 
   146 subsection {* Diagnostic *}
   146 subsection \<open>Diagnostic\<close>
   147 
   147 
   148 definition tracing :: "String.literal \<Rightarrow> 'a \<Rightarrow> 'a" where
   148 definition tracing :: "String.literal \<Rightarrow> 'a \<Rightarrow> 'a" where
   149   [code del]: "tracing s x = x"
   149   [code del]: "tracing s x = x"
   150 
   150 
   151 code_printing
   151 code_printing