src/HOL/Tools/Nitpick/nitpick_rep.ML
author blanchet
Wed, 20 Jan 2010 10:38:06 +0100
changeset 34923 c4f04bee79f3
parent 34120 c4988215a691
child 34969 7b8c366e34a2
permissions -rw-r--r--
some work on Nitpick's support for quotient types;
quotient types are not yet in Isabelle, so for now I hardcoded "IntEx.my_int"
blanchet@33982
     1
(*  Title:      HOL/Tools/Nitpick/nitpick_rep.ML
blanchet@33192
     2
    Author:     Jasmin Blanchette, TU Muenchen
blanchet@33192
     3
    Copyright   2008, 2009
blanchet@33192
     4
blanchet@33192
     5
Kodkod representations of Nitpick terms.
blanchet@33192
     6
*)
blanchet@33192
     7
blanchet@33192
     8
signature NITPICK_REP =
blanchet@33192
     9
sig
blanchet@33224
    10
  type polarity = Nitpick_Util.polarity
blanchet@33224
    11
  type scope = Nitpick_Scope.scope
blanchet@33192
    12
blanchet@33192
    13
  datatype rep =
blanchet@33192
    14
    Any |
blanchet@33192
    15
    Formula of polarity |
blanchet@33192
    16
    Unit |
blanchet@33192
    17
    Atom of int * int |
blanchet@33192
    18
    Struct of rep list |
blanchet@33192
    19
    Vect of int * rep |
blanchet@33192
    20
    Func of rep * rep |
blanchet@33192
    21
    Opt of rep
blanchet@33192
    22
blanchet@33192
    23
  exception REP of string * rep list
blanchet@33192
    24
blanchet@33192
    25
  val string_for_polarity : polarity -> string
blanchet@33192
    26
  val string_for_rep : rep -> string
blanchet@33192
    27
  val is_Func : rep -> bool
blanchet@33192
    28
  val is_Opt : rep -> bool
blanchet@33192
    29
  val is_opt_rep : rep -> bool
blanchet@33192
    30
  val flip_rep_polarity : rep -> rep
blanchet@33192
    31
  val card_of_rep : rep -> int
blanchet@33192
    32
  val arity_of_rep : rep -> int
blanchet@33192
    33
  val min_univ_card_of_rep : rep -> int
blanchet@33192
    34
  val is_one_rep : rep -> bool
blanchet@33192
    35
  val is_lone_rep : rep -> bool
blanchet@33192
    36
  val dest_Func : rep -> rep * rep
blanchet@33192
    37
  val smart_range_rep : int Typtab.table -> typ -> (unit -> int) -> rep -> rep
blanchet@33192
    38
  val binder_reps : rep -> rep list
blanchet@33192
    39
  val body_rep : rep -> rep
blanchet@33192
    40
  val one_rep : int Typtab.table -> typ -> rep -> rep
blanchet@33192
    41
  val optable_rep : int Typtab.table -> typ -> rep -> rep
blanchet@33192
    42
  val opt_rep : int Typtab.table -> typ -> rep -> rep
blanchet@33192
    43
  val unopt_rep : rep -> rep
blanchet@33192
    44
  val min_rep : rep -> rep -> rep
blanchet@33192
    45
  val min_reps : rep list -> rep list -> rep list
blanchet@33192
    46
  val card_of_domain_from_rep : int -> rep -> int
blanchet@33192
    47
  val rep_to_binary_rel_rep : int Typtab.table -> typ -> rep -> rep
blanchet@33192
    48
  val best_one_rep_for_type : scope -> typ -> rep
blanchet@33192
    49
  val best_opt_set_rep_for_type : scope -> typ -> rep
blanchet@33192
    50
  val best_non_opt_set_rep_for_type : scope -> typ -> rep
blanchet@33192
    51
  val best_set_rep_for_type : scope -> typ -> rep
