src/HOL/Smallcheck.thy
author bulwahn
Fri Dec 17 12:14:18 2010 +0100 (2010-12-17)
changeset 41231 2e901158675e
parent 41178 f4d3acf0c4cc
child 41719 91c2510e19c5
permissions -rw-r--r--
adding exhaustive tester instances for numeric types: code_numeral, nat, rat and real
bulwahn@40420
     1
(* Author: Lukas Bulwahn, TU Muenchen *)
bulwahn@40420
     2
bulwahn@40420
     3
header {* Another simple counterexample generator *}
bulwahn@40420
     4
bulwahn@40420
     5
theory Smallcheck
bulwahn@40420
     6
imports Quickcheck
bulwahn@40420
     7
uses ("Tools/smallvalue_generators.ML")
bulwahn@40420
     8
begin
bulwahn@40420
     9
bulwahn@41105
    10
subsection {* basic operations for generators *}
bulwahn@41105
    11
bulwahn@41105
    12
definition orelse :: "'a option => 'a option => 'a option" (infixr "orelse" 55)
bulwahn@41105
    13
where
bulwahn@41105
    14
  [code_unfold]: "x orelse y = (case x of Some x' => Some x' | None => y)"
bulwahn@40420
    15
huffman@40620
    16
subsection {* small value generator type classes *}
bulwahn@40420
    17
bulwahn@40420
    18
class small = term_of +
bulwahn@40420
    19
fixes small :: "('a \<Rightarrow> term list option) \<Rightarrow> code_numeral \<Rightarrow> term list option"
bulwahn@40420
    20
bulwahn@40420
    21
instantiation unit :: small
bulwahn@40420
    22
begin
bulwahn@40420
    23
bulwahn@40639
    24
definition "small f d = f ()"
bulwahn@40420
    25
bulwahn@40420
    26
instance ..
bulwahn@40420
    27
bulwahn@40420
    28
end
bulwahn@40420
    29
bulwahn@40420
    30
instantiation int :: small
bulwahn@40420
    31
begin
bulwahn@40420
    32
bulwahn@40420
    33
function small' :: "(int => term list option) => int => int => term list option"
bulwahn@40420
    34
where "small' f d i = (if d < i then None else (case f i of Some t => Some t | None => small' f d (i + 1)))"
bulwahn@40420
    35
by pat_completeness auto
bulwahn@40420
    36
bulwahn@40420
    37
termination 
bulwahn@40420
    38
  by (relation "measure (%(_, d, i). nat (d + 1 - i))") auto
bulwahn@40420
    39
bulwahn@40420
    40
definition "small f d = small' f (Code_Numeral.int_of d) (- (Code_Numeral.int_of d))"
bulwahn@40420
    41
bulwahn@40420
    42
instance ..
bulwahn@40420
    43
bulwahn@40420
    44
end
bulwahn@40420
    45
bulwahn@40420
    46
instantiation prod :: (small, small) small
bulwahn@40420
    47
begin
bulwahn@40420
    48
bulwahn@40420
    49
definition
bulwahn@40420
    50
  "small f d = small (%x. small (%y. f (x, y)) d) d"
bulwahn@40420
    51
bulwahn@40420
    52
instance ..
bulwahn@40420
    53
bulwahn@40420
    54
end
bulwahn@40420
    55
bulwahn@40899
    56
subsection {* full small value generator type classes *}
bulwahn@40639
    57
bulwahn@40639
    58
class full_small = term_of +
bulwahn@40639
    59
fixes full_small :: "('a * (unit => term) \<Rightarrow> term list option) \<Rightarrow> code_numeral \<Rightarrow> term list option"
bulwahn@40639
    60
bulwahn@40639
    61
instantiation unit :: full_small
bulwahn@40639
    62
begin
bulwahn@40639
    63
bulwahn@40639
    64
definition "full_small f d = f (Code_Evaluation.valtermify ())"
bulwahn@40639
    65
