src/HOL/Datatype.thy
changeset 21111 624ed9c7c4fe
parent 21079 747d716e98d0
child 21126 4dbc3ccbaab0
equal deleted inserted replaced
21110:fc98cb66c5c3 21111:624ed9c7c4fe
   721 lemma option_map_o_sum_case [simp]:
   721 lemma option_map_o_sum_case [simp]:
   722     "option_map f o sum_case g h = sum_case (option_map f o g) (option_map f o h)"
   722     "option_map f o sum_case g h = sum_case (option_map f o g) (option_map f o h)"
   723   by (rule ext) (simp split: sum.split)
   723   by (rule ext) (simp split: sum.split)
   724 
   724 
   725 
   725 
   726 subsubsection {* Codegenerator setup *}
   726 subsubsection {* Code generator setup *}
   727 
   727 
   728 consts
   728 definition
   729   is_none :: "'a option \<Rightarrow> bool"
   729   is_none :: "'a option \<Rightarrow> bool"
   730 primrec
   730   is_none_none [normal post, symmetric, code inline]: "is_none x \<longleftrightarrow> x = None"
   731   "is_none None = True"
   731 
   732   "is_none (Some x) = False"
   732 lemma is_none_code [code]:
   733 
   733   shows "is_none None \<longleftrightarrow> True"
   734 lemma is_none_none [code inline, symmetric, normal post]:
   734     and "is_none (Some x) \<longleftrightarrow> False"
   735     "(x = None) = (is_none x)" 
   735   unfolding is_none_none [symmetric] by simp_all
   736   by (cases x) simp_all
   736 
       
   737 hide (open) const is_none
   737 
   738 
   738 lemmas [code] = imp_conv_disj
   739 lemmas [code] = imp_conv_disj
   739 
   740 
   740 lemma [code func]:
   741 lemma [code func]:
   741   "(\<not> True) = False" by (rule HOL.simp_thms)
   742   "(\<not> True) = False" by (rule HOL.simp_thms)
   764 lemma split_is_prod_case [code inline]:
   765 lemma split_is_prod_case [code inline]:
   765     "split = prod_case"
   766     "split = prod_case"
   766   by (simp add: expand_fun_eq split_def prod.cases)
   767   by (simp add: expand_fun_eq split_def prod.cases)
   767 
   768 
   768 code_type bool
   769 code_type bool
   769   (SML target_atom "bool")
   770   (SML "bool")
   770   (Haskell target_atom "Bool")
   771   (Haskell "Bool")
   771 
   772 
   772 code_const True and False and Not and "op &" and "op |" and If
   773 code_const True and False and Not and "op &" and "op |" and If
   773   (SML target_atom "true" and target_atom "false" and target_atom "not"
   774   (SML "true" and "false" and "not"
   774     and infixl 1 "andalso" and infixl 0 "orelse"
   775     and infixl 1 "andalso" and infixl 0 "orelse"
   775     and target_atom "(if __/ then __/ else __)")
   776     and "!(if __/ then __/ else __)")
   776   (Haskell target_atom "True" and target_atom "False" and target_atom "not"
   777   (Haskell "True" and "False" and "not"
   777     and infixl 3 "&&" and infixl 2 "||"
   778     and infixl 3 "&&" and infixl 2 "||"
   778     and target_atom "(if __/ then __/ else __)")
   779     and "!(if __/ then __/ else __)")
   779 
   780 
   780 code_type *
   781 code_type *
   781   (SML infix 2 "*")
   782   (SML infix 2 "*")
   782   (Haskell target_atom "(__,/ __)")
   783   (Haskell "!(__,/ __)")
   783 
   784 
   784 code_const Pair
   785 code_const Pair
   785   (SML target_atom "(__,/ __)")
   786   (SML "!(__,/ __)")
   786   (Haskell target_atom "(__,/ __)")
   787   (Haskell "!(__,/ __)")
   787 
   788 
   788 code_type unit
   789 code_type unit
   789   (SML target_atom "unit")
   790   (SML "unit")
   790   (Haskell target_atom "()")
   791   (Haskell "()")
   791 
   792 
   792 code_const Unity
   793 code_const Unity
   793   (SML target_atom "()")
   794   (SML "()")
   794   (Haskell target_atom "()")
   795   (Haskell "()")
   795 
   796 
   796 code_type option
   797 code_type option
   797   (SML "_ option")
   798   (SML "_ option")
   798   (Haskell "Maybe _")
   799   (Haskell "Maybe _")
   799 
   800 
   800 code_const None and Some
   801 code_const None and Some
   801   (SML target_atom "NONE" and target_atom "SOME")
   802   (SML "NONE" and "SOME")
   802   (Haskell target_atom "Nothing" and target_atom "Just")
   803   (Haskell "Nothing" and "Just")
   803 
   804 
   804 code_instance option :: eq
   805 code_instance option :: eq
   805   (Haskell -)
   806   (Haskell -)
   806 
   807 
   807 code_const "Code_Generator.eq \<Colon> 'a\<Colon>eq option \<Rightarrow> 'a option \<Rightarrow> bool"
   808 code_const "Code_Generator.eq \<Colon> 'a\<Colon>eq option \<Rightarrow> 'a option \<Rightarrow> bool"