blanchet@33192
    52
  val best_non_opt_symmetric_reps_for_fun_type : scope -> typ -> rep * rep
blanchet@33192
    53
  val atom_schema_of_rep : rep -> (int * int) list
blanchet@33192
    54
  val atom_schema_of_reps : rep list -> (int * int) list
blanchet@33192
    55
  val type_schema_of_rep : typ -> rep -> typ list
blanchet@33192
    56
  val type_schema_of_reps : typ list -> rep list -> typ list
blanchet@33192
    57
  val all_combinations_for_rep : rep -> int list list
blanchet@33192
    58
  val all_combinations_for_reps : rep list -> int list list
blanchet@33192
    59
end;
blanchet@33192
    60
blanchet@33224
    61
structure Nitpick_Rep : NITPICK_REP =
blanchet@33192
    62
struct
blanchet@33192
    63
blanchet@33224
    64
open Nitpick_Util
blanchet@33224
    65
open Nitpick_HOL
blanchet@33224
    66
open Nitpick_Scope
blanchet@33192
    67
blanchet@33192
    68
datatype rep =
blanchet@33192
    69
  Any |
blanchet@33192
    70
  Formula of polarity |
blanchet@33192
    71
  Unit |
blanchet@33192
    72
  Atom of int * int |
blanchet@33192
    73
  Struct of rep list |
blanchet@33192
    74
  Vect of int * rep |
blanchet@33192
    75
  Func of rep * rep |
blanchet@33192
    76
  Opt of rep
blanchet@33192
    77
blanchet@33192
    78
exception REP of string * rep list
blanchet@33192
    79
blanchet@33192
    80
(* polarity -> string *)
blanchet@33192
    81
fun string_for_polarity Pos = "+"
blanchet@33192
    82
  | string_for_polarity Neg = "-"
blanchet@33192
    83
  | string_for_polarity Neut = "="
blanchet@33192
    84
blanchet@33192
    85
(* rep -> string *)
blanchet@33192
    86
fun atomic_string_for_rep rep =
blanchet@33192
    87
  let val s = string_for_rep rep in
blanchet@33192
    88
    if String.isPrefix "[" s orelse not (is_substring_of " " s) then s
blanchet@33192
    89
    else "(" ^ s ^ ")"
blanchet@33192
    90
  end
blanchet@33192
    91
(* rep -> string *)
blanchet@33192
    92
and string_for_rep Any = "X"
blanchet@33192
    93
  | string_for_rep (Formula polar) = "F" ^ string_for_polarity polar
blanchet@33192
    94
  | string_for_rep Unit = "U"
blanchet@33192
    95
  | string_for_rep (Atom (k, j0)) =
blanchet@33192
    96
    "A" ^ string_of_int k ^ (if j0 = 0 then "" else "@" ^ string_of_int j0)
blanchet@33192
    97
  | string_for_rep (Struct rs) = "[" ^ commas (map string_for_rep rs) ^ "]"
blanchet@33192
    98
  | string_for_rep (Vect (k, R)) =
blanchet@33192
    99
    string_of_int k ^ " x " ^ atomic_string_for_rep R
blanchet@33192
   100
  | string_for_rep (Func (R1, R2)) =
blanchet@33192
   101
    atomic_string_for_rep R1 ^ " => " ^ string_for_rep R2
blanchet@33192
   102
  | string_for_rep (Opt R) = atomic_string_for_rep R ^ "?"
blanchet@33192
   103
blanchet@33192
   104
(* rep -> bool *)
blanchet@33192
   105
fun is_Func (Func _) = true
blanchet@33192
   106
  | is_Func _ = false
blanchet@33192
   107
fun is_Opt (Opt _) = true
blanchet@33192
   108
  | is_Opt _ = false
blanchet@33192
   109
fun is_opt_rep (Func (_, R2)) = is_opt_rep R2
blanchet@33192
   110
  | is_opt_rep (Opt _) = true
