117 |
117 |
118 declare [[code drop: rec_term case_term |
118 declare [[code drop: rec_term case_term |
119 "term_of :: typerep \<Rightarrow> _" "term_of :: term \<Rightarrow> _" "term_of :: String.literal \<Rightarrow> _" |
119 "term_of :: typerep \<Rightarrow> _" "term_of :: term \<Rightarrow> _" "term_of :: String.literal \<Rightarrow> _" |
120 "term_of :: _ Predicate.pred \<Rightarrow> term" "term_of :: _ Predicate.seq \<Rightarrow> term"]] |
120 "term_of :: _ Predicate.pred \<Rightarrow> term" "term_of :: _ Predicate.seq \<Rightarrow> term"]] |
121 |
121 |
122 definition case_char :: "'a \<Rightarrow> (num \<Rightarrow> 'a) \<Rightarrow> char \<Rightarrow> 'a" |
|
123 where "case_char f g c = (if c = 0 then f else g (num_of_nat (nat_of_char c)))" |
|
124 |
|
125 lemma term_of_char [unfolded typerep_fun_def typerep_char_def typerep_num_def, code]: |
|
126 "term_of = |
|
127 case_char (Const (STR ''Groups.zero_class.zero'') (TYPEREP(char))) |
|
128 (\<lambda>k. App (Const (STR ''String.Char'') (TYPEREP(num \<Rightarrow> char))) (term_of k))" |
|
129 by (rule ext) (rule term_of_anything [THEN meta_eq_to_obj_eq]) |
|
130 |
|
131 lemma term_of_string [code]: |
|
132 "term_of s = App (Const (STR ''STR'') |
|
133 (Typerep.Typerep (STR ''fun'') [Typerep.Typerep (STR ''list'') [Typerep.Typerep (STR ''char'') []], |
|
134 Typerep.Typerep (STR ''String.literal'') []])) (term_of (String.explode s))" |
|
135 by (subst term_of_anything) rule |
|
136 |
|
137 code_printing |
122 code_printing |
138 constant "term_of :: integer \<Rightarrow> term" \<rightharpoonup> (Eval) "HOLogic.mk'_number/ HOLogic.code'_integerT" |
123 constant "term_of :: integer \<Rightarrow> term" \<rightharpoonup> (Eval) "HOLogic.mk'_number/ HOLogic.code'_integerT" |
139 | constant "term_of :: String.literal \<Rightarrow> term" \<rightharpoonup> (Eval) "HOLogic.mk'_literal" |
124 | constant "term_of :: String.literal \<Rightarrow> term" \<rightharpoonup> (Eval) "HOLogic.mk'_literal" |
140 |
125 |
141 declare [[code drop: "term_of :: integer \<Rightarrow> _"]] |
126 declare [[code drop: "term_of :: integer \<Rightarrow> _"]] |