src/HOL/Codegenerator_Test/Candidates.thy
changeset 61129 774752af4a1f
parent 59842 9fda99b3d5ee
child 61130 8e736ce4c6f4
equal deleted inserted replaced
61128:8e5072cba671 61129:774752af4a1f
    10   "~~/src/HOL/Library/Sublist_Order"
    10   "~~/src/HOL/Library/Sublist_Order"
    11   "~~/src/HOL/Number_Theory/Eratosthenes"
    11   "~~/src/HOL/Number_Theory/Eratosthenes"
    12   "~~/src/HOL/ex/Records"
    12   "~~/src/HOL/ex/Records"
    13 begin
    13 begin
    14 
    14 
       
    15 text \<open>Drop technical stuff from @{theory Quickcheck_Narrowing} which is tailored towards Haskell\<close>
       
    16 
    15 setup \<open>
    17 setup \<open>
    16 fn thy =>
    18 fn thy =>
    17 let
    19 let
    18   val tycos = Sign.logical_types thy;
    20   val tycos = Sign.logical_types thy;
    19   val consts = map_filter (try (curry (Axclass.param_of_inst thy)
    21   val consts = map_filter (try (curry (Axclass.param_of_inst thy)
    20     @{const_name "Quickcheck_Narrowing.partial_term_of"})) tycos;
    22     @{const_name "Quickcheck_Narrowing.partial_term_of"})) tycos;
    21 in fold Code.del_eqns consts thy end
    23 in fold Code.del_eqns consts thy end
    22 \<close> -- \<open>drop technical stuff from @{text Quickcheck_Narrowing} which is tailored towards Haskell\<close>
    24 \<close>
       
    25 
       
    26 text \<open>Simple example for the predicate compiler.\<close>
    23 
    27 
    24 inductive sublist :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool"
    28 inductive sublist :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool"
    25 where
    29 where
    26   empty: "sublist [] xs"
    30   empty: "sublist [] xs"
    27 | drop: "sublist ys xs \<Longrightarrow> sublist ys (x # xs)"
    31 | drop: "sublist ys xs \<Longrightarrow> sublist ys (x # xs)"
    28 | take: "sublist ys xs \<Longrightarrow> sublist (x # ys) (x # xs)"
    32 | take: "sublist ys xs \<Longrightarrow> sublist (x # ys) (x # xs)"
    29 
    33 
    30 code_pred sublist .
    34 code_pred sublist .
    31 
    35 
    32 code_reserved SML upto -- {* avoid popular infix *}
    36 text \<open>Avoid popular infix.\<close>
       
    37 
       
    38 code_reserved SML upto
       
    39 
       
    40 text \<open>Explicit check in @{text OCaml} for correct precedence of let expressions in list expressions\<close>
       
    41 
       
    42 definition funny_list :: "bool list"
       
    43 where
       
    44   "funny_list = [let b = True in b, False]"
       
    45 
       
    46 definition funny_list' :: "bool list"
       
    47 where
       
    48   "funny_list' = funny_list"
       
    49 
       
    50 lemma [code]:
       
    51   "funny_list' = [True, False]"
       
    52   by (simp add: funny_list_def funny_list'_def)
       
    53 
       
    54 definition check_list :: unit
       
    55 where
       
    56   "check_list = (if funny_list = funny_list' then () else undefined)"
    33 
    57 
    34 end
    58 end