blanchet@33192
   111
  | is_opt_rep _ = false
blanchet@33192
   112
blanchet@33192
   113
(* rep -> int *)
blanchet@33224
   114
fun card_of_rep Any = raise REP ("Nitpick_Rep.card_of_rep", [Any])
blanchet@33192
   115
  | card_of_rep (Formula _) = 2
blanchet@33192
   116
  | card_of_rep Unit = 1
blanchet@33192
   117
  | card_of_rep (Atom (k, _)) = k
blanchet@33192
   118
  | card_of_rep (Struct rs) = Integer.prod (map card_of_rep rs)
blanchet@33192
   119
  | card_of_rep (Vect (k, R)) = reasonable_power (card_of_rep R) k
blanchet@33192
   120
  | card_of_rep (Func (R1, R2)) =
blanchet@33192
   121
    reasonable_power (card_of_rep R2) (card_of_rep R1)
blanchet@33192
   122
  | card_of_rep (Opt R) = card_of_rep R
blanchet@33224
   123
fun arity_of_rep Any = raise REP ("Nitpick_Rep.arity_of_rep", [Any])
blanchet@33192
   124
  | arity_of_rep (Formula _) = 0
blanchet@33192
   125
  | arity_of_rep Unit = 0
blanchet@33192
   126
  | arity_of_rep (Atom _) = 1
blanchet@33192
   127
  | arity_of_rep (Struct Rs) = Integer.sum (map arity_of_rep Rs)
blanchet@33192
   128
  | arity_of_rep (Vect (k, R)) = k * arity_of_rep R
blanchet@33192
   129
  | arity_of_rep (Func (R1, R2)) = arity_of_rep R1 + arity_of_rep R2
blanchet@33192
   130
  | arity_of_rep (Opt R) = arity_of_rep R
blanchet@33192
   131
fun min_univ_card_of_rep Any =
blanchet@33224
   132
    raise REP ("Nitpick_Rep.min_univ_card_of_rep", [Any])
blanchet@33192
   133
  | min_univ_card_of_rep (Formula _) = 0
blanchet@33192
   134
  | min_univ_card_of_rep Unit = 0
blanchet@33192
   135
  | min_univ_card_of_rep (Atom (k, j0)) = k + j0 + 1
blanchet@33192
   136
  | min_univ_card_of_rep (Struct Rs) =
blanchet@33192
   137
    fold Integer.max (map min_univ_card_of_rep Rs) 0
blanchet@33192
   138
  | min_univ_card_of_rep (Vect (_, R)) = min_univ_card_of_rep R
blanchet@33192
   139
  | min_univ_card_of_rep (Func (R1, R2)) =
blanchet@33192
   140
    Int.max (min_univ_card_of_rep R1, min_univ_card_of_rep R2)
blanchet@33192
   141
  | min_univ_card_of_rep (Opt R) = min_univ_card_of_rep R
blanchet@33192
   142
blanchet@33192
   143
(* rep -> bool *)
blanchet@33192
   144
fun is_one_rep Unit = true
blanchet@33192
   145
  | is_one_rep (Atom _) = true
blanchet@33192
   146
  | is_one_rep (Struct _) = true
blanchet@33192
   147
  | is_one_rep (Vect _) = true
blanchet@33192
   148
  | is_one_rep _ = false
blanchet@33192
   149
fun is_lone_rep (Opt R) = is_one_rep R
blanchet@33192
   150
  | is_lone_rep R = is_one_rep R
blanchet@33192
   151
blanchet@33192
   152
(* rep -> rep * rep *)
blanchet@33192
   153
fun dest_Func (Func z) = z
blanchet@33224
   154
  | dest_Func R = raise REP ("Nitpick_Rep.dest_Func", [R])
blanchet@33192
   155
(* int Typtab.table -> typ -> (unit -> int) -> rep -> rep *)
blanchet@33192
   156
