src/Pure/sorts.ML
author wenzelm
Fri May 05 21:59:46 2006 +0200 (2006-05-05)
changeset 19578 f93b7637a5e6
parent 19531 89970e06351f
child 19584 606d6a73e6d9
permissions -rw-r--r--
added class_error and exception CLASS_ERROR (supercedes DOMAIN);
clarified of_class_derivation;
tuned witness_sorts;
wenzelm@2956
     1
(*  Title:      Pure/sorts.ML
wenzelm@2956
     2
    ID:         $Id$
wenzelm@2956
     3
    Author:     Markus Wenzel and Stefan Berghofer, TU Muenchen
wenzelm@2956
     4
wenzelm@19514
     5
The order-sorted algebra of type classes.
wenzelm@19529
     6
wenzelm@19529
     7
Classes denote (possibly empty) collections of types that are
wenzelm@19529
     8
partially ordered by class inclusion. They are represented
wenzelm@19529
     9
symbolically by strings.
wenzelm@19529
    10
wenzelm@19529
    11
Sorts are intersections of finitely many classes. They are represented
wenzelm@19529
    12
by lists of classes.  Normal forms of sorts are sorted lists of
wenzelm@19529
    13
minimal classes (wrt. current class inclusion).
wenzelm@2956
    14
*)
wenzelm@2956
    15
wenzelm@2956
    16
signature SORTS =
wenzelm@2956
    17
sig
wenzelm@16598
    18
  val eq_set: sort list * sort list -> bool
wenzelm@16598
    19
  val union: sort list -> sort list -> sort list
wenzelm@16598
    20
  val subtract: sort list -> sort list -> sort list
wenzelm@19463
    21
  val remove_sort: sort -> sort list -> sort list
wenzelm@16598
    22
  val insert_sort: sort -> sort list -> sort list
wenzelm@16598
    23
  val insert_typ: typ -> sort list -> sort list
wenzelm@16598
    24
  val insert_typs: typ list -> sort list -> sort list
wenzelm@16598
    25
  val insert_term: term -> sort list -> sort list
wenzelm@16598
    26
  val insert_terms: term list -> sort list -> sort list
wenzelm@14782
    27
  type classes
wenzelm@14782
    28
  type arities
wenzelm@14782
    29
  val class_eq: classes -> class * class -> bool
wenzelm@14782
    30
  val class_less: classes -> class * class -> bool
wenzelm@14782
    31
  val class_le: classes -> class * class -> bool
wenzelm@14782
    32
  val sort_eq: classes -> sort * sort -> bool
wenzelm@14782
    33
  val sort_le: classes -> sort * sort -> bool
wenzelm@14782
    34
  val sorts_le: classes -> sort list * sort list -> bool
wenzelm@14782
    35
  val inter_sort: classes -> sort * sort -> sort
wenzelm@14782
    36
  val norm_sort: classes -> sort -> sort
wenzelm@19514
    37
  val add_arities: Pretty.pp -> classes -> string * (class * sort list) list -> arities -> arities
wenzelm@19514
    38
  val rebuild_arities: Pretty.pp -> classes -> arities -> arities
wenzelm@19514
    39
  val merge_arities: Pretty.pp -> classes -> arities * arities -> arities
wenzelm@19514
    40
  val add_class: Pretty.pp -> class * class list -> classes -> classes
wenzelm@19514
    41
  val add_classrel: Pretty.pp -> class * class -> classes -> classes
wenzelm@19514
    42
  val merge_classes: Pretty.pp -> classes * classes -> classes
wenzelm@19578
    43
  type class_error
wenzelm@19578
    44
  val class_error: Pretty.pp -> class_error -> 'a
wenzelm@19578
    45
  exception CLASS_ERROR of class_error
wenzelm@19578
    46
  val mg_domain: classes * arities -> string -> sort -> sort list   (*exception CLASS_ERROR*)
wenzelm@19529
    47
  val of_sort: classes * arities -> typ * sort -> bool
wenzelm@19529
    48
  val of_sort_derivation: Pretty.pp -> classes * arities ->