bulwahn@40639
    66
instance ..
bulwahn@40639
    67
bulwahn@40639
    68
end
bulwahn@40639
    69
bulwahn@41231
    70
instantiation code_numeral :: full_small
bulwahn@41231
    71
begin
bulwahn@41231
    72
bulwahn@41231
    73
function full_small_code_numeral' :: "(code_numeral * (unit => term) => term list option) => code_numeral => code_numeral => term list option"
bulwahn@41231
    74
  where "full_small_code_numeral' f d i = (if d < i then None else (case f (i, %_. Code_Evaluation.term_of i) of Some t => Some t | None => full_small_code_numeral' f d (i + 1)))"
bulwahn@41231
    75
by pat_completeness auto
bulwahn@41231
    76
bulwahn@41231
    77
termination 
bulwahn@41231
    78
  by (relation "measure (%(_, d, i). Code_Numeral.nat_of (d + 1 - i))") auto
bulwahn@41231
    79
bulwahn@41231
    80
definition "full_small f d = full_small_code_numeral' f d 0"
bulwahn@41231
    81
bulwahn@41231
    82
instance ..
bulwahn@41231
    83
bulwahn@41231
    84
end
bulwahn@41231
    85
bulwahn@41231
    86
instantiation nat :: full_small
bulwahn@41231
    87
begin
bulwahn@41231
    88
bulwahn@41231
    89
definition "full_small f d = full_small (%(x, xt). f (Code_Numeral.nat_of x, %_. Code_Evaluation.term_of (Code_Numeral.nat_of x))) d"
bulwahn@41231
    90
bulwahn@41231
    91
instance ..
bulwahn@41231
    92
bulwahn@41231
    93
end
bulwahn@41231
    94
bulwahn@40639
    95
instantiation int :: full_small
bulwahn@40639
    96
begin
bulwahn@40639
    97
bulwahn@40639
    98
function full_small' :: "(int * (unit => term) => term list option) => int => int => term list option"
bulwahn@40639
    99
  where "full_small' f d i = (if d < i then None else (case f (i, %_. Code_Evaluation.term_of i) of Some t => Some t | None => full_small' f d (i + 1)))"
bulwahn@40639
   100
by pat_completeness auto
bulwahn@40639
   101
bulwahn@40639
   102
termination 
bulwahn@40639
   103
  by (relation "measure (%(_, d, i). nat (d + 1 - i))") auto
bulwahn@40639
   104
bulwahn@40639
   105
definition "full_small f d = full_small' f (Code_Numeral.int_of d) (- (Code_Numeral.int_of d))"
bulwahn@40639
   106
bulwahn@40639
   107
instance ..
bulwahn@40639
   108
bulwahn@40639
   109
end
bulwahn@40639
   110
bulwahn@40639
   111
instantiation prod :: (full_small, full_small) full_small
bulwahn@40639
   112
begin
bulwahn@40899
   113
bulwahn@40639
   114
definition
bulwahn@40639
   115
  "full_small f d = full_small (%(x, t1). full_small (%(y, t2). f ((x, y),
bulwahn@40639
   116
    %u. Code_Evaluation.App (Code_Evaluation.App (Code_Evaluation.term_of (Pair :: 'a => 'b => ('a * 'b))) (t1 ())) (t2 ()))) d) d"
bulwahn@40639
   117
bulwahn@40639
   118
instance ..
bulwahn@40639
   119
bulwahn@40639
   120
end
bulwahn@40639
   121
bulwahn@40639
   122
instantiation "fun" :: ("{equal, full_small}", full_small) full_small
bulwahn@40639
   123
begin
bulwahn@40639
   124
bulwahn@40639
   125
fun full_small_fun' :: "(('a => 'b) * (unit => term) => term list option) => code_numeral => code_numeral => term list option"
bulwahn@40639
   126
where
bulwahn@40639
   127
  "full_small_fun' f i d = (if i > 1 then