fun smart_range_rep _ _ _ Unit = Unit
blanchet@33192
   157
  | smart_range_rep _ _ _ (Vect (_, R)) = R
blanchet@33192
   158
  | smart_range_rep _ _ _ (Func (_, R2)) = R2
blanchet@33192
   159
  | smart_range_rep ofs T ran_card (Opt R) =
blanchet@33192
   160
    Opt (smart_range_rep ofs T ran_card R)
blanchet@33192
   161
  | smart_range_rep ofs (Type ("fun", [_, T2])) _ (Atom (1, _)) =
blanchet@33192
   162
    Atom (1, offset_of_type ofs T2)
blanchet@33192
   163
  | smart_range_rep ofs (Type ("fun", [_, T2])) ran_card (Atom _) =
blanchet@33192
   164
    Atom (ran_card (), offset_of_type ofs T2)
blanchet@33224
   165
  | smart_range_rep _ _ _ R = raise REP ("Nitpick_Rep.smart_range_rep", [R])
blanchet@33192
   166
blanchet@33192
   167
(* rep -> rep list *)
blanchet@33192
   168
fun binder_reps (Func (R1, R2)) = R1 :: binder_reps R2
blanchet@33192
   169
  | binder_reps R = []
blanchet@33192
   170
(* rep -> rep *)
blanchet@33192
   171
fun body_rep (Func (_, R2)) = body_rep R2
blanchet@33192
   172
  | body_rep R = R
blanchet@33192
   173
blanchet@33192
   174
(* rep -> rep *)
blanchet@33192
   175
fun flip_rep_polarity (Formula polar) = Formula (flip_polarity polar)
blanchet@33192
   176
  | flip_rep_polarity (Func (R1, R2)) = Func (R1, flip_rep_polarity R2)
blanchet@33192
   177
  | flip_rep_polarity R = R
blanchet@33192
   178
blanchet@33192
   179
(* int Typtab.table -> rep -> rep *)
blanchet@33224
   180
fun one_rep _ _ Any = raise REP ("Nitpick_Rep.one_rep", [Any])
blanchet@33192
   181
  | one_rep _ _ (Atom x) = Atom x
blanchet@33192
   182
  | one_rep _ _ (Struct Rs) = Struct Rs
blanchet@33192
   183
  | one_rep _ _ (Vect z) = Vect z
blanchet@33192
   184
  | one_rep ofs T (Opt R) = one_rep ofs T R
blanchet@33192
   185
  | one_rep ofs T R = Atom (card_of_rep R, offset_of_type ofs T)
blanchet@33192
   186
fun optable_rep ofs (Type ("fun", [_, T2])) (Func (R1, R2)) =
blanchet@33192
   187
    Func (R1, optable_rep ofs T2 R2)
blanchet@33192
   188
  | optable_rep ofs T R = one_rep ofs T R
blanchet@33192
   189
fun opt_rep ofs (Type ("fun", [_, T2])) (Func (R1, R2)) =
blanchet@33192
   190
    Func (R1, opt_rep ofs T2 R2)
blanchet@33192
   191
  | opt_rep ofs T R = Opt (optable_rep ofs T R)
blanchet@33192
   192
(* rep -> rep *)
blanchet@33192
   193
fun unopt_rep (Func (R1, R2)) = Func (R1, unopt_rep R2)
blanchet@33192
   194
  | unopt_rep (Opt R) = R
blanchet@33192
   195
  | unopt_rep R = R
blanchet@33192
   196
blanchet@33192
   197
(* polarity -> polarity -> polarity *)
blanchet@33192
   198
fun min_polarity polar1 polar2 =
blanchet@33192
   199
  if polar1 = polar2 then
blanchet@33192
   200
    polar1
blanchet@33192
   201
  else if polar1 = Neut then
blanchet@33192
   202
    polar2
blanchet@33192
   203
  else if polar2 = Neut then
blanchet@33192
   204
    polar1