wenzelm@19529
    49
    {classrel: 'a * class -> class -> 'a,
wenzelm@19529
    50
     constructor: string -> ('a * class) list list -> class -> 'a,
wenzelm@19578
    51
     variable: typ -> ('a * class) list} -> typ * sort -> 'a list   (*exception CLASS_ERROR*)
wenzelm@19529
    52
  val witness_sorts: classes * arities -> string list ->
wenzelm@19529
    53
    sort list -> sort list -> (typ * sort) list
wenzelm@2956
    54
end;
wenzelm@2956
    55
wenzelm@2956
    56
structure Sorts: SORTS =
wenzelm@2956
    57
struct
wenzelm@2956
    58
wenzelm@19514
    59
wenzelm@19529
    60
(** ordered lists of sorts **)
wenzelm@14782
    61
wenzelm@16598
    62
val eq_set = OrdList.eq_set Term.sort_ord;
wenzelm@16598
    63
val op union = OrdList.union Term.sort_ord;
wenzelm@16598
    64
val subtract = OrdList.subtract Term.sort_ord;
wenzelm@14782
    65
wenzelm@19463
    66
val remove_sort = OrdList.remove Term.sort_ord;
wenzelm@16598
    67
val insert_sort = OrdList.insert Term.sort_ord;
wenzelm@14782
    68
wenzelm@16598
    69
fun insert_typ (TFree (_, S)) Ss = insert_sort S Ss
wenzelm@16598
    70
  | insert_typ (TVar (_, S)) Ss = insert_sort S Ss
wenzelm@16598
    71
  | insert_typ (Type (_, Ts)) Ss = insert_typs Ts Ss
wenzelm@16598
    72
and insert_typs [] Ss = Ss
wenzelm@16598
    73
  | insert_typs (T :: Ts) Ss = insert_typs Ts (insert_typ T Ss);
wenzelm@14782
    74
wenzelm@16598
    75
fun insert_term (Const (_, T)) Ss = insert_typ T Ss
wenzelm@16598
    76
  | insert_term (Free (_, T)) Ss = insert_typ T Ss
wenzelm@16598
    77
  | insert_term (Var (_, T)) Ss = insert_typ T Ss
wenzelm@16598
    78
  | insert_term (Bound _) Ss = Ss
wenzelm@16598
    79
  | insert_term (Abs (_, T, t)) Ss = insert_term t (insert_typ T Ss)
wenzelm@16598
    80
  | insert_term (t $ u) Ss = insert_term t (insert_term u Ss);
wenzelm@14782
    81
wenzelm@16598
    82
fun insert_terms [] Ss = Ss
wenzelm@16598
    83
  | insert_terms (t :: ts) Ss = insert_terms ts (insert_term t Ss);
wenzelm@14782
    84
wenzelm@14782
    85
wenzelm@19529
    86
wenzelm@19529
    87
(** order-sorted algebra **)
wenzelm@2956
    88
wenzelm@2956
    89
(*
wenzelm@14782
    90
  classes: graph representing class declarations together with proper
wenzelm@14782
    91
    subclass relation, which needs to be transitive and acyclic.
wenzelm@2956
    92
wenzelm@14782
    93
  arities: table of association lists of all type arities; (t, ars)
wenzelm@19531
    94
    means that type constructor t has the arities ars; an element
wenzelm@19531
    95
    (c, (c0, Ss)) of ars represents the arity t::(Ss)c being derived
wenzelm@19531
    96
    via c0 <= c.  "Coregularity" of the arities structure requires
wenzelm@19531
    97
    that for any two declarations t::(Ss1)c1 and t::(Ss2)c2 such that
wenzelm@19531
    98
    c1 <= c2 holds Ss1 <= Ss2.
wenzelm@2956
    99
*)
wenzelm@2956
   100
wenzelm@14782
   101
type classes = stamp Graph.T;
wenzelm@19524
   102
type arities = (class * (class * sort list)) list Symtab.table;
wenzelm@2956
   103
wenzelm@2956
   104
wenzelm@19529
   105
(* class relations *)
wenzelm@2956
   106
wenzelm@14782
   107
fun class_eq (_: classes) (c1, c2:class) = c1 = c2;
wenzelm@14782
   108
val class_less: classes -> class * class -> bool = Graph.is_edge;
wenzelm@14782
   109
fun class_le classes (c1, c2) = c1 = c2 orelse class_less classes (c1, c2);
wenzelm@2956
   110
wenzelm@2956
   111
wenzelm@19529
   112
(* sort relations *)
wenzelm@2956
   113
wenzelm@14782
   114
fun sort_le classes (S1, S2) =
haftmann@17155
   115
  forall (fn c2 => exists (fn c1 => class_le classes (c1, c2)) S1) S2;
wenzelm@2956
   116
wenzelm@14782
   117
fun sorts_le classes (Ss1, Ss2) =
wenzelm@14782
   118
  ListPair.all (sort_le classes) (Ss1, Ss2);
wenzelm@2956
   119
wenzelm@14782
   120
fun sort_eq classes (S1, S2) =
wenzelm@14782
   121
  sort_le classes (S1, S2) andalso sort_le classes (S2, S1);
wenzelm@2956
   122
wenzelm@2956
   123
wenzelm@19529
   124
(* intersection *)
wenzelm@2956
   125
wenzelm@16881
   126
fun inter_class classes c S =
wenzelm@2956
   127
  let
wenzelm@2956
   128
    fun intr [] = [c]
wenzelm@2956
   129
      | intr (S' as c' :: c's) =
wenzelm@14782
   130
          if class_le classes (c', c) then S'
wenzelm@14782
   131
          else if class_le classes (c, c') then intr c's
wenzelm@2956
   132
          else c' :: intr c's
wenzelm@2956
   133
  in intr S end;
wenzelm@2956
   134
wenzelm@16881
   135
fun inter_sort classes (S1, S2) =
wenzelm@16881
   136
  sort_strings (fold (inter_class classes) S1 S2);
wenzelm@2956
   137
wenzelm@2956
   138
wenzelm@19529
   139
(* normal forms *)
wenzelm@2956
   140
wenzelm@19529
   141
fun norm_sort _ [] = []
wenzelm@19529
   142
  | norm_sort _ (S as [_]) = S
wenzelm@19529
   143
  | norm_sort classes S =
wenzelm@19529
   144
      filter (fn c => not (exists (fn c' => class_less classes (c', c)) S)) S
wenzelm@19529
   145
      |> sort_distinct string_ord;
wenzelm@2990
   146
wenzelm@2990
   147
wenzelm@2956
   148
wenzelm@19529
   149
(** build algebras **)
wenzelm@19514
   150
wenzelm@19514
   151
(* classes *)
wenzelm@19514
   152
wenzelm@19514
   153
local
wenzelm@19514
   154
wenzelm@19514
   155
fun err_dup_classes cs =
wenzelm@19514
   156
  error ("Duplicate declaration of class(es): " ^ commas_quote cs);
wenzelm@19514
   157
wenzelm@19514
   158
fun err_cyclic_classes pp css =
wenzelm@19514
   159
  error (cat_lines (map (fn cs =>
wenzelm@19514
   160
    "Cycle in class relation: " ^ Pretty.string_of_classrel pp cs) css));
wenzelm@19514
   161
wenzelm@19514
   162
in
wenzelm@19514
   163
wenzelm@19514
   164
fun add_class pp (c, cs) classes =
wenzelm@19514
   165
  let
wenzelm@19514
   166
    val classes' = classes |> Graph.new_node (c, stamp ())
wenzelm@19514
   167
      handle Graph.DUP dup => err_dup_classes [dup];
wenzelm@19514
   168
    val classes'' = classes' |> fold Graph.add_edge_trans_acyclic (map (pair c) cs)
wenzelm@19514
   169
      handle Graph.CYCLES css => err_cyclic_classes pp css;
wenzelm@19514
   170
  in classes'' end;
wenzelm@19514
   171
wenzelm@19514
   172
fun add_classrel pp rel classes =
wenzelm@19514
   173
  classes |> Graph.add_edge_trans_acyclic rel
wenzelm@19514
   174
    handle Graph.CYCLES css => err_cyclic_classes pp css;
wenzelm@19514
   175
wenzelm@19514
   176
fun merge_classes pp args : classes =
wenzelm@19514
   177
  Graph.merge_trans_acyclic (op =) args
wenzelm@19514
   178
    handle Graph.DUPS cs => err_dup_classes cs
wenzelm@19514
   179
        | Graph.CYCLES css => err_cyclic_classes pp css;
wenzelm@19514
   180
wenzelm@14828
   181
end;
wenzelm@19514
   182
wenzelm@19514
   183
wenzelm@19514
   184
(* arities *)
wenzelm@19514
   185
wenzelm@19514
   186
local
wenzelm@19514
   187
wenzelm@19514
   188
fun for_classes _ NONE = ""
wenzelm@19514
   189
  | for_classes pp (SOME (c1, c2)) =
wenzelm@19514
   190
      " for classes " ^ Pretty.string_of_classrel pp [c1, c2];
wenzelm@19514
   191
wenzelm@19514
   192
fun err_conflict pp t cc (c, Ss) (c', Ss') =
wenzelm@19514
   193
  error ("Conflict of type arities" ^ for_classes pp cc ^ ":\n  " ^
wenzelm@19514
   194
    Pretty.string_of_arity pp (t, Ss, [c]) ^ " and\n  " ^
wenzelm@19514
   195
    Pretty.string_of_arity pp (t, Ss', [c']));
wenzelm@19514
   196
wenzelm@19524
   197
fun coregular pp C t (c, (c0, Ss)) ars =
wenzelm@19514
   198
  let
wenzelm@19524
   199
    fun conflict (c', (_, Ss')) =
wenzelm@19514
   200
      if class_le C (c, c') andalso not (sorts_le C (Ss, Ss')) then
wenzelm@19514
   201
        SOME ((c, c'), (c', Ss'))
wenzelm@19514
   202
      else if class_le C (c', c) andalso not (sorts_le C (Ss', Ss)) then
wenzelm@19514
   203
        SOME ((c', c), (c', Ss'))
wenzelm@19514
   204
      else NONE;
wenzelm@19514
   205
  in
wenzelm@19514
   206
    (case get_first conflict ars of
wenzelm@19514
   207
      SOME ((c1, c2), (c', Ss')) => err_conflict pp t (SOME (c1, c2)) (c, Ss) (c', Ss')
wenzelm@19524
   208
    | NONE => (c, (c0, Ss)) :: ars)
wenzelm@19514
   209
  end;
wenzelm@19514
   210
wenzelm@19524
   211
fun insert pp C t (c, (c0, Ss)) ars =
wenzelm@19514
   212
  (case AList.lookup (op =) ars c of
wenzelm@19524
   213
    NONE => coregular pp C t (c, (c0, Ss)) ars
wenzelm@19524
   214
  | SOME (_, Ss') =>
wenzelm@19514
   215
      if sorts_le C (Ss, Ss') then ars
wenzelm@19524
   216
      else if sorts_le C (Ss', Ss) then
wenzelm@19524
   217
        coregular pp C t (c, (c0, Ss))
wenzelm@19524
   218
          (filter_out (fn (c'', (_, Ss'')) => c = c'' andalso Ss'' = Ss') ars)
wenzelm@19514
   219
      else err_conflict pp t NONE (c, Ss) (c, Ss'));
wenzelm@19514
   220
wenzelm@19524
   221
fun complete C (c0, Ss) = map (rpair (c0, Ss)) (Graph.all_succs C [c0]);
wenzelm@19514
   222
wenzelm@19514
   223
in
wenzelm@19514
   224
wenzelm@19514
   225
fun add_arities pp classes (t, ars) arities =
wenzelm@19514
   226
  let val ars' =
wenzelm@19514
   227
    Symtab.lookup_list arities t
wenzelm@19514
   228
    |> fold_rev (fold_rev (insert pp classes t)) (map (complete classes) ars)
wenzelm@19514
   229
  in Symtab.update (t, ars') arities end;
wenzelm@19514
   230
wenzelm@19529
   231
fun add_arities_table pp classes =
wenzelm@19529
   232
  Symtab.fold (fn (t, ars) => add_arities pp classes (t, map snd ars));
wenzelm@19514
   233
wenzelm@19514
   234
fun rebuild_arities pp classes arities =
wenzelm@19514
   235
  Symtab.empty
wenzelm@19514
   236
  |> add_arities_table pp classes arities;
wenzelm@19514
   237
wenzelm@19514
   238
fun merge_arities pp classes (arities1, arities2) =
wenzelm@19514
   239
  Symtab.empty
wenzelm@19514
   240
  |> add_arities_table pp classes arities1
wenzelm@19514
   241
  |> add_arities_table pp classes arities2;
wenzelm@19514
   242
wenzelm@19514
   243
end;
wenzelm@19514
   244
wenzelm@19529
   245
wenzelm@19529
   246
wenzelm@19529
   247
(** sorts of types **)
wenzelm@19529
   248
wenzelm@19578
   249
(* errors *)
wenzelm@19578
   250
wenzelm@19578
   251
datatype class_error = NoClassrel of class * class | NoArity of string * class;
wenzelm@19529
   252
wenzelm@19578
   253
fun class_error pp (NoClassrel (c1, c2)) =
wenzelm@19578
   254
      error ("No class relation " ^ Pretty.string_of_classrel pp [c1, c2])
wenzelm@19578
   255
  | class_error pp (NoArity (a, c)) =
wenzelm@19578
   256
      error ("No type arity " ^ Pretty.string_of_arity pp (a, [], [c]));
wenzelm@19529
   257
wenzelm@19578
   258
exception CLASS_ERROR of class_error;
wenzelm@19578
   259
wenzelm@19578
   260
wenzelm@19578
   261
(* mg_domain *)
wenzelm@19529
   262
wenzelm@19529
   263
fun mg_domain (classes, arities) a S =
wenzelm@19529
   264
  let
wenzelm@19529
   265
    fun dom c =
wenzelm@19529
   266
      (case AList.lookup (op =) (Symtab.lookup_list arities a) c of
wenzelm@19578
   267
        NONE => raise CLASS_ERROR (NoArity (a, c))
wenzelm@19529
   268
      | SOME (_, Ss) => Ss);
wenzelm@19529
   269
    fun dom_inter c Ss = ListPair.map (inter_sort classes) (dom c, Ss);
wenzelm@19529
   270
  in
wenzelm@19529
   271
    (case S of
wenzelm@19529
   272
      [] => raise Fail "Unknown domain of empty intersection"
wenzelm@19529
   273
    | c :: cs => fold dom_inter cs (dom c))
wenzelm@19529
   274
  end;
wenzelm@19529
   275
wenzelm@19529
   276
wenzelm@19529
   277
(* of_sort *)
wenzelm@19529
   278
wenzelm@19529
   279
fun of_sort (classes, arities) =
wenzelm@19529
   280
  let
wenzelm@19529
   281
    fun ofS (_, []) = true
wenzelm@19529
   282
      | ofS (TFree (_, S), S') = sort_le classes (S, S')
wenzelm@19529
   283
      | ofS (TVar (_, S), S') = sort_le classes (S, S')
wenzelm@19529
   284
      | ofS (Type (a, Ts), S) =
wenzelm@19529
   285
          let val Ss = mg_domain (classes, arities) a S in
wenzelm@19529
   286
            ListPair.all ofS (Ts, Ss)
wenzelm@19578
   287
          end handle CLASS_ERROR _ => false;
wenzelm@19529
   288
  in ofS end;
wenzelm@19529
   289
wenzelm@19529
   290
wenzelm@19529
   291
(* of_sort_derivation *)
wenzelm@19529
   292
wenzelm@19529
   293
fun of_sort_derivation pp (classes, arities) {classrel, constructor, variable} =
wenzelm@19529
   294
  let
wenzelm@19578
   295
    fun weaken_path (x, c1 :: c2 :: cs) = weaken_path (classrel (x, c1) c2, c2 :: cs)
wenzelm@19578
   296
      | weaken_path (x, _) = x;
wenzelm@19578
   297
    fun weaken (x, c1) c2 =
wenzelm@19578
   298
      (case Graph.irreducible_paths classes (c1, c2) of
wenzelm@19578
   299
        [] => raise CLASS_ERROR (NoClassrel (c1, c2))
wenzelm@19578
   300
      | cs :: _ => weaken_path (x, cs));
wenzelm@19578
   301
wenzelm@19529
   302
    fun weakens S1 S2 = S2 |> map (fn c2 =>
wenzelm@19529
   303
      (case S1 |> find_first (fn (_, c1) => class_le classes (c1, c2)) of
wenzelm@19529
   304
        SOME d1 => weaken d1 c2
wenzelm@19529
   305
      | NONE => error ("Cannot derive subsort relation " ^
wenzelm@19529
   306
          Pretty.string_of_sort pp (map #2 S1) ^ " < " ^ Pretty.string_of_sort pp S2)));
wenzelm@19529
   307
wenzelm@19529
   308
    fun derive _ [] = []
wenzelm@19529
   309
      | derive (Type (a, Ts)) S =
wenzelm@19529
   310
          let
wenzelm@19578
   311
            val Ss = mg_domain (classes, arities) a S;
wenzelm@19529
   312
            val dom = map2 (fn T => fn S => derive T S ~~ S) Ts Ss;
wenzelm@19529
   313
          in
wenzelm@19529
   314
            S |> map (fn c =>
wenzelm@19529
   315
              let
wenzelm@19529
   316
                val (c0, Ss') = the (AList.lookup (op =) (Symtab.lookup_list arities a) c);
wenzelm@19529
   317
                val dom' = map2 (fn d => fn S' => weakens d S' ~~ S') dom Ss';
wenzelm@19529
   318
              in weaken (constructor a dom' c0, c0) c end)
wenzelm@19529
   319
          end
wenzelm@19529
   320
      | derive T S = weakens (variable T) S;
wenzelm@19529
   321
  in uncurry derive end;
wenzelm@19529
   322
wenzelm@19529
   323
wenzelm@19529
   324
(* witness_sorts *)
wenzelm@19529
   325
wenzelm@19578
   326
fun witness_sorts (classes, arities) log_types hyps sorts =
wenzelm@19529
   327
  let
wenzelm@19529
   328
    fun le S1 S2 = sort_le classes (S1, S2);
wenzelm@19529
   329
    fun get_solved S2 (T, S1) = if le S1 S2 then SOME (T, S2) else NONE;
wenzelm@19529
   330
    fun get_hyp S2 S1 = if le S1 S2 then SOME (TFree ("'hyp", S1), S2) else NONE;
wenzelm@19578
   331
    fun mg_dom t S = SOME (mg_domain (classes, arities) t S) handle CLASS_ERROR _ => NONE;
wenzelm@19529
   332
wenzelm@19578
   333
    fun witn_sort _ [] solved_failed = (SOME (propT, []), solved_failed)
wenzelm@19578
   334
      | witn_sort path S (solved, failed) =
wenzelm@19578
   335
          if exists (le S) failed then (NONE, (solved, failed))
wenzelm@19529
   336
          else
wenzelm@19529
   337
            (case get_first (get_solved S) solved of
wenzelm@19578
   338
              SOME w => (SOME w, (solved, failed))
wenzelm@19529
   339
            | NONE =>
wenzelm@19529
   340
                (case get_first (get_hyp S) hyps of
wenzelm@19578
   341
                  SOME w => (SOME w, (w :: solved, failed))
wenzelm@19578
   342
                | NONE => witn_types path log_types S (solved, failed)))
wenzelm@19529
   343
wenzelm@19578
   344
    and witn_sorts path x = fold_map (witn_sort path) x
wenzelm@19529
   345
wenzelm@19578
   346
    and witn_types _ [] S (solved, failed) = (NONE, (solved, S :: failed))
wenzelm@19578
   347
      | witn_types path (t :: ts) S solved_failed =
wenzelm@19529
   348
          (case mg_dom t S of
wenzelm@19529
   349
            SOME SS =>
wenzelm@19529
   350
              (*do not descend into stronger args (achieving termination)*)
wenzelm@19529
   351
              if exists (fn D => le D S orelse exists (le D) path) SS then
wenzelm@19578
   352
                witn_types path ts S solved_failed
wenzelm@19529
   353
              else
wenzelm@19578
   354
                let val (ws, (solved', failed')) = witn_sorts (S :: path) SS solved_failed in
wenzelm@19529
   355
                  if forall is_some ws then
wenzelm@19529
   356
                    let val w = (Type (t, map (#1 o the) ws), S)
wenzelm@19578
   357
                    in (SOME w, (w :: solved', failed')) end
wenzelm@19578
   358
                  else witn_types path ts S (solved', failed')
wenzelm@19529
   359
                end
wenzelm@19578
   360
          | NONE => witn_types path ts S solved_failed);
wenzelm@19529
   361
wenzelm@19578
   362
    fun double_check TS =
wenzelm@19578
   363
      if of_sort (classes, arities) TS then TS
wenzelm@19578
   364
      else sys_error "FIXME Bad sort witness";
wenzelm@19529
   365
wenzelm@19578
   366
  in map_filter (Option.map double_check) (#1 (witn_sorts [] sorts ([], []))) end;
wenzelm@19529
   367
wenzelm@19514
   368
end;