src/HOL/Library/DAList.thy
changeset 72581 de581f98a3a1
parent 67091 1393c2340eec
child 72607 feebdaa346e5
equal deleted inserted replaced
72580:531a0c44ea3f 72581:de581f98a3a1
   126 end
   126 end
   127 
   127 
   128 
   128 
   129 subsection \<open>Quickcheck generators\<close>
   129 subsection \<open>Quickcheck generators\<close>
   130 
   130 
   131 notation fcomp (infixl "\<circ>>" 60)
       
   132 notation scomp (infixl "\<circ>\<rightarrow>" 60)
       
   133 
       
   134 definition (in term_syntax)
   131 definition (in term_syntax)
   135   valterm_empty :: "('key :: typerep, 'value :: typerep) alist \<times> (unit \<Rightarrow> Code_Evaluation.term)"
   132   valterm_empty :: "('key :: typerep, 'value :: typerep) alist \<times> (unit \<Rightarrow> Code_Evaluation.term)"
   136   where "valterm_empty = Code_Evaluation.valtermify empty"
   133   where "valterm_empty = Code_Evaluation.valtermify empty"
   137 
   134 
   138 definition (in term_syntax)
   135 definition (in term_syntax)
   140   'value :: typerep \<times> (unit \<Rightarrow> Code_Evaluation.term) \<Rightarrow>
   137   'value :: typerep \<times> (unit \<Rightarrow> Code_Evaluation.term) \<Rightarrow>
   141   ('key, 'value) alist \<times> (unit \<Rightarrow> Code_Evaluation.term) \<Rightarrow>
   138   ('key, 'value) alist \<times> (unit \<Rightarrow> Code_Evaluation.term) \<Rightarrow>
   142   ('key, 'value) alist \<times> (unit \<Rightarrow> Code_Evaluation.term)" where
   139   ('key, 'value) alist \<times> (unit \<Rightarrow> Code_Evaluation.term)" where
   143   [code_unfold]: "valterm_update k v a = Code_Evaluation.valtermify update {\<cdot>} k {\<cdot>} v {\<cdot>}a"
   140   [code_unfold]: "valterm_update k v a = Code_Evaluation.valtermify update {\<cdot>} k {\<cdot>} v {\<cdot>}a"
   144 
   141 
   145 fun (in term_syntax) random_aux_alist
   142 context
       
   143   includes state_combinator_syntax
       
   144 begin
       
   145 
       
   146 fun random_aux_alist
   146 where
   147 where
   147   "random_aux_alist i j =
   148   "random_aux_alist i j =
   148     (if i = 0 then Pair valterm_empty
   149     (if i = 0 then Pair valterm_empty
   149      else Quickcheck_Random.collapse
   150      else Quickcheck_Random.collapse
   150        (Random.select_weight
   151        (Random.select_weight
   151          [(i, Quickcheck_Random.random j \<circ>\<rightarrow> (\<lambda>k. Quickcheck_Random.random j \<circ>\<rightarrow>
   152          [(i, Quickcheck_Random.random j \<circ>\<rightarrow> (\<lambda>k. Quickcheck_Random.random j \<circ>\<rightarrow>
   152            (\<lambda>v. random_aux_alist (i - 1) j \<circ>\<rightarrow> (\<lambda>a. Pair (valterm_update k v a))))),
   153            (\<lambda>v. random_aux_alist (i - 1) j \<circ>\<rightarrow> (\<lambda>a. Pair (valterm_update k v a))))),
   153           (1, Pair valterm_empty)]))"
   154           (1, Pair valterm_empty)]))"
   154 
   155 
       
   156 end
       
   157 
   155 instantiation alist :: (random, random) random
   158 instantiation alist :: (random, random) random
   156 begin
   159 begin
   157 
   160 
   158 definition random_alist
   161 definition random_alist
   159 where
   162 where
   160   "random_alist i = random_aux_alist i i"
   163   "random_alist i = random_aux_alist i i"
   161 
   164 
   162 instance ..
   165 instance ..
   163 
   166 
   164 end
   167 end
   165 
       
   166 no_notation fcomp (infixl "\<circ>>" 60)
       
   167 no_notation scomp (infixl "\<circ>\<rightarrow>" 60)
       
   168 
   168 
   169 instantiation alist :: (exhaustive, exhaustive) exhaustive
   169 instantiation alist :: (exhaustive, exhaustive) exhaustive
   170 begin
   170 begin
   171 
   171 
   172 fun exhaustive_alist ::
   172 fun exhaustive_alist ::