blanchet@33192
   205
  else
blanchet@33224
   206
    raise ARG ("Nitpick_Rep.min_polarity",
blanchet@33192
   207
               commas (map (quote o string_for_polarity) [polar1, polar2]))
blanchet@33192
   208
blanchet@33192
   209
(* It's important that Func is before Vect, because if the range is Opt we
blanchet@33192
   210
   could lose information by converting a Func to a Vect. *)
blanchet@33192
   211
(* rep -> rep -> rep *)
blanchet@33192
   212
fun min_rep (Opt R1) (Opt R2) = Opt (min_rep R1 R2)
blanchet@33192
   213
  | min_rep (Opt R) _ = Opt R
blanchet@33192
   214
  | min_rep _ (Opt R) = Opt R
blanchet@33192
   215
  | min_rep (Formula polar1) (Formula polar2) =
blanchet@33192
   216
    Formula (min_polarity polar1 polar2)
blanchet@33192
   217
  | min_rep (Formula polar) _ = Formula polar
blanchet@33192
   218
  | min_rep _ (Formula polar) = Formula polar
blanchet@33192
   219
  | min_rep Unit _ = Unit
blanchet@33192
   220
  | min_rep _ Unit = Unit
blanchet@33192
   221
  | min_rep (Atom x) _ = Atom x
blanchet@33192
   222
  | min_rep _ (Atom x) = Atom x
blanchet@33192
   223
  | min_rep (Struct Rs1) (Struct Rs2) = Struct (min_reps Rs1 Rs2)
blanchet@33192
   224
  | min_rep (Struct Rs) _ = Struct Rs
blanchet@33192
   225
  | min_rep _ (Struct Rs) = Struct Rs
blanchet@33192
   226
  | min_rep (R1 as Func (R11, R12)) (R2 as Func (R21, R22)) =
blanchet@33192
   227
    (case pairself is_opt_rep (R12, R22) of
blanchet@33192
   228
       (true, false) => R1
blanchet@33192
   229
     | (false, true) => R2
blanchet@33192
   230
     | _ => if R11 = R21 then Func (R11, min_rep R12 R22)
blanchet@33192
   231
            else if min_rep R11 R21 = R11 then R1
blanchet@33192
   232
            else R2)
blanchet@33192
   233
  | min_rep (Func z) _ = Func z
blanchet@33192
   234
  | min_rep _ (Func z) = Func z
blanchet@33192
   235
  | min_rep (Vect (k1, R1)) (Vect (k2, R2)) =
blanchet@33192
   236
    if k1 < k2 then Vect (k1, R1)
blanchet@33192
   237
    else if k1 > k2 then Vect (k2, R2)
blanchet@33192
   238
    else Vect (k1, min_rep R1 R2)
blanchet@33224
   239
  | min_rep R1 R2 = raise REP ("Nitpick_Rep.min_rep", [R1, R2])
blanchet@33192
   240
(* rep list -> rep list -> rep list *)
blanchet@33192
   241
and min_reps [] _ = []
blanchet@33192
   242
  | min_reps _ [] = []
blanchet@33192
   243
  | min_reps (R1 :: Rs1) (R2 :: Rs2) =
blanchet@33192
   244
    if R1 = R2 then R1 :: min_reps Rs1 Rs2
blanchet@33192
   245
    else if min_rep R1 R2 = R1 then R1 :: Rs1
blanchet@33192
   246
    else R2 :: Rs2
blanchet@33192
   247
blanchet@33192
   248
(* int -> rep -> int *)
blanchet@33192
   249
fun card_of_domain_from_rep ran_card R =
blanchet@33192
   250
  case R of
blanchet@33192
   251
    Unit => 1
blanchet@33192
   252
  | Atom (k, _) => exact_log ran_card k
blanchet@33192
   253
  | Vect (k, _) => k
blanchet@33192
   254
  | Func (R1, _) => card_of_rep R1