bulwahn@40639
   128
    full_small (%(a, at). full_small (%(b, bt).
bulwahn@40639
   129
      full_small_fun' (%(g, gt). f (g(a := b),
bulwahn@40899
   130
        (%_. let T1 = (Typerep.typerep (TYPE('a)));
bulwahn@40899
   131
                 T2 = (Typerep.typerep (TYPE('b)))
bulwahn@40899
   132
             in
bulwahn@40899
   133
               Code_Evaluation.App (Code_Evaluation.App (Code_Evaluation.App
bulwahn@40899
   134
                 (Code_Evaluation.Const (STR ''Fun.fun_upd'')
bulwahn@40899
   135
                    (Typerep.Typerep (STR ''fun'') [Typerep.Typerep (STR ''fun'') [T1, T2],
bulwahn@40899
   136
                       Typerep.Typerep (STR ''fun'') [T1, Typerep.Typerep (STR ''fun'') [T2, Typerep.Typerep (STR ''fun'') [T1, T2]]]]))
bulwahn@40899
   137
               (gt ())) (at ())) (bt ())))) (i - 1) d) d) d
bulwahn@40899
   138
  else (if i > 0 then
bulwahn@40899
   139
    full_small (%(b, t). f (%_. b, %_. Code_Evaluation.Abs (STR ''x'') (Typerep.typerep TYPE('a)) (t ()))) d else None))"
bulwahn@40639
   140
bulwahn@40639
   141
definition full_small_fun :: "(('a => 'b) * (unit => term) => term list option) => code_numeral => term list option"
bulwahn@40639
   142
where
bulwahn@40639
   143
  "full_small_fun f d = full_small_fun' f d d" 
bulwahn@40639
   144
bulwahn@40639
   145
instance ..
bulwahn@40639
   146
bulwahn@40639
   147
end
bulwahn@40639
   148
bulwahn@41085
   149
subsubsection {* A smarter enumeration scheme for functions over finite datatypes *}
bulwahn@41085
   150
bulwahn@41085
   151
bulwahn@41085
   152
class check_all = enum + term_of +
bulwahn@41177
   153
  fixes check_all :: "('a * (unit \<Rightarrow> term) \<Rightarrow> term list option) \<Rightarrow> term list option"
bulwahn@41177
   154
  fixes enum_term_of :: "'a itself \<Rightarrow> unit \<Rightarrow> term list"
bulwahn@41177
   155
  
bulwahn@41085
   156
fun check_all_n_lists :: "(('a :: check_all) list * (unit \<Rightarrow> term list) \<Rightarrow> term list option) \<Rightarrow> code_numeral \<Rightarrow> term list option"
bulwahn@41085
   157
where
bulwahn@41085
   158
  "check_all_n_lists f n =
bulwahn@41085
   159
     (if n = 0 then f ([], (%_. [])) else check_all (%(x, xt). check_all_n_lists (%(xs, xst). f ((x # xs), (%_. (xt () # xst ())))) (n - 1)))"
bulwahn@41085
   160
bulwahn@41177
   161
definition mk_map_term :: " (unit \<Rightarrow> typerep) \<Rightarrow> (unit \<Rightarrow> typerep) \<Rightarrow> (unit \<Rightarrow> term list) \<Rightarrow> (unit \<Rightarrow> term list) \<Rightarrow> unit \<Rightarrow> term"
bulwahn@41085
   162
where
bulwahn@41177
   163
  "mk_map_term T1 T2 domm rng =
bulwahn@41177
   164
     (%_. let T1 = T1 ();
bulwahn@41085
   165
              T2 = T2 ();
bulwahn@41085
   166
              update_term = (%g (a, b).
bulwahn@41085
   167
                Code_Evaluation.App (Code_Evaluation.App (Code_Evaluation.App
bulwahn@41085
   168
                 (Code_Evaluation.Const (STR ''Fun.fun_upd'')
bulwahn@41085
   169
                   (Typerep.Typerep (STR ''fun'') [Typerep.Typerep (STR ''fun'') [T1, T2],
bulwahn@41177
   170
                      Typerep.Typerep (STR ''fun'') [T1,
bulwahn@41177
   171
                        Typerep.Typerep (STR ''fun'') [T2, Typerep.Typerep (STR ''fun'') [T1, T2]]]]))
bulwahn@41177
   172
                        g) a) b)
bulwahn@41085
   173
          in
bulwahn@41177
   174
             List.foldl update_term (Code_Evaluation.Abs (STR ''x'') T1 (Code_Evaluation.Const (STR ''HOL.undefined'') T2)) (zip (domm ()) (rng ())))"
bulwahn@41177
   175
bulwahn@41177
   176
instantiation "fun" :: ("{equal, check_all}", check_all) check_all
bulwahn@41177
   177
begin
bulwahn@41085
   178
bulwahn@41085
   179
definition
bulwahn@41177
   180
  "check_all f =
bulwahn@41177
   181
    (let
bulwahn@41177
   182
      mk_term = mk_map_term (%_. Typerep.typerep (TYPE('a))) (%_. Typerep.typerep (TYPE('b))) (enum_term_of (TYPE('a)));
bulwahn@41177
   183
      enum = (Enum.enum :: 'a list)
bulwahn@41177
   184
    in check_all_n_lists (\<lambda>(ys, yst). f (the o map_of (zip enum ys), mk_term yst)) (Code_Numeral.of_nat (length enum)))"
bulwahn@41085
   185
bulwahn@41177
   186
definition enum_term_of_fun :: "('a => 'b) itself => unit => term list"
bulwahn@41177
   187
where
bulwahn@41177
   188
  "enum_term_of_fun = (%_ _. let
bulwahn@41177
   189
    enum_term_of_a = enum_term_of (TYPE('a));
bulwahn@41177
   190
    mk_term = mk_map_term (%_. Typerep.typerep (TYPE('a))) (%_. Typerep.typerep (TYPE('b))) enum_term_of_a
bulwahn@41177
   191
  in map (%ys. mk_term (%_. ys) ()) (Enum.n_lists (length (enum_term_of_a ())) (enum_term_of (TYPE('b)) ())))"
bulwahn@41177
   192
 
bulwahn@41085
   193
instance ..
bulwahn@41085
   194
bulwahn@41085
   195
end
bulwahn@41085
   196
bulwahn@41105
   197
bulwahn@41105
   198
instantiation unit :: check_all
bulwahn@41105
   199
begin
bulwahn@41105
   200
bulwahn@41105
   201
definition
bulwahn@41105
   202
  "check_all f = f (Code_Evaluation.valtermify ())"
bulwahn@41105
   203
bulwahn@41177
   204
definition enum_term_of_unit :: "unit itself => unit => term list"
bulwahn@41177
   205
where
bulwahn@41177
   206
  "enum_term_of_unit = (%_ _. [Code_Evaluation.term_of ()])"
bulwahn@41177
   207
bulwahn@41105
   208
instance ..
bulwahn@41105
   209
bulwahn@41105
   210
end
bulwahn@41105
   211
bulwahn@41105
   212
bulwahn@41085
   213
instantiation bool :: check_all
bulwahn@41085
   214
begin
bulwahn@41085
   215
bulwahn@41085
   216
definition
bulwahn@41085
   217
  "check_all f = (case f (Code_Evaluation.valtermify False) of Some x' \<Rightarrow> Some x' | None \<Rightarrow> f (Code_Evaluation.valtermify True))"
bulwahn@41085
   218
bulwahn@41177
   219
definition enum_term_of_bool :: "bool itself => unit => term list"
bulwahn@41177
   220
where
bulwahn@41177
   221
  "enum_term_of_bool = (%_ _. map Code_Evaluation.term_of (Enum.enum :: bool list))"
bulwahn@41177
   222
bulwahn@41085
   223
instance ..
bulwahn@41085
   224
bulwahn@41085
   225
end
bulwahn@41085
   226
bulwahn@41105
   227
bulwahn@41085
   228
instantiation prod :: (check_all, check_all) check_all
bulwahn@41085
   229
begin
bulwahn@41085
   230
bulwahn@41085
   231
definition
bulwahn@41085
   232
  "check_all f = check_all (%(x, t1). check_all (%(y, t2). f ((x, y), %_. Code_Evaluation.App (Code_Evaluation.App (Code_Evaluation.term_of (Pair :: 'a => 'b => ('a * 'b))) (t1 ())) (t2 ()))))"
bulwahn@41085
   233
bulwahn@41177
   234
definition enum_term_of_prod :: "('a * 'b) itself => unit => term list"
bulwahn@41177
   235
where
bulwahn@41177
   236
  "enum_term_of_prod = (%_ _. map (%(x, y). Code_Evaluation.App (Code_Evaluation.App (Code_Evaluation.term_of (Pair :: 'a => 'b => ('a * 'b))) x) y) (Enum.product (enum_term_of (TYPE('a)) ()) (enum_term_of (TYPE('b)) ())))"
bulwahn@41177
   237
bulwahn@41085
   238
instance ..
bulwahn@41085
   239
bulwahn@41085
   240
end
bulwahn@41085
   241
bulwahn@41105
   242
bulwahn@41105
   243
instantiation sum :: (check_all, check_all) check_all
bulwahn@41105
   244
begin
bulwahn@41105
   245
bulwahn@41105
   246
definition
bulwahn@41105
   247
  "check_all f = (case check_all (%(a, t). f (Inl a, %_. Code_Evaluation.App (Code_Evaluation.term_of (Inl :: 'a => 'a + 'b)) (t ()))) of Some x' => Some x'
bulwahn@41105
   248
             | None => check_all (%(b, t). f (Inr b, %_. Code_Evaluation.App (Code_Evaluation.term_of (Inr :: 'b => 'a + 'b)) (t ()))))"
bulwahn@41105
   249
bulwahn@41177
   250
definition enum_term_of_sum :: "('a + 'b) itself => unit => term list"
bulwahn@41177
   251
where
bulwahn@41177
   252
  "enum_term_of_sum = (%_ _. map (Code_Evaluation.App (Code_Evaluation.term_of (Inl :: 'a => ('a + 'b)))) (enum_term_of (TYPE('a)) ()) @
bulwahn@41177
   253
     map (Code_Evaluation.App (Code_Evaluation.term_of (Inr :: 'b => ('a + 'b)))) (enum_term_of (TYPE('b)) ()))"
bulwahn@41177
   254
bulwahn@41105
   255
instance ..
bulwahn@41105
   256
bulwahn@41105
   257
end
bulwahn@41105
   258
bulwahn@41105
   259
instantiation nibble :: check_all
bulwahn@41105
   260
begin
bulwahn@41105
   261
bulwahn@41105
   262
definition
bulwahn@41105
   263
  "check_all f =
bulwahn@41105
   264
    f (Code_Evaluation.valtermify Nibble0) orelse
bulwahn@41105
   265
    f (Code_Evaluation.valtermify Nibble1) orelse
bulwahn@41105
   266
    f (Code_Evaluation.valtermify Nibble2) orelse
bulwahn@41105
   267
    f (Code_Evaluation.valtermify Nibble3) orelse
bulwahn@41105
   268
    f (Code_Evaluation.valtermify Nibble4) orelse
bulwahn@41105
   269
    f (Code_Evaluation.valtermify Nibble5) orelse
bulwahn@41105
   270
    f (Code_Evaluation.valtermify Nibble6) orelse
bulwahn@41105
   271
    f (Code_Evaluation.valtermify Nibble7) orelse
bulwahn@41105
   272
    f (Code_Evaluation.valtermify Nibble8) orelse
bulwahn@41105
   273
    f (Code_Evaluation.valtermify Nibble9) orelse
bulwahn@41105
   274
    f (Code_Evaluation.valtermify NibbleA) orelse
bulwahn@41105
   275
    f (Code_Evaluation.valtermify NibbleB) orelse
bulwahn@41105
   276
    f (Code_Evaluation.valtermify NibbleC) orelse
bulwahn@41105
   277
    f (Code_Evaluation.valtermify NibbleD) orelse
bulwahn@41105
   278
    f (Code_Evaluation.valtermify NibbleE) orelse
bulwahn@41105
   279
    f (Code_Evaluation.valtermify NibbleF)"
bulwahn@41105
   280
bulwahn@41177
   281
definition enum_term_of_nibble :: "nibble itself => unit => term list"
bulwahn@41177
   282
where
bulwahn@41177
   283
  "enum_term_of_nibble = (%_ _. map Code_Evaluation.term_of (Enum.enum :: nibble list))"
bulwahn@41177
   284
bulwahn@41105
   285
instance ..
bulwahn@41105
   286
bulwahn@41105
   287
end
bulwahn@41105
   288
bulwahn@41105
   289
bulwahn@41105
   290
instantiation char :: check_all
bulwahn@41105
   291
begin
bulwahn@41105
   292
bulwahn@41105
   293
definition
bulwahn@41105
   294
  "check_all f = check_all (%(x, t1). check_all (%(y, t2). f (Char x y, %_. Code_Evaluation.App (Code_Evaluation.App (Code_Evaluation.term_of Char) (t1 ())) (t2 ()))))"
bulwahn@41105
   295
bulwahn@41177
   296
definition enum_term_of_char :: "char itself => unit => term list"
bulwahn@41177
   297
where
bulwahn@41177
   298
  "enum_term_of_char = (%_ _. map Code_Evaluation.term_of (Enum.enum :: char list))"
bulwahn@41177
   299
bulwahn@41105
   300
instance ..
bulwahn@41105
   301
bulwahn@41105
   302
end
bulwahn@41105
   303
bulwahn@41105
   304
bulwahn@41105
   305
instantiation option :: (check_all) check_all
bulwahn@41105
   306
begin
bulwahn@41105
   307
bulwahn@41105
   308
definition
bulwahn@41178
   309
  "check_all f = f (Code_Evaluation.valtermify (None :: 'a option)) orelse check_all (%(x, t). f (Some x, %_. Code_Evaluation.App
bulwahn@41178
   310
    (Code_Evaluation.Const (STR ''Option.option.Some'')
bulwahn@41178
   311
      (Typerep.Typerep (STR ''fun'') [Typerep.typerep TYPE('a),  Typerep.Typerep (STR ''Option.option'') [Typerep.typerep TYPE('a)]])) (t ())))"
bulwahn@41105
   312
bulwahn@41177
   313
definition enum_term_of_option :: "'a option itself => unit => term list"
bulwahn@41177
   314
where
bulwahn@41177
   315
  "enum_term_of_option = (% _ _. (Code_Evaluation.term_of (None :: 'a option)) # (map (Code_Evaluation.App (Code_Evaluation.term_of (Some :: 'a => 'a option))) (enum_term_of (TYPE('a)) ())))"
bulwahn@41177
   316
bulwahn@41105
   317
instance ..
bulwahn@41105
   318
bulwahn@41105
   319
end
bulwahn@41105
   320
bulwahn@41105
   321
bulwahn@41085
   322
instantiation Enum.finite_1 :: check_all
bulwahn@41085
   323
begin
bulwahn@41085
   324
bulwahn@41085
   325
definition
bulwahn@41085
   326
  "check_all f = f (Code_Evaluation.valtermify Enum.finite_1.a\<^isub>1)"
bulwahn@41085
   327
bulwahn@41177
   328
definition enum_term_of_finite_1 :: "Enum.finite_1 itself => unit => term list"
bulwahn@41177
   329
where
bulwahn@41177
   330
  "enum_term_of_finite_1 = (%_ _. [Code_Evaluation.term_of Enum.finite_1.a\<^isub>1])"
bulwahn@41177
   331
bulwahn@41085
   332
instance ..
bulwahn@41085
   333
bulwahn@41085
   334
end
bulwahn@41085
   335
bulwahn@41085
   336
instantiation Enum.finite_2 :: check_all
bulwahn@41085
   337
begin
bulwahn@41085
   338
bulwahn@41085
   339
definition
bulwahn@41085
   340
  "check_all f = (case f (Code_Evaluation.valtermify Enum.finite_2.a\<^isub>1) of Some x' \<Rightarrow> Some x' | None \<Rightarrow> f (Code_Evaluation.valtermify Enum.finite_2.a\<^isub>2))"
bulwahn@41085
   341
bulwahn@41177
   342
definition enum_term_of_finite_2 :: "Enum.finite_2 itself => unit => term list"
bulwahn@41177
   343
where
bulwahn@41177
   344
  "enum_term_of_finite_2 = (%_ _. map Code_Evaluation.term_of (Enum.enum :: Enum.finite_2 list))"
bulwahn@41177
   345
bulwahn@41085
   346
instance ..
bulwahn@41085
   347
bulwahn@41085
   348
end
bulwahn@41085
   349
bulwahn@41085
   350
instantiation Enum.finite_3 :: check_all
bulwahn@41085
   351
begin
bulwahn@41085
   352
bulwahn@41085
   353
definition
bulwahn@41085
   354
  "check_all f = (case f (Code_Evaluation.valtermify Enum.finite_3.a\<^isub>1) of Some x' \<Rightarrow> Some x' | None \<Rightarrow> (case f (Code_Evaluation.valtermify Enum.finite_3.a\<^isub>2) of Some x' \<Rightarrow> Some x' | None \<Rightarrow> f (Code_Evaluation.valtermify Enum.finite_3.a\<^isub>3)))"
bulwahn@41085
   355
bulwahn@41177
   356
definition enum_term_of_finite_3 :: "Enum.finite_3 itself => unit => term list"
bulwahn@41177
   357
where
bulwahn@41177
   358
  "enum_term_of_finite_3 = (%_ _. map Code_Evaluation.term_of (Enum.enum :: Enum.finite_3 list))"
bulwahn@41177
   359
bulwahn@41085
   360
instance ..
bulwahn@41085
   361
bulwahn@41085
   362
end
bulwahn@41085
   363
bulwahn@41085
   364
bulwahn@41085
   365
huffman@40620
   366
subsection {* Defining combinators for any first-order data type *}
bulwahn@40420
   367
bulwahn@40420
   368
definition catch_match :: "term list option => term list option => term list option"
bulwahn@40420
   369
where
bulwahn@40420
   370
  [code del]: "catch_match t1 t2 = (SOME t. t = t1 \<or> t = t2)"
bulwahn@40420
   371
bulwahn@40420
   372
code_const catch_match 
bulwahn@40420
   373
  (SML "(_) handle Match => _")
bulwahn@40420
   374
bulwahn@40420
   375
use "Tools/smallvalue_generators.ML"
bulwahn@40420
   376
bulwahn@40420
   377
setup {* Smallvalue_Generators.setup *}
bulwahn@40420
   378
bulwahn@40915
   379
declare [[quickcheck_tester = exhaustive]]
bulwahn@40915
   380
bulwahn@40899
   381
hide_fact orelse_def catch_match_def
bulwahn@41105
   382
no_notation orelse (infixr "orelse" 55)
bulwahn@41085
   383
hide_const (open) orelse catch_match mk_map_term check_all_n_lists
bulwahn@40420
   384
bulwahn@40420
   385
end