added const_type: sg -> typ option;
authorwenzelm
Thu May 19 16:20:52 1994 +0200 (1994-05-19)
changeset 386e9ba9f7e2542
parent 385 921f87897a76
child 387 69f4356d915d
added const_type: sg -> typ option;
stamps now stored in REVERSE order;
now supports 'draft signatures' and incremental extension: is_draft,
add_classes (supports axclasses), add_defsort, add_types, add_tyabbrs,
add_tyabbrs_i, add_arities, add_consts, add_consts_i, add_syntax,
add_syntax_i, add_trfuns, add_trrules, add_name, make_draft;
added const_of_class, class_of_const (for axclasses);
changed the pure signature to support axclasses (added itself, TYPE);
various major internal changes;
src/Pure/sign.ML
     1.1 --- a/src/Pure/sign.ML	Thu May 19 16:17:46 1994 +0200
     1.2 +++ b/src/Pure/sign.ML	Thu May 19 16:20:52 1994 +0200
     1.3 @@ -5,7 +5,7 @@
     1.4  The abstract type "sg" of signatures.
     1.5  
     1.6  TODO:
     1.7 -  a clean modular sequential Sign.extend (using sg_ext list);
     1.8 +  pure sign: elim Syntax.constrainC
     1.9  *)
    1.10  
    1.11  signature SIGN =
    1.12 @@ -14,19 +14,21 @@
    1.13    structure Syntax: SYNTAX
    1.14    structure Type: TYPE
    1.15    sharing Symtab = Type.Symtab
    1.16 -  local open Type in
    1.17 +  local open Type Syntax Syntax.Mixfix in
    1.18      type sg
    1.19      val rep_sg: sg ->
    1.20        {tsig: type_sig,
    1.21         const_tab: typ Symtab.table,
    1.22 -       syn: Syntax.syntax,
    1.23 +       syn: syntax,
    1.24         stamps: string ref list}
    1.25      val subsig: sg * sg -> bool
    1.26      val eq_sg: sg * sg -> bool
    1.27 +    val is_draft: sg -> bool
    1.28 +    val const_type: sg -> string -> typ option
    1.29      val print_sg: sg -> unit
    1.30      val pprint_sg: sg -> pprint_args -> unit
    1.31 -    val pretty_term: sg -> term -> Syntax.Pretty.T
    1.32 -    val pretty_typ: sg -> typ -> Syntax.Pretty.T
    1.33 +    val pretty_term: sg -> term -> Pretty.T
    1.34 +    val pretty_typ: sg -> typ -> Pretty.T
    1.35      val string_of_term: sg -> term -> string
    1.36      val string_of_typ: sg -> typ -> string
    1.37      val pprint_term: sg -> term -> pprint_args -> unit
    1.38 @@ -34,14 +36,34 @@
    1.39      val certify_typ: sg -> typ -> typ
    1.40      val certify_term: sg -> term -> term * typ * int
    1.41      val read_typ: sg * (indexname -> sort option) -> string -> typ
    1.42 +    val add_classes: (class list * class * class list) list -> sg -> sg
    1.43 +    val add_defsort: sort -> sg -> sg
    1.44 +    val add_types: (string * int * mixfix) list -> sg -> sg
    1.45 +    val add_tyabbrs: (string * string list * string * mixfix) list -> sg -> sg
    1.46 +    val add_tyabbrs_i: (string * string list * typ * mixfix) list -> sg -> sg
    1.47 +    val add_arities: (string * sort list * sort) list -> sg -> sg
    1.48 +    val add_consts: (string * string * mixfix) list -> sg -> sg
    1.49 +    val add_consts_i: (string * typ * mixfix) list -> sg -> sg
    1.50 +    val add_syntax: (string * string * mixfix) list -> sg -> sg
    1.51 +    val add_syntax_i: (string * typ * mixfix) list -> sg -> sg
    1.52 +    val add_trfuns:
    1.53 +      (string * (ast list -> ast)) list *
    1.54 +      (string * (term list -> term)) list *
    1.55 +      (string * (term list -> term)) list *
    1.56 +      (string * (ast list -> ast)) list -> sg -> sg
    1.57 +    val add_trrules: xrule list -> sg -> sg
    1.58 +    val add_name: string -> sg -> sg
    1.59 +    val make_draft: sg -> sg
    1.60      val extend: sg -> string ->
    1.61        (class * class list) list * class list *
    1.62        (string list * int) list *
    1.63        (string * string list * string) list *
    1.64        (string list * (sort list * class)) list *
    1.65 -      (string list * string) list * Syntax.sext option -> sg
    1.66 +      (string list * string) list * sext option -> sg
    1.67      val merge: sg * sg -> sg
    1.68      val pure: sg
    1.69 +    val const_of_class: class -> string
    1.70 +    val class_of_const: string -> class
    1.71    end
    1.72  end;
    1.73  
    1.74 @@ -50,9 +72,11 @@
    1.75  
    1.76  structure Symtab = Type.Symtab;
    1.77  structure Syntax = Syntax;
    1.78 +structure BasicSyntax: BASIC_SYNTAX = Syntax;
    1.79  structure Pretty = Syntax.Pretty;
    1.80  structure Type = Type;
    1.81 -open Type;
    1.82 +open BasicSyntax Type;
    1.83 +open Syntax.Mixfix;   (* FIXME *)
    1.84  
    1.85  
    1.86  (** datatype sg **)
    1.87 @@ -70,14 +94,23 @@
    1.88  fun rep_sg (Sg args) = args;
    1.89  
    1.90  
    1.91 +fun is_draft (Sg {stamps = ref "#" :: _, ...}) = true
    1.92 +  | is_draft _ = false;
    1.93 +
    1.94  fun subsig (Sg {stamps = s1, ...}, Sg {stamps = s2, ...}) = s1 subset s2;
    1.95  
    1.96  fun eq_sg (Sg {stamps = s1, ...}, Sg {stamps = s2, ...}) = eq_set (s1, s2);
    1.97  
    1.98  
    1.99 +fun const_type (Sg {const_tab, ...}) c =
   1.100 +  Symtab.lookup (const_tab, c);
   1.101 +
   1.102 +
   1.103  
   1.104  (** print signature **)
   1.105  
   1.106 +val stamp_names = rev o map !;
   1.107 +
   1.108  fun print_sg sg =
   1.109    let
   1.110      fun prt_typ syn ty = Pretty.quote (Syntax.pretty_typ syn ty);
   1.111 @@ -113,7 +146,7 @@
   1.112      val Sg {tsig, const_tab, syn, stamps} = sg;
   1.113      val {classes, subclass, default, args, abbrs, coreg} = rep_tsig tsig;
   1.114    in
   1.115 -    Pretty.writeln (Pretty.strs ("stamps:" :: map ! stamps));
   1.116 +    Pretty.writeln (Pretty.strs ("stamps:" :: stamp_names stamps));
   1.117      Pretty.writeln (Pretty.strs ("classes:" :: classes));
   1.118      Pretty.writeln (Pretty.big_list "subclass:" (map pretty_subclass subclass));
   1.119      Pretty.writeln (pretty_default default);
   1.120 @@ -121,12 +154,12 @@
   1.121      Pretty.writeln (Pretty.big_list "abbrs:" (map (pretty_abbr syn) abbrs));
   1.122      Pretty.writeln (Pretty.big_list "coreg:" (flat (map pretty_coreg coreg)));
   1.123      Pretty.writeln (Pretty.big_list "consts:"
   1.124 -      (map (pretty_const syn) (Symtab.alist_of const_tab)))
   1.125 +      (map (pretty_const syn) (Symtab.dest const_tab)))
   1.126    end;
   1.127  
   1.128  
   1.129  fun pprint_sg (Sg {stamps, ...}) =
   1.130 -  Pretty.pprint (Pretty.str_list "{" "}" (map ! stamps));
   1.131 +  Pretty.pprint (Pretty.str_list "{" "}" (stamp_names stamps));
   1.132  
   1.133  
   1.134  
   1.135 @@ -143,22 +176,19 @@
   1.136  
   1.137  
   1.138  
   1.139 -(** certify types and terms **)
   1.140 -
   1.141 -(*errors are indicated by exception TYPE*)
   1.142 +(** certify types and terms **)   (*exception TYPE*)
   1.143  
   1.144  fun certify_typ (Sg {tsig, ...}) ty = cert_typ tsig ty;
   1.145  
   1.146  
   1.147 -(* FIXME -> term.ML (?) *)
   1.148 -fun mapfilter_atoms f (Abs (_, _, t)) = mapfilter_atoms f t
   1.149 -  | mapfilter_atoms f (t $ u) = mapfilter_atoms f t @ mapfilter_atoms f u
   1.150 -  | mapfilter_atoms f a = (case f a of Some y => [y] | None => []);
   1.151 +fun mapfilt_atoms f (Abs (_, _, t)) = mapfilt_atoms f t
   1.152 +  | mapfilt_atoms f (t $ u) = mapfilt_atoms f t @ mapfilt_atoms f u
   1.153 +  | mapfilt_atoms f a = (case f a of Some y => [y] | None => []);
   1.154  
   1.155 -fun certify_term (sg as Sg {tsig, const_tab, ...}) tm =
   1.156 +fun certify_term (sg as Sg {tsig, ...}) tm =
   1.157    let
   1.158      fun valid_const a T =
   1.159 -      (case Symtab.lookup (const_tab, a) of
   1.160 +      (case const_type sg a of
   1.161          Some U => typ_instance (tsig, T, U)
   1.162        | _ => false);
   1.163  
   1.164 @@ -170,23 +200,21 @@
   1.165            if i < 0 then Some ("Negative index for Var " ^ quote x) else None
   1.166        | atom_err _ = None;
   1.167  
   1.168 -
   1.169      val norm_tm =
   1.170        (case it_term_types (typ_errors tsig) (tm, []) of
   1.171          [] => map_term_types (norm_typ tsig) tm
   1.172        | errs => raise_type (cat_lines errs) [] [tm]);
   1.173    in
   1.174 -    (case mapfilter_atoms atom_err norm_tm of
   1.175 +    (case mapfilt_atoms atom_err norm_tm of
   1.176        [] => (norm_tm, type_of norm_tm, maxidx_of_term norm_tm)
   1.177      | errs => raise_type (cat_lines errs) [] [norm_tm])
   1.178    end;
   1.179  
   1.180  
   1.181  
   1.182 -(** read types **)
   1.183 +(** read types **)    (*exception ERROR*)
   1.184  
   1.185 -(*read and certify typ wrt a signature; errors are indicated by
   1.186 -  exception ERROR (with messages already printed)*)
   1.187 +(* FIXME rd_typ vs. read_raw_typ (?) *)
   1.188  
   1.189  fun rd_typ tsig syn sort_of s =
   1.190    let
   1.191 @@ -203,9 +231,230 @@
   1.192  
   1.193  
   1.194  
   1.195 -(** extend signature **)
   1.196 +(** extend signature **)    (*exception ERROR*)
   1.197 +
   1.198 +(* FIXME -> type.ML *)
   1.199 +
   1.200 +(* FIXME replace? *)
   1.201 +fun varify_typ (Type (t, tys)) = Type (t, map varify_typ tys)
   1.202 +  | varify_typ (TFree (a, s)) = TVar ((a, 0), s)
   1.203 +  | varify_typ (ty as TVar _) =
   1.204 +      raise_type "Illegal schematic type variable" [ty] [];
   1.205 +
   1.206 +
   1.207 +(* fake newstyle interfaces *) (* FIXME -> type.ML *)
   1.208 +
   1.209 +fun ext_tsig_classes tsig classes =
   1.210 +  if exists (fn ([], _, _) => false | _ => true) classes then
   1.211 +    sys_error "FIXME ext_tsig_classes"
   1.212 +  else
   1.213 +    extend_tsig tsig (map (fn (_, c, cs) => (c, cs)) classes, [], [], []);
   1.214 +
   1.215 +fun ext_tsig_defsort tsig defsort =
   1.216 +  extend_tsig tsig ([], defsort, [], []);
   1.217 +
   1.218 +fun ext_tsig_types tsig types =
   1.219 +  extend_tsig tsig ([], [], map (fn (t, n) => ([t], n)) types, []);
   1.220 +
   1.221 +(* FIXME varify_typ, rem_sorts; norm_typ (?) *)
   1.222 +fun ext_tsig_abbrs tsig abbrs = Type.ext_tsig_abbrs tsig
   1.223 +  (map (fn (t, vs, rhs) => (t, (map (rpair 0) vs, varifyT rhs))) abbrs);
   1.224 +
   1.225 +fun ext_tsig_arities tsig arities = extend_tsig tsig
   1.226 +  ([], [], [], flat (map (fn (t, ss, cs) => map (fn c => ([t], (ss, c))) cs) arities));
   1.227 +
   1.228 +
   1.229 +
   1.230 +(** read types **)  (*exception ERROR*)
   1.231 +
   1.232 +fun err_in_type s =
   1.233 +  error ("The error(s) above occurred in type " ^ quote s);
   1.234 +
   1.235 +fun read_raw_typ syn tsig sort_of str =
   1.236 +  Syntax.read_typ syn (fn x => if_none (sort_of x) (defaultS tsig)) str
   1.237 +    handle ERROR => err_in_type str;
   1.238 +
   1.239 +(*read and certify typ wrt a signature*)
   1.240 +fun read_typ (Sg {tsig, syn, ...}, sort_of) str =
   1.241 +  cert_typ tsig (read_raw_typ syn tsig sort_of str)
   1.242 +    handle TYPE (msg, _, _) => (writeln msg; err_in_type str);
   1.243 +
   1.244 +
   1.245 +
   1.246 +(** extension functions **)  (*exception ERROR*)
   1.247 +
   1.248 +fun decls_of name_of mfixs =
   1.249 +  map (fn (x, y, mx) => (name_of x mx, y)) mfixs;
   1.250 +
   1.251 +
   1.252 +(* add default sort *)
   1.253 +
   1.254 +fun ext_defsort (syn, tsig, ctab) defsort =
   1.255 +  (syn, ext_tsig_defsort tsig defsort, ctab);
   1.256 +
   1.257 +
   1.258 +(* add type constructors *)
   1.259 +
   1.260 +fun ext_types (syn, tsig, ctab) types =
   1.261 +  (Syntax.extend_type_gram syn types,
   1.262 +    ext_tsig_types tsig (decls_of type_name types),
   1.263 +    ctab);
   1.264 +
   1.265 +
   1.266 +(* add type abbreviations *)
   1.267 +
   1.268 +fun read_abbr syn tsig (t, vs, rhs_src) =
   1.269 +  (t, vs, read_raw_typ syn tsig (K None) rhs_src)
   1.270 +    handle ERROR => error ("in type abbreviation " ^ t);
   1.271 +
   1.272 +fun ext_abbrs rd_abbr (syn, tsig, ctab) abbrs =
   1.273 +  let
   1.274 +    fun mfix_of (t, vs, _, mx) = (t, length vs, mx);
   1.275 +    val syn1 = Syntax.extend_type_gram syn (map mfix_of abbrs);
   1.276 +
   1.277 +    fun decl_of (t, vs, rhs, mx) =
   1.278 +      rd_abbr syn1 tsig (type_name t mx, vs, rhs);
   1.279 +  in
   1.280 +    (syn1, ext_tsig_abbrs tsig (map decl_of abbrs), ctab)
   1.281 +  end;
   1.282 +
   1.283 +val ext_tyabbrs_i = ext_abbrs (K (K I));
   1.284 +val ext_tyabbrs = ext_abbrs read_abbr;
   1.285 +
   1.286 +
   1.287 +(* add type arities *)
   1.288 +
   1.289 +fun ext_arities (syn, tsig, ctab) arities =
   1.290 +  let
   1.291 +    val tsig1 = ext_tsig_arities tsig arities;
   1.292 +    val log_types = logical_types tsig1;
   1.293 +  in
   1.294 +    (Syntax.extend_log_types syn log_types, tsig1, ctab)
   1.295 +  end;
   1.296 +
   1.297 +
   1.298 +(* add term constants and syntax *)
   1.299 +
   1.300 +fun err_in_const c =
   1.301 +  error ("in declaration of constant " ^ quote c);
   1.302 +
   1.303 +fun err_dup_consts cs =
   1.304 +  error ("Duplicate declaration of constant(s) " ^ commas_quote cs);
   1.305 +
   1.306  
   1.307 -(*errors are indicated by exception ERROR (with messages already printed)*)
   1.308 +fun read_const syn tsig (c, ty_src, mx) =
   1.309 +  (c, read_raw_typ syn tsig (K None) ty_src, mx)
   1.310 +    handle ERROR => err_in_const (const_name c mx);
   1.311 +
   1.312 +fun ext_cnsts rd_const syn_only (syn, tsig, ctab) raw_consts =
   1.313 +  let
   1.314 +    fun prep_const (c, ty, mx) = (c, cert_typ tsig (varify_typ ty), mx)
   1.315 +      handle TYPE (msg, _, _) => (writeln msg; err_in_const (const_name c mx));
   1.316 +
   1.317 +    val consts = map (prep_const o rd_const syn tsig) raw_consts;
   1.318 +    val decls =
   1.319 +      if syn_only then []
   1.320 +      else filter_out (equal "" o fst) (decls_of const_name consts);
   1.321 +  in
   1.322 +    (Syntax.extend_const_gram syn consts, tsig,
   1.323 +      Symtab.extend_new (ctab, decls)
   1.324 +        handle Symtab.DUPS cs => err_dup_consts cs)
   1.325 +  end;
   1.326 +
   1.327 +val ext_consts_i = ext_cnsts (K (K I)) false;
   1.328 +val ext_consts = ext_cnsts read_const false;
   1.329 +val ext_syntax_i = ext_cnsts (K (K I)) true;
   1.330 +val ext_syntax = ext_cnsts read_const true;
   1.331 +
   1.332 +
   1.333 +(* add type classes *)
   1.334 +
   1.335 +fun const_of_class c = c ^ "_class";
   1.336 +
   1.337 +fun class_of_const c_class =
   1.338 +  let
   1.339 +    val c = implode (take (size c_class - 6, explode c_class));
   1.340 +  in
   1.341 +    if const_of_class c = c_class then c
   1.342 +    else raise_term ("class_of_const: bad name " ^ quote c_class) []
   1.343 +  end;
   1.344 +
   1.345 +
   1.346 +fun ext_classes (syn, tsig, ctab) classes =
   1.347 +  let
   1.348 +    val names = map (fn (_, c, _) => c) classes;
   1.349 +    val consts =
   1.350 +      map (fn c => (const_of_class c, a_itselfT --> propT, NoSyn)) names;
   1.351 +  in
   1.352 +    ext_consts_i
   1.353 +      (Syntax.extend_consts syn names, ext_tsig_classes tsig classes, ctab)
   1.354 +      consts
   1.355 +  end;
   1.356 +
   1.357 +
   1.358 +(* add syntactic translations *)
   1.359 +
   1.360 +fun ext_trfuns (syn, tsig, ctab) trfuns =
   1.361 +  (Syntax.extend_trfuns syn trfuns, tsig, ctab);
   1.362 +
   1.363 +fun ext_trrules (syn, tsig, ctab) xrules =
   1.364 +  (Syntax.extend_trrules syn xrules, tsig, ctab);
   1.365 +
   1.366 +
   1.367 +(* build signature *)
   1.368 +
   1.369 +(* FIXME debug *)
   1.370 +fun assert_stamps_ok stamps =
   1.371 +  let val names = map ! stamps;
   1.372 +  in
   1.373 +    if not (null (duplicates stamps)) then
   1.374 +      error "DEBUG dup stamps"
   1.375 +    else if not (null (duplicates names)) then
   1.376 +      error "DEBUG dup stamp names"
   1.377 +    else if not (null names) andalso exists (equal "#") (tl names) then
   1.378 +      error "DEBUG misplaced draft stamp name"
   1.379 +    else stamps
   1.380 +  end;
   1.381 +
   1.382 +fun ext_stamps stamps name =
   1.383 +  let
   1.384 +    val stmps = (case stamps of ref "#" :: ss => ss | ss => ss);
   1.385 +  in
   1.386 +    if exists (equal name o !) stmps then
   1.387 +      error ("Theory already contains a " ^ quote name ^ " component")
   1.388 +    else assert_stamps_ok (ref name :: stmps)
   1.389 +  end;
   1.390 +
   1.391 +
   1.392 +fun make_sign (syn, tsig, ctab) stamps name =
   1.393 +  Sg {tsig = tsig, const_tab = ctab, syn = syn,
   1.394 +    stamps = ext_stamps stamps name};
   1.395 +
   1.396 +fun extend_sign extfun name decls (Sg {tsig, const_tab, syn, stamps}) =
   1.397 +  make_sign (extfun (syn, tsig, const_tab) decls) stamps name;
   1.398 +
   1.399 +
   1.400 +(* the external interfaces *)
   1.401 +
   1.402 +val add_classes   = extend_sign ext_classes "#";
   1.403 +val add_defsort   = extend_sign ext_defsort "#";
   1.404 +val add_types     = extend_sign ext_types "#";
   1.405 +val add_tyabbrs   = extend_sign ext_tyabbrs "#";
   1.406 +val add_tyabbrs_i = extend_sign ext_tyabbrs_i "#";
   1.407 +val add_arities   = extend_sign ext_arities "#";
   1.408 +val add_consts    = extend_sign ext_consts "#";
   1.409 +val add_consts_i  = extend_sign ext_consts_i "#";
   1.410 +val add_syntax    = extend_sign ext_syntax "#";
   1.411 +val add_syntax_i  = extend_sign ext_syntax_i "#";
   1.412 +val add_trfuns    = extend_sign ext_trfuns "#";
   1.413 +val add_trrules   = extend_sign ext_trrules "#";
   1.414 +
   1.415 +fun add_name name sg = extend_sign K name () sg;
   1.416 +val make_draft = add_name "#";
   1.417 +
   1.418 +
   1.419 +
   1.420 +(** extend signature (old) **)      (* FIXME remove *)
   1.421  
   1.422  fun extend sg name (classes, default, types, abbrs, arities, consts, opt_sext) =
   1.423    let
   1.424 @@ -237,7 +486,7 @@
   1.425      val sext = if_none opt_sext Syntax.empty_sext;
   1.426  
   1.427      val tsig' = extend_tsig tsig (classes, default, types, arities);
   1.428 -    val tsig1 = ext_tsig_abbrs tsig' (map (read_abbr syn) abbrs);
   1.429 +    val tsig1 = Type.ext_tsig_abbrs tsig' (map (read_abbr syn) abbrs);
   1.430  
   1.431      val syn1 = Syntax.extend syn (rd_typ tsig1 syn (K None))
   1.432        (logical_types tsig1, xconsts, sext);
   1.433 @@ -246,33 +495,23 @@
   1.434        (Syntax.constants sext @ consts));
   1.435  
   1.436      val const_tab1 =
   1.437 -      Symtab.extend (K false) (const_tab, map (read_const tsig1 syn) all_consts)
   1.438 -        handle Symtab.DUPLICATE c
   1.439 -          => error ("Constant " ^ quote c ^ " declared twice");
   1.440 +      Symtab.extend_new (const_tab, map (read_const tsig1 syn) all_consts)
   1.441 +        handle Symtab.DUPS cs => err_dup_consts cs;
   1.442  
   1.443 -    val stamps1 =
   1.444 -      if exists (equal name o !) stamps then
   1.445 -        error ("Theory already contains a " ^ quote name ^ " component")
   1.446 -      else stamps @ [ref name];
   1.447 +    val stamps1 = ext_stamps stamps name;
   1.448    in
   1.449      Sg {tsig = tsig1, const_tab = const_tab1, syn = syn1, stamps = stamps1}
   1.450    end;
   1.451  
   1.452  
   1.453  
   1.454 -(** merge signatures **)
   1.455 -
   1.456 -(*errors are indicated by exception TERM*)
   1.457 -
   1.458 -fun check_stamps stamps =
   1.459 -  (case duplicates (map ! stamps) of
   1.460 -    [] => stamps
   1.461 -  | dups => raise_term ("Attempt to merge different versions of theories " ^
   1.462 -      commas (map quote dups)) []);
   1.463 +(** merge signatures **)    (*exception TERM*)
   1.464  
   1.465  fun merge (sg1, sg2) =
   1.466    if subsig (sg2, sg1) then sg1
   1.467    else if subsig (sg1, sg2) then sg2
   1.468 +  else if is_draft sg1 orelse is_draft sg2 then
   1.469 +    raise_term "Illegal merge of draft signatures" []
   1.470    else
   1.471      (*neither is union already; must form union*)
   1.472      let
   1.473 @@ -281,16 +520,21 @@
   1.474        val Sg {tsig = tsig2, const_tab = const_tab2, syn = syn2,
   1.475          stamps = stamps2} = sg2;
   1.476  
   1.477 +
   1.478        val tsig = merge_tsigs (tsig1, tsig2);
   1.479  
   1.480        val const_tab = Symtab.merge (op =) (const_tab1, const_tab2)
   1.481 -        handle Symtab.DUPLICATE c =>
   1.482 -          raise_term ("Incompatible types for constant " ^ quote c) [];
   1.483 +        handle Symtab.DUPS cs =>
   1.484 +          raise_term ("Incompatible types for constant(s) " ^ commas_quote cs) [];
   1.485 +
   1.486 +      val syn = Syntax.merge_syntaxes syn1 syn2;
   1.487  
   1.488 -      val syn = Syntax.merge (logical_types tsig) syn1 syn2;
   1.489 -
   1.490 -      val stamps = check_stamps (merge_lists stamps1 stamps2);
   1.491 +      val stamps = merge_rev_lists stamps1 stamps2;
   1.492 +      val dups = duplicates (stamp_names stamps);
   1.493      in
   1.494 +      if null dups then assert_stamps_ok stamps    (* FIXME debug *)
   1.495 +      else raise_term ("Attempt to merge different versions of theories " ^
   1.496 +        commas_quote dups) [];
   1.497        Sg {tsig = tsig, const_tab = const_tab, syn = syn, stamps = stamps}
   1.498      end;
   1.499  
   1.500 @@ -298,20 +542,29 @@
   1.501  
   1.502  (** the Pure signature **)
   1.503  
   1.504 -val sg0 = Sg {tsig = tsig0, const_tab = Symtab.null,
   1.505 -  syn = Syntax.type_syn, stamps = []};
   1.506 -
   1.507 -val pure = extend sg0 "Pure"
   1.508 -  ([("logic", [])],
   1.509 -   ["logic"],
   1.510 -   [(["fun"], 2),
   1.511 -    (["prop"], 0),
   1.512 -    (Syntax.syntax_types, 0)],
   1.513 -   [],
   1.514 -   [(["fun"],  ([["logic"], ["logic"]], "logic")),
   1.515 -    (["prop"], ([], "logic"))],
   1.516 -   ([Syntax.constrainC], "'a::{} => 'a") :: Syntax.syntax_consts,
   1.517 -   Some Syntax.pure_sext);
   1.518 +val pure =
   1.519 +  make_sign (Syntax.type_syn, tsig0, Symtab.null) [] "#"
   1.520 +  also add_types
   1.521 +   (("fun", 2, NoSyn) ::
   1.522 +    ("prop", 0, NoSyn) ::
   1.523 +    ("itself", 1, NoSyn) ::
   1.524 +    Syntax.Mixfix.pure_types)
   1.525 +  also add_classes [([], logicC, [])]
   1.526 +  also add_defsort logicS
   1.527 +  also add_arities
   1.528 +   [("fun", [logicS, logicS], logicS),
   1.529 +    ("prop", [], logicS),
   1.530 +    ("itself", [logicS], logicS)]
   1.531 +  also add_syntax Syntax.Mixfix.pure_syntax
   1.532 +  also add_trfuns Syntax.pure_trfuns
   1.533 +  also add_consts
   1.534 +   [("==", "['a::{}, 'a] => prop", Mixfix ("(_ ==/ _)", [3, 2], 2)),
   1.535 +    ("=?=", "['a::{}, 'a] => prop", Mixfix ("(_ =?=/ _)", [3, 2], 2)),
   1.536 +    ("==>", "[prop, prop] => prop", Mixfix ("(_ ==>/ _)", [2, 1], 1)),
   1.537 +    ("all", "('a => prop) => prop", Binder ("!!", 0)),
   1.538 +    ("TYPE", "'a itself", NoSyn),
   1.539 +    (Syntax.constrainC, "'a::{} => 'a", NoSyn)]
   1.540 +  also add_name "Pure";
   1.541  
   1.542  
   1.543  end;