blanchet@33192
   255
  | Opt R => card_of_domain_from_rep ran_card R
blanchet@33224
   256
  | _ => raise REP ("Nitpick_Rep.card_of_domain_from_rep", [R])
blanchet@33192
   257
blanchet@33192
   258
(* int Typtab.table -> typ -> rep -> rep *)
blanchet@33192
   259
fun rep_to_binary_rel_rep ofs T R =
blanchet@33192
   260
  let
blanchet@33192
   261
    val k = exact_root 2 (card_of_domain_from_rep 2 R)
blanchet@33192
   262
    val j0 = offset_of_type ofs (fst (HOLogic.dest_prodT (domain_type T)))
blanchet@33192
   263
  in Func (Struct [Atom (k, j0), Atom (k, j0)], Formula Neut) end
blanchet@33192
   264
blanchet@33192
   265
(* scope -> typ -> rep *)
blanchet@33192
   266
fun best_one_rep_for_type (scope as {card_assigns, ...} : scope)
blanchet@33192
   267
                          (Type ("fun", [T1, T2])) =
blanchet@33192
   268
    (case best_one_rep_for_type scope T2 of
blanchet@33192
   269
       Unit => Unit
blanchet@33192
   270
     | R2 => Vect (card_of_type card_assigns T1, R2))
blanchet@33192
   271
  | best_one_rep_for_type scope (Type ("*", [T1, T2])) =
blanchet@33192
   272
    (case (best_one_rep_for_type scope T1, best_one_rep_for_type scope T2) of
blanchet@33192
   273
       (Unit, Unit) => Unit
blanchet@33192
   274
     | (R1, R2) => Struct [R1, R2])
blanchet@33192
   275
  | best_one_rep_for_type (scope as {card_assigns, datatypes, ofs, ...}) T =
blanchet@33192
   276
    (case card_of_type card_assigns T of
blanchet@34923
   277
       1 => if is_some (datatype_spec datatypes T) orelse
blanchet@34923
   278
               is_fp_iterator_type T then
blanchet@33192
   279
              Atom (1, offset_of_type ofs T)
blanchet@33192
   280
            else
blanchet@33192
   281
              Unit
blanchet@33192
   282
     | k => Atom (k, offset_of_type ofs T))
blanchet@33192
   283
blanchet@33192
   284
(* Datatypes are never represented by Unit, because it would confuse
blanchet@33192
   285
   "nfa_transitions_for_ctor". *)
blanchet@33192
   286
(* scope -> typ -> rep *)
blanchet@33192
   287
fun best_opt_set_rep_for_type scope (Type ("fun", [T1, T2])) =
blanchet@33192
   288
    Func (best_one_rep_for_type scope T1, best_opt_set_rep_for_type scope T2)
blanchet@33192
   289
  | best_opt_set_rep_for_type (scope as {ofs, ...}) T =
blanchet@33192
   290
    opt_rep ofs T (best_one_rep_for_type scope T)
blanchet@33192
   291
fun best_non_opt_set_rep_for_type (scope as {ofs, ...})
blanchet@33192
   292
                                  (Type ("fun", [T1, T2])) =
blanchet@33192
   293
    (case (best_one_rep_for_type scope T1,
blanchet@33192
   294
           best_non_opt_set_rep_for_type scope T2) of
blanchet@33192
   295
       (_, Unit) => Unit
blanchet@33192
   296
     | (Unit, Atom (2, _)) =>
blanchet@33192
   297
       Func (Atom (1, offset_of_type ofs T1), Formula Neut)
blanchet@33192
   298
     | (R1, Atom (2, _)) => Func (R1, Formula Neut)
blanchet@33192
   299
     | z => Func z)
blanchet@33192
   300
  | best_non_opt_set_rep_for_type scope T = best_one_rep_for_type scope T
blanchet@33192
   301
