182 ( |
182 ( |
183 type T = unit -> term list option |
183 type T = unit -> term list option |
184 fun init _ () = error "Counterexample" |
184 fun init _ () = error "Counterexample" |
185 ) |
185 ) |
186 |
186 |
187 val put_counterexample = Counterexample.put |
187 val put_counterexample = Counterexample.put |
188 |
188 |
189 fun finitize_functions t = t |
189 fun finitize_functions t = |
|
190 let |
|
191 val ((names, Ts), t') = apfst split_list (strip_abs t) |
|
192 fun mk_eval_ffun dT rT = |
|
193 Const (@{const_name "Quickcheck_Narrowing.eval_ffun"}, |
|
194 Type (@{type_name "Quickcheck_Narrowing.ffun"}, [dT, rT]) --> dT --> rT) |
|
195 fun mk_eval_cfun dT rT = |
|
196 Const (@{const_name "Quickcheck_Narrowing.eval_cfun"}, |
|
197 Type (@{type_name "Quickcheck_Narrowing.cfun"}, [rT]) --> dT --> rT) |
|
198 fun eval_function (T as Type (@{type_name fun}, [dT, rT])) = |
|
199 let |
|
200 val (rt', rT') = eval_function rT |
|
201 in |
|
202 case dT of |
|
203 Type (@{type_name fun}, _) => |
|
204 (fn t => absdummy (dT, rt' (mk_eval_cfun dT rT' $ incr_boundvars 1 t $ Bound 0)), |
|
205 Type (@{type_name "Quickcheck_Narrowing.cfun"}, [rT'])) |
|
206 | _ => (fn t => absdummy (dT, rt' (mk_eval_ffun dT rT' $ incr_boundvars 1 t $ Bound 0)), |
|
207 Type (@{type_name "Quickcheck_Narrowing.ffun"}, [dT, rT'])) |
|
208 end |
|
209 | eval_function T = (I, T) |
|
210 val (tt, Ts') = split_list (map eval_function Ts) |
|
211 val t'' = subst_bounds (map2 (fn f => fn x => f x) (rev tt) (map_index (Bound o fst) Ts), t') |
|
212 in |
|
213 list_abs (names ~~ Ts', t'') |
|
214 end |
190 |
215 |
191 fun compile_generator_expr ctxt t size = |
216 fun compile_generator_expr ctxt t size = |
192 let |
217 let |
193 val thy = ProofContext.theory_of ctxt |
218 val thy = ProofContext.theory_of ctxt |
194 val t' = if Config.get ctxt finite_functions then finitize_functions t else t |
219 val t' = if Config.get ctxt finite_functions then finitize_functions t else t |