src/HOL/Code_Generator.thy
changeset 21454 a1937c51ed88
parent 21404 eb85850d3eb7
child 21546 268b6bed0cc8
equal deleted inserted replaced
21453:03ca07d478be 21454:a1937c51ed88
   190 
   190 
   191 subsection {* Operational equality for code generation *}
   191 subsection {* Operational equality for code generation *}
   192 
   192 
   193 subsubsection {* eq class *}
   193 subsubsection {* eq class *}
   194 
   194 
   195 class eq =
   195 axclass eq \<subseteq> type
   196   fixes eq :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
   196   attach "op ="
   197 
       
   198 defs
       
   199   eq_def [normal post]: "eq \<equiv> (op =)"
       
   200 
       
   201 lemmas [symmetric, code inline, code func] = eq_def
       
   202 
   197 
   203 
   198 
   204 subsubsection {* bool type *}
   199 subsubsection {* bool type *}
   205 
   200 
   206 instance bool :: eq ..
   201 instance bool :: eq ..
   207 
   202 
   208 lemma [code func]:
   203 lemma [code func]:
   209   "eq True p = p" unfolding eq_def by auto
   204   "True = P \<longleftrightarrow> P" by simp
   210 
   205 
   211 lemma [code func]:
   206 lemma [code func]:
   212   "eq False p = (\<not> p)" unfolding eq_def by auto
   207   "False = P \<longleftrightarrow> \<not> P" by simp
   213 
   208 
   214 lemma [code func]:
   209 lemma [code func]:
   215   "eq p True = p" unfolding eq_def by auto
   210   "P = True \<longleftrightarrow> P" by simp
   216 
   211 
   217 lemma [code func]:
   212 lemma [code func]:
   218   "eq p False = (\<not> p)" unfolding eq_def by auto
   213   "P = False \<longleftrightarrow> \<not> P" by simp
   219 
   214 
   220 
   215 
   221 subsubsection {* Haskell *}
   216 subsubsection {* Haskell *}
   222 
   217 
   223 code_class eq
   218 code_class eq
   224   (Haskell "Eq" where eq \<equiv> "(==)")
   219   (Haskell "Eq" where "op =" \<equiv> "(==)")
   225 
   220 
   226 code_const eq
   221 code_const "op ="
   227   (Haskell infixl 4 "==")
   222   (Haskell infixl 4 "==")
   228 
   223 
   229 code_instance bool :: eq
   224 code_instance bool :: eq
   230   (Haskell -)
   225   (Haskell -)
   231 
   226 
   232 code_const "eq \<Colon> bool \<Rightarrow> bool \<Rightarrow> bool"
   227 code_const "op = \<Colon> bool \<Rightarrow> bool \<Rightarrow> bool"
   233   (Haskell infixl 4 "==")
   228   (Haskell infixl 4 "==")
   234 
   229 
   235 code_reserved Haskell
   230 code_reserved Haskell
   236   Eq eq
   231   Eq eq
   237 
   232 
   238 
   233 
   239 hide (open) const eq if_delayed
   234 hide (open) const if_delayed
   240 
   235 
   241 end
   236 end