fun best_set_rep_for_type (scope as {datatypes, ...}) T =
blanchet@34120
   302
  (if is_exact_type datatypes T then best_non_opt_set_rep_for_type
blanchet@33192
   303
   else best_opt_set_rep_for_type) scope T
blanchet@33192
   304
fun best_non_opt_symmetric_reps_for_fun_type (scope as {ofs, ...})
blanchet@33192
   305
                                             (Type ("fun", [T1, T2])) =
blanchet@33192
   306
    (optable_rep ofs T1 (best_one_rep_for_type scope T1),
blanchet@33192
   307
     optable_rep ofs T2 (best_one_rep_for_type scope T2))
blanchet@33192
   308
  | best_non_opt_symmetric_reps_for_fun_type _ T =
blanchet@33224
   309
    raise TYPE ("Nitpick_Rep.best_non_opt_symmetric_reps_for_fun_type", [T], [])
blanchet@33192
   310
blanchet@33192
   311
(* rep -> (int * int) list *)
blanchet@33224
   312
fun atom_schema_of_rep Any = raise REP ("Nitpick_Rep.atom_schema_of_rep", [Any])
blanchet@33192
   313
  | atom_schema_of_rep (Formula _) = []
blanchet@33192
   314
  | atom_schema_of_rep Unit = []
blanchet@33192
   315
  | atom_schema_of_rep (Atom x) = [x]
blanchet@33192
   316
  | atom_schema_of_rep (Struct Rs) = atom_schema_of_reps Rs
blanchet@33192
   317
  | atom_schema_of_rep (Vect (k, R)) = replicate_list k (atom_schema_of_rep R)
blanchet@33192
   318
  | atom_schema_of_rep (Func (R1, R2)) =
blanchet@33192
   319
    atom_schema_of_rep R1 @ atom_schema_of_rep R2
blanchet@33192
   320
  | atom_schema_of_rep (Opt R) = atom_schema_of_rep R
blanchet@33192
   321
(* rep list -> (int * int) list *)
blanchet@33192
   322
and atom_schema_of_reps Rs = maps atom_schema_of_rep Rs
blanchet@33192
   323
blanchet@33192
   324
(* typ -> rep -> typ list *)
blanchet@33192
   325
fun type_schema_of_rep _ (Formula _) = []
blanchet@33192
   326
  | type_schema_of_rep _ Unit = []
blanchet@33192
   327
  | type_schema_of_rep T (Atom _) = [T]
blanchet@33192
   328
  | type_schema_of_rep (Type ("*", [T1, T2])) (Struct [R1, R2]) =
blanchet@33192
   329
    type_schema_of_reps [T1, T2] [R1, R2]
blanchet@33192
   330
  | type_schema_of_rep (Type ("fun", [_, T2])) (Vect (k, R)) =
blanchet@33192
   331
    replicate_list k (type_schema_of_rep T2 R)
blanchet@33192
   332
  | type_schema_of_rep (Type ("fun", [T1, T2])) (Func (R1, R2)) =
blanchet@33192
   333
    type_schema_of_rep T1 R1 @ type_schema_of_rep T2 R2
blanchet@33192
   334
  | type_schema_of_rep T (Opt R) = type_schema_of_rep T R
blanchet@33224
   335
  | type_schema_of_rep T R = raise REP ("Nitpick_Rep.type_schema_of_rep", [R])
blanchet@33192
   336
(* typ list -> rep list -> typ list *)
blanchet@33192
   337
and type_schema_of_reps Ts Rs = flat (map2 type_schema_of_rep Ts Rs)
blanchet@33192
   338
blanchet@33192
   339
(* rep -> int list list *)
blanchet@33192
   340
val all_combinations_for_rep = all_combinations o atom_schema_of_rep
blanchet@33192
   341
(* rep list -> int list list *)
blanchet@33192
   342
val all_combinations_for_reps = all_combinations o atom_schema_of_reps
blanchet@33192
   343
blanchet@33192
   344
end;