src/HOL/Datatype.thy
changeset 19817 bb16bf9ae3fd
parent 19787 b949911ecff5
child 19890 1aad48bcc674
equal deleted inserted replaced
19816:a8c8ed1c85e0 19817:bb16bf9ae3fd
   217   apply (rule ext)
   217   apply (rule ext)
   218   apply (simp split add: sum.split)
   218   apply (simp split add: sum.split)
   219   done
   219   done
   220 
   220 
   221 
   221 
       
   222 subsubsection {* Codegenerator setup *}
       
   223 
   222 consts
   224 consts
   223   is_none :: "'a option \<Rightarrow> bool"
   225   is_none :: "'a option \<Rightarrow> bool"
   224 primrec
   226 primrec
   225   "is_none None = True"
   227   "is_none None = True"
   226   "is_none (Some x) = False"
   228   "is_none (Some x) = False"
   227 
   229 
   228 (* lemma is_none_none [code unfolt]:
   230 lemma is_none_none [code unfolt]:
   229   "(x = None) = (is_none x)" 
   231   "(x = None) = (is_none x)" 
   230 by (cases "x") simp_all *)
   232 by (cases "x") simp_all
   231 
   233 
   232 lemmas [code] = imp_conv_disj
   234 lemmas [code] = imp_conv_disj
   233 
       
   234 subsubsection {* Codegenerator setup *}
       
   235 
   235 
   236 lemma [code fun]:
   236 lemma [code fun]:
   237   "(\<not> True) = False" by (rule HOL.simp_thms)
   237   "(\<not> True) = False" by (rule HOL.simp_thms)
   238 
   238 
   239 lemma [code fun]:
   239 lemma [code fun]:
   257   fst_conv [code]
   257   fst_conv [code]
   258   snd_conv [code]
   258   snd_conv [code]
   259 
   259 
   260 lemma [code unfolt]:
   260 lemma [code unfolt]:
   261   "1 == Suc 0" by simp
   261   "1 == Suc 0" by simp
   262 
       
   263 code_generate True False Not "op &" "op |" If
       
   264 
   262 
   265 code_syntax_tyco bool
   263 code_syntax_tyco bool
   266   ml (target_atom "bool")
   264   ml (target_atom "bool")
   267   haskell (target_atom "Bool")
   265   haskell (target_atom "Bool")
   268 
   266 
   284     haskell (infixl 2 "||")
   282     haskell (infixl 2 "||")
   285   If
   283   If
   286     ml (target_atom "(if __/ then __/ else __)")
   284     ml (target_atom "(if __/ then __/ else __)")
   287     haskell (target_atom "(if __/ then __/ else __)")
   285     haskell (target_atom "(if __/ then __/ else __)")
   288 
   286 
   289 code_generate Pair
       
   290 
       
   291 code_syntax_tyco
   287 code_syntax_tyco
   292   *
   288   *
   293     ml (infix 2 "*")
   289     ml (infix 2 "*")
   294     haskell (target_atom "(__,/ __)")
   290     haskell (target_atom "(__,/ __)")
   295 
   291 
   296 code_syntax_const
   292 code_syntax_const
   297   Pair
   293   Pair
   298     ml (target_atom "(__,/ __)")
   294     ml (target_atom "(__,/ __)")
   299     haskell (target_atom "(__,/ __)")
   295     haskell (target_atom "(__,/ __)")
   300 
   296 
   301 code_generate Unity
       
   302 
       
   303 code_syntax_tyco
   297 code_syntax_tyco
   304   unit
   298   unit
   305     ml (target_atom "unit")
   299     ml (target_atom "unit")
   306     haskell (target_atom "()")
   300     haskell (target_atom "()")
   307 
   301 
   308 code_syntax_const
   302 code_syntax_const
   309   Unity
   303   Unity
   310     ml (target_atom "()")
   304     ml (target_atom "()")
   311     haskell (target_atom "()")
   305     haskell (target_atom "()")
   312 
       
   313 code_generate None Some
       
   314 
   306 
   315 code_syntax_tyco
   307 code_syntax_tyco
   316   option
   308   option
   317     ml ("_ option")
   309     ml ("_ option")
   318     haskell ("Maybe _")
   310     haskell ("Maybe _")
   323     haskell (target_atom "Nothing")
   315     haskell (target_atom "Nothing")
   324   Some
   316   Some
   325     ml (target_atom "SOME")
   317     ml (target_atom "SOME")
   326     haskell (target_atom "Just")
   318     haskell (target_atom "Just")
   327 
   319 
   328 
       
   329 
       
   330 
       
   331 end
   320 end