| author | wenzelm | 
| Sun, 15 Oct 2023 14:22:37 +0200 | |
| changeset 78782 | c44171d372a1 | 
| parent 77979 | a12c48fbf10f | 
| child 79134 | 5f0bbed1c606 | 
| permissions | -rw-r--r-- | 
| 256 | 1 | (* Title: Pure/type.ML | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 2 | Author: Tobias Nipkow, Lawrence C Paulson, and Markus Wenzel | 
| 0 | 3 | |
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 4 | Type signatures and certified types, special treatment of type vars, | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 5 | matching and unification of types, extend and merge type signatures. | 
| 0 | 6 | *) | 
| 7 | ||
| 8 | signature TYPE = | |
| 2964 | 9 | sig | 
| 39288 | 10 | (*constraints*) | 
| 39290 
44e4d8dfd6bf
load type_infer.ML later -- proper context for Type_Infer.infer_types;
 wenzelm parents: 
39289diff
changeset | 11 | val mark_polymorphic: typ -> typ | 
| 39288 | 12 | val constraint: typ -> term -> term | 
| 45445 
41e641a870de
pass term positions into check phase, where resulting types are reported accordingly, and eventually shown as tooltips;
 wenzelm parents: 
44116diff
changeset | 13 | val constraint_type: Proof.context -> typ -> typ | 
| 39292 
6f085332c7d3
Type_Infer.preterm: eliminated separate Constraint;
 wenzelm parents: 
39290diff
changeset | 14 | val strip_constraints: term -> term | 
| 42383 
0ae4ad40d7b5
simplified pretty printing context, which is only required for certain kernel operations;
 wenzelm parents: 
42381diff
changeset | 15 | val appl_error: Proof.context -> term -> typ -> term -> typ -> string | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 16 | (*type signatures and certified types*) | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 17 | datatype decl = | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 18 | LogicalType of int | | 
| 14989 | 19 | Abbreviation of string list * typ * bool | | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 20 | Nonterminal | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 21 | type tsig | 
| 35669 
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
 wenzelm parents: 
35359diff
changeset | 22 | val eq_tsig: tsig * tsig -> bool | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 23 | val rep_tsig: tsig -> | 
| 33095 
bbd52d2f8696
renamed NameSpace to Name_Space -- also to emphasize its subtle change in semantics;
 wenzelm parents: 
33094diff
changeset | 24 |    {classes: Name_Space.T * Sorts.algebra,
 | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 25 | default: sort, | 
| 33173 
b8ca12f6681a
eliminated obsolete tags for types/consts -- now handled via name space, in strongly typed fashion;
 wenzelm parents: 
33097diff
changeset | 26 | types: decl Name_Space.table, | 
| 26641 | 27 | log_types: string list} | 
| 56056 
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
 wenzelm parents: 
56050diff
changeset | 28 | val change_base: bool -> tsig -> tsig | 
| 56139 
b7add947a6ef
more frugal recording of changes: join merely requires information from one side;
 wenzelm parents: 
56056diff
changeset | 29 | val change_ignore: tsig -> tsig | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 30 | val empty_tsig: tsig | 
| 35669 
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
 wenzelm parents: 
35359diff
changeset | 31 | val class_space: tsig -> Name_Space.T | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 32 | val defaultS: tsig -> sort | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 33 | val logical_types: tsig -> string list | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 34 | val eq_sort: tsig -> sort * sort -> bool | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 35 | val subsort: tsig -> sort * sort -> bool | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 36 | val of_sort: tsig -> typ * sort -> bool | 
| 19464 | 37 | val inter_sort: tsig -> sort * sort -> sort | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 38 | val cert_class: tsig -> class -> class | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 39 | val cert_sort: tsig -> sort -> sort | 
| 36447 | 40 | val minimize_sort: tsig -> sort -> sort | 
| 31946 
99ac0321cd47
witness_sorts: proper type witnesses for hyps, not invented "'hyp" variables;
 wenzelm parents: 
30343diff
changeset | 41 | val witness_sorts: tsig -> (typ * sort) list -> sort list -> (typ * sort) list | 
| 24274 
cb9236269af1
type mode: models certification mode (default, syntax, abbrev);
 wenzelm parents: 
23655diff
changeset | 42 | type mode | 
| 
cb9236269af1
type mode: models certification mode (default, syntax, abbrev);
 wenzelm parents: 
23655diff
changeset | 43 | val mode_default: mode | 
| 
cb9236269af1
type mode: models certification mode (default, syntax, abbrev);
 wenzelm parents: 
23655diff
changeset | 44 | val mode_syntax: mode | 
| 
cb9236269af1
type mode: models certification mode (default, syntax, abbrev);
 wenzelm parents: 
23655diff
changeset | 45 | val mode_abbrev: mode | 
| 24484 | 46 | val get_mode: Proof.context -> mode | 
| 47 | val set_mode: mode -> Proof.context -> Proof.context | |
| 48 | val restore_mode: Proof.context -> Proof.context -> Proof.context | |
| 35669 
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
 wenzelm parents: 
35359diff
changeset | 49 | val type_space: tsig -> Name_Space.T | 
| 35680 | 50 | val type_alias: Name_Space.naming -> binding -> string -> tsig -> tsig | 
| 55922 
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
 wenzelm parents: 
55841diff
changeset | 51 | val check_decl: Context.generic -> tsig -> | 
| 
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
 wenzelm parents: 
55841diff
changeset | 52 | xstring * Position.T -> (string * Position.report list) * decl | 
| 42468 | 53 | val the_decl: tsig -> string * Position.T -> decl | 
| 24274 
cb9236269af1
type mode: models certification mode (default, syntax, abbrev);
 wenzelm parents: 
23655diff
changeset | 54 | val cert_typ_mode: mode -> tsig -> typ -> typ | 
| 14993 | 55 | val cert_typ: tsig -> typ -> typ | 
| 19464 | 56 | val arity_number: tsig -> string -> int | 
| 61262 
7bd1eb4b056e
tuned signature: eliminated pointless type Context.pretty;
 wenzelm parents: 
59885diff
changeset | 57 | val arity_sorts: Context.generic -> tsig -> string -> sort -> sort list | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 58 | |
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 59 | (*special treatment of type vars*) | 
| 36621 
2fd4e2c76636
proof terms for strip_shyps, based on the version by krauss/schropp with some notable differences:
 wenzelm parents: 
36450diff
changeset | 60 | val sort_of_atyp: typ -> sort | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 61 | val strip_sorts: typ -> typ | 
| 49687 
4b9034f089eb
use explicit Type.strip_sorts_dummy to suppress sort constraints in output;
 wenzelm parents: 
48992diff
changeset | 62 | val strip_sorts_dummy: typ -> typ | 
| 621 | 63 | val no_tvars: typ -> typ | 
| 74266 | 64 | val varify_global: TFrees.set -> term -> ((string * sort) * indexname) list * term | 
| 33832 | 65 | val legacy_freeze_thaw_type: typ -> typ * (typ -> typ) | 
| 66 | val legacy_freeze_type: typ -> typ | |
| 67 | val legacy_freeze_thaw: term -> term * (term -> term) | |
| 68 | val legacy_freeze: term -> term | |
| 2964 | 69 | |
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 70 | (*matching and unification*) | 
| 2964 | 71 | exception TYPE_MATCH | 
| 25324 | 72 | type tyenv = (sort * typ) Vartab.table | 
| 26327 | 73 | val lookup: tyenv -> indexname * sort -> typ option | 
| 32648 
143e0b0a6b33
Correct chasing of type variable instantiations during type unification.
 paulson parents: 
32030diff
changeset | 74 | val devar: tyenv -> typ -> typ | 
| 16946 | 75 | val typ_match: tsig -> typ * typ -> tyenv -> tyenv | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 76 | val typ_instance: tsig -> typ * typ -> bool | 
| 16946 | 77 | val raw_match: typ * typ -> tyenv -> tyenv | 
| 19694 | 78 | val raw_matches: typ list * typ list -> tyenv -> tyenv | 
| 56050 
fdccbb97915a
minor performance tuning via fast matching filter;
 wenzelm parents: 
56025diff
changeset | 79 | val could_match: typ * typ -> bool | 
| 
fdccbb97915a
minor performance tuning via fast matching filter;
 wenzelm parents: 
56025diff
changeset | 80 | val could_matches: typ list * typ list -> bool | 
| 16946 | 81 | val raw_instance: typ * typ -> bool | 
| 2964 | 82 | exception TUNIFY | 
| 16946 | 83 | val unify: tsig -> typ * typ -> tyenv * int -> tyenv * int | 
| 84 | val raw_unify: typ * typ -> tyenv -> tyenv | |
| 19696 | 85 | val raw_unifys: typ list * typ list -> tyenv -> tyenv | 
| 17804 | 86 | val could_unify: typ * typ -> bool | 
| 19696 | 87 | val could_unifys: typ list * typ list -> bool | 
| 58949 
e9559088ba29
clarified name of Type.unified, to emphasize its connection to the "unify" family;
 wenzelm parents: 
58942diff
changeset | 88 | val unified: tyenv -> typ * typ -> bool | 
| 0 | 89 | |
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 90 | (*extend and merge type signatures*) | 
| 47005 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 wenzelm parents: 
46649diff
changeset | 91 | val add_class: Context.generic -> binding * class list -> tsig -> tsig | 
| 26669 | 92 | val hide_class: bool -> string -> tsig -> tsig | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 93 | val set_defsort: sort -> tsig -> tsig | 
| 47005 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 wenzelm parents: 
46649diff
changeset | 94 | val add_type: Context.generic -> binding * int -> tsig -> tsig | 
| 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 wenzelm parents: 
46649diff
changeset | 95 | val add_abbrev: Context.generic -> binding * string list * typ -> tsig -> tsig | 
| 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 wenzelm parents: 
46649diff
changeset | 96 | val add_nonterminal: Context.generic -> binding -> tsig -> tsig | 
| 26669 | 97 | val hide_type: bool -> string -> tsig -> tsig | 
| 61262 
7bd1eb4b056e
tuned signature: eliminated pointless type Context.pretty;
 wenzelm parents: 
59885diff
changeset | 98 | val add_arity: Context.generic -> arity -> tsig -> tsig | 
| 
7bd1eb4b056e
tuned signature: eliminated pointless type Context.pretty;
 wenzelm parents: 
59885diff
changeset | 99 | val add_classrel: Context.generic -> class * class -> tsig -> tsig | 
| 
7bd1eb4b056e
tuned signature: eliminated pointless type Context.pretty;
 wenzelm parents: 
59885diff
changeset | 100 | val merge_tsig: Context.generic -> tsig * tsig -> tsig | 
| 2964 | 101 | end; | 
| 102 | ||
| 103 | structure Type: TYPE = | |
| 0 | 104 | struct | 
| 105 | ||
| 39288 | 106 | (** constraints **) | 
| 107 | ||
| 39290 
44e4d8dfd6bf
load type_infer.ML later -- proper context for Type_Infer.infer_types;
 wenzelm parents: 
39289diff
changeset | 108 | (*indicate polymorphic Vars*) | 
| 
44e4d8dfd6bf
load type_infer.ML later -- proper context for Type_Infer.infer_types;
 wenzelm parents: 
39289diff
changeset | 109 | fun mark_polymorphic T = Type ("_polymorphic_", [T]);
 | 
| 
44e4d8dfd6bf
load type_infer.ML later -- proper context for Type_Infer.infer_types;
 wenzelm parents: 
39289diff
changeset | 110 | |
| 39288 | 111 | fun constraint T t = | 
| 112 | if T = dummyT then t | |
| 113 |   else Const ("_type_constraint_", T --> T) $ t;
 | |
| 114 | ||
| 45445 
41e641a870de
pass term positions into check phase, where resulting types are reported accordingly, and eventually shown as tooltips;
 wenzelm parents: 
44116diff
changeset | 115 | fun constraint_type ctxt T = | 
| 
41e641a870de
pass term positions into check phase, where resulting types are reported accordingly, and eventually shown as tooltips;
 wenzelm parents: 
44116diff
changeset | 116 |   let fun err () = error ("Malformed internal type constraint: " ^ Syntax.string_of_typ ctxt T);
 | 
| 
41e641a870de
pass term positions into check phase, where resulting types are reported accordingly, and eventually shown as tooltips;
 wenzelm parents: 
44116diff
changeset | 117 |   in (case T of Type ("fun", [A, B]) => if A = B then A else err () | _ => err ()) end;
 | 
| 
41e641a870de
pass term positions into check phase, where resulting types are reported accordingly, and eventually shown as tooltips;
 wenzelm parents: 
44116diff
changeset | 118 | |
| 39292 
6f085332c7d3
Type_Infer.preterm: eliminated separate Constraint;
 wenzelm parents: 
39290diff
changeset | 119 | fun strip_constraints (Const ("_type_constraint_", _) $ t) = strip_constraints t
 | 
| 
6f085332c7d3
Type_Infer.preterm: eliminated separate Constraint;
 wenzelm parents: 
39290diff
changeset | 120 | | strip_constraints (t $ u) = strip_constraints t $ strip_constraints u | 
| 
6f085332c7d3
Type_Infer.preterm: eliminated separate Constraint;
 wenzelm parents: 
39290diff
changeset | 121 | | strip_constraints (Abs (x, T, t)) = Abs (x, T, strip_constraints t) | 
| 
6f085332c7d3
Type_Infer.preterm: eliminated separate Constraint;
 wenzelm parents: 
39290diff
changeset | 122 | | strip_constraints a = a; | 
| 
6f085332c7d3
Type_Infer.preterm: eliminated separate Constraint;
 wenzelm parents: 
39290diff
changeset | 123 | |
| 42383 
0ae4ad40d7b5
simplified pretty printing context, which is only required for certain kernel operations;
 wenzelm parents: 
42381diff
changeset | 124 | fun appl_error ctxt (Const ("_type_constraint_", Type ("fun", [T, _]))) _ u U =
 | 
| 39289 
92b50c8bb67b
common Type.appl_error, which also covers explicit constraints;
 wenzelm parents: 
39288diff
changeset | 125 | cat_lines | 
| 
92b50c8bb67b
common Type.appl_error, which also covers explicit constraints;
 wenzelm parents: 
39288diff
changeset | 126 | ["Failed to meet type constraint:", "", | 
| 
92b50c8bb67b
common Type.appl_error, which also covers explicit constraints;
 wenzelm parents: 
39288diff
changeset | 127 | Pretty.string_of (Pretty.block | 
| 42383 
0ae4ad40d7b5
simplified pretty printing context, which is only required for certain kernel operations;
 wenzelm parents: 
42381diff
changeset | 128 | [Pretty.str "Term:", Pretty.brk 2, Syntax.pretty_term ctxt u, | 
| 
0ae4ad40d7b5
simplified pretty printing context, which is only required for certain kernel operations;
 wenzelm parents: 
42381diff
changeset | 129 | Pretty.str " ::", Pretty.brk 1, Syntax.pretty_typ ctxt U]), | 
| 39289 
92b50c8bb67b
common Type.appl_error, which also covers explicit constraints;
 wenzelm parents: 
39288diff
changeset | 130 | Pretty.string_of (Pretty.block | 
| 42383 
0ae4ad40d7b5
simplified pretty printing context, which is only required for certain kernel operations;
 wenzelm parents: 
42381diff
changeset | 131 | [Pretty.str "Type:", Pretty.brk 2, Syntax.pretty_typ ctxt T])] | 
| 
0ae4ad40d7b5
simplified pretty printing context, which is only required for certain kernel operations;
 wenzelm parents: 
42381diff
changeset | 132 | | appl_error ctxt t T u U = | 
| 39289 
92b50c8bb67b
common Type.appl_error, which also covers explicit constraints;
 wenzelm parents: 
39288diff
changeset | 133 | cat_lines | 
| 
92b50c8bb67b
common Type.appl_error, which also covers explicit constraints;
 wenzelm parents: 
39288diff
changeset | 134 | ["Type error in application: " ^ | 
| 
92b50c8bb67b
common Type.appl_error, which also covers explicit constraints;
 wenzelm parents: 
39288diff
changeset | 135 | (case T of | 
| 
92b50c8bb67b
common Type.appl_error, which also covers explicit constraints;
 wenzelm parents: 
39288diff
changeset | 136 |             Type ("fun", _) => "incompatible operand type"
 | 
| 
92b50c8bb67b
common Type.appl_error, which also covers explicit constraints;
 wenzelm parents: 
39288diff
changeset | 137 | | _ => "operator not of function type"), | 
| 
92b50c8bb67b
common Type.appl_error, which also covers explicit constraints;
 wenzelm parents: 
39288diff
changeset | 138 | "", | 
| 
92b50c8bb67b
common Type.appl_error, which also covers explicit constraints;
 wenzelm parents: 
39288diff
changeset | 139 | Pretty.string_of (Pretty.block | 
| 42383 
0ae4ad40d7b5
simplified pretty printing context, which is only required for certain kernel operations;
 wenzelm parents: 
42381diff
changeset | 140 | [Pretty.str "Operator:", Pretty.brk 2, Syntax.pretty_term ctxt t, | 
| 
0ae4ad40d7b5
simplified pretty printing context, which is only required for certain kernel operations;
 wenzelm parents: 
42381diff
changeset | 141 | Pretty.str " ::", Pretty.brk 1, Syntax.pretty_typ ctxt T]), | 
| 39289 
92b50c8bb67b
common Type.appl_error, which also covers explicit constraints;
 wenzelm parents: 
39288diff
changeset | 142 | Pretty.string_of (Pretty.block | 
| 42383 
0ae4ad40d7b5
simplified pretty printing context, which is only required for certain kernel operations;
 wenzelm parents: 
42381diff
changeset | 143 | [Pretty.str "Operand:", Pretty.brk 3, Syntax.pretty_term ctxt u, | 
| 
0ae4ad40d7b5
simplified pretty printing context, which is only required for certain kernel operations;
 wenzelm parents: 
42381diff
changeset | 144 | Pretty.str " ::", Pretty.brk 1, Syntax.pretty_typ ctxt U])]; | 
| 39289 
92b50c8bb67b
common Type.appl_error, which also covers explicit constraints;
 wenzelm parents: 
39288diff
changeset | 145 | |
| 39288 | 146 | |
| 147 | ||
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 148 | (** type signatures and certified types **) | 
| 2964 | 149 | |
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 150 | (* type declarations *) | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 151 | |
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 152 | datatype decl = | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 153 | LogicalType of int | | 
| 14989 | 154 | Abbreviation of string list * typ * bool | | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 155 | Nonterminal; | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 156 | |
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 157 | |
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 158 | (* type tsig *) | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 159 | |
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 160 | datatype tsig = | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 161 |   TSig of {
 | 
| 33095 
bbd52d2f8696
renamed NameSpace to Name_Space -- also to emphasize its subtle change in semantics;
 wenzelm parents: 
33094diff
changeset | 162 | classes: Name_Space.T * Sorts.algebra, (*order-sorted algebra of type classes*) | 
| 16370 
033d890fe91f
name space of classes and types maintained in tsig;
 wenzelm parents: 
16340diff
changeset | 163 | default: sort, (*default sort on input*) | 
| 33173 
b8ca12f6681a
eliminated obsolete tags for types/consts -- now handled via name space, in strongly typed fashion;
 wenzelm parents: 
33097diff
changeset | 164 | types: decl Name_Space.table, (*declared types*) | 
| 26641 | 165 | log_types: string list}; (*logical types sorted by number of arguments*) | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 166 | |
| 35669 
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
 wenzelm parents: 
35359diff
changeset | 167 | fun eq_tsig | 
| 
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
 wenzelm parents: 
35359diff
changeset | 168 |    (TSig {classes = classes1, default = default1, types = types1, log_types = _},
 | 
| 
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
 wenzelm parents: 
35359diff
changeset | 169 |     TSig {classes = classes2, default = default2, types = types2, log_types = _}) =
 | 
| 
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
 wenzelm parents: 
35359diff
changeset | 170 | pointer_eq (classes1, classes2) andalso | 
| 
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
 wenzelm parents: 
35359diff
changeset | 171 | default1 = default2 andalso | 
| 
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
 wenzelm parents: 
35359diff
changeset | 172 | pointer_eq (types1, types2); | 
| 
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
 wenzelm parents: 
35359diff
changeset | 173 | |
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 174 | fun rep_tsig (TSig comps) = comps; | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 175 | |
| 26641 | 176 | fun make_tsig (classes, default, types, log_types) = | 
| 177 |   TSig {classes = classes, default = default, types = types, log_types = log_types};
 | |
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 178 | |
| 56056 
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
 wenzelm parents: 
56050diff
changeset | 179 | fun change_base begin (TSig {classes, default, types, log_types}) =
 | 
| 
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
 wenzelm parents: 
56050diff
changeset | 180 | make_tsig (classes, default, Name_Space.change_base begin types, log_types); | 
| 
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
 wenzelm parents: 
56050diff
changeset | 181 | |
| 56139 
b7add947a6ef
more frugal recording of changes: join merely requires information from one side;
 wenzelm parents: 
56056diff
changeset | 182 | fun change_ignore (TSig {classes, default, types, log_types}) =
 | 
| 
b7add947a6ef
more frugal recording of changes: join merely requires information from one side;
 wenzelm parents: 
56056diff
changeset | 183 | make_tsig (classes, default, Name_Space.change_ignore types, log_types); | 
| 
b7add947a6ef
more frugal recording of changes: join merely requires information from one side;
 wenzelm parents: 
56056diff
changeset | 184 | |
| 33094 
ef0d77b1e687
eliminated separate stamp -- NameSpace.define/merge etc. ensure uniqueness already;
 wenzelm parents: 
32784diff
changeset | 185 | fun build_tsig (classes, default, types) = | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 186 | let | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 187 | val log_types = | 
| 56025 | 188 | Name_Space.fold_table (fn (c, LogicalType n) => cons (c, n) | _ => I) types [] | 
| 59058 
a78612c67ec0
renamed "pairself" to "apply2", in accordance to @{apply 2};
 wenzelm parents: 
58949diff
changeset | 189 | |> Library.sort (int_ord o apply2 snd) |> map fst; | 
| 33094 
ef0d77b1e687
eliminated separate stamp -- NameSpace.define/merge etc. ensure uniqueness already;
 wenzelm parents: 
32784diff
changeset | 190 | in make_tsig (classes, default, types, log_types) end; | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 191 | |
| 26641 | 192 | fun map_tsig f (TSig {classes, default, types, log_types = _}) =
 | 
| 19642 | 193 | build_tsig (f (classes, default, types)); | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 194 | |
| 16370 
033d890fe91f
name space of classes and types maintained in tsig;
 wenzelm parents: 
16340diff
changeset | 195 | val empty_tsig = | 
| 50201 
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
 wenzelm parents: 
49687diff
changeset | 196 | build_tsig ((Name_Space.empty Markup.classN, Sorts.empty_algebra), [], | 
| 
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
 wenzelm parents: 
49687diff
changeset | 197 | Name_Space.empty_table Markup.type_nameN); | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 198 | |
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 199 | |
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 200 | (* classes and sorts *) | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 201 | |
| 35669 
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
 wenzelm parents: 
35359diff
changeset | 202 | val class_space = #1 o #classes o rep_tsig; | 
| 
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
 wenzelm parents: 
35359diff
changeset | 203 | |
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 204 | fun defaultS (TSig {default, ...}) = default;
 | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 205 | fun logical_types (TSig {log_types, ...}) = log_types;
 | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 206 | |
| 16370 
033d890fe91f
name space of classes and types maintained in tsig;
 wenzelm parents: 
16340diff
changeset | 207 | fun eq_sort (TSig {classes, ...}) = Sorts.sort_eq (#2 classes);
 | 
| 
033d890fe91f
name space of classes and types maintained in tsig;
 wenzelm parents: 
16340diff
changeset | 208 | fun subsort (TSig {classes, ...}) = Sorts.sort_le (#2 classes);
 | 
| 19642 | 209 | fun of_sort (TSig {classes, ...}) = Sorts.of_sort (#2 classes);
 | 
| 19464 | 210 | fun inter_sort (TSig {classes, ...}) = Sorts.inter_sort (#2 classes);
 | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 211 | |
| 45595 | 212 | fun cert_class (TSig {classes = (_, algebra), ...}) c =
 | 
| 213 | if can (Graph.get_entry (Sorts.classes_of algebra)) c then c | |
| 214 |   else raise TYPE ("Undeclared class: " ^ quote c, [], []);
 | |
| 215 | ||
| 216 | val cert_sort = map o cert_class; | |
| 217 | ||
| 36447 | 218 | fun minimize_sort (TSig {classes, ...}) = Sorts.minimize_sort (#2 classes);
 | 
| 19515 
9f650083da65
build classes/arities: refer to operations in sorts.ML;
 wenzelm parents: 
19464diff
changeset | 219 | |
| 32784 | 220 | fun witness_sorts (TSig {classes, log_types, ...}) =
 | 
| 19642 | 221 | Sorts.witness_sorts (#2 classes) log_types; | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 222 | |
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 223 | |
| 24274 
cb9236269af1
type mode: models certification mode (default, syntax, abbrev);
 wenzelm parents: 
23655diff
changeset | 224 | (* certification mode *) | 
| 
cb9236269af1
type mode: models certification mode (default, syntax, abbrev);
 wenzelm parents: 
23655diff
changeset | 225 | |
| 
cb9236269af1
type mode: models certification mode (default, syntax, abbrev);
 wenzelm parents: 
23655diff
changeset | 226 | datatype mode = Mode of {normalize: bool, logical: bool};
 | 
| 
cb9236269af1
type mode: models certification mode (default, syntax, abbrev);
 wenzelm parents: 
23655diff
changeset | 227 | |
| 
cb9236269af1
type mode: models certification mode (default, syntax, abbrev);
 wenzelm parents: 
23655diff
changeset | 228 | val mode_default = Mode {normalize = true, logical = true};
 | 
| 
cb9236269af1
type mode: models certification mode (default, syntax, abbrev);
 wenzelm parents: 
23655diff
changeset | 229 | val mode_syntax = Mode {normalize = true, logical = false};
 | 
| 
cb9236269af1
type mode: models certification mode (default, syntax, abbrev);
 wenzelm parents: 
23655diff
changeset | 230 | val mode_abbrev = Mode {normalize = false, logical = false};
 | 
| 
cb9236269af1
type mode: models certification mode (default, syntax, abbrev);
 wenzelm parents: 
23655diff
changeset | 231 | |
| 33519 | 232 | structure Mode = Proof_Data | 
| 24484 | 233 | ( | 
| 234 | type T = mode; | |
| 235 | fun init _ = mode_default; | |
| 236 | ); | |
| 237 | ||
| 238 | val get_mode = Mode.get; | |
| 239 | fun set_mode mode = Mode.map (K mode); | |
| 240 | fun restore_mode ctxt = set_mode (get_mode ctxt); | |
| 241 | ||
| 24274 
cb9236269af1
type mode: models certification mode (default, syntax, abbrev);
 wenzelm parents: 
23655diff
changeset | 242 | |
| 35669 
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
 wenzelm parents: 
35359diff
changeset | 243 | (* types *) | 
| 
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
 wenzelm parents: 
35359diff
changeset | 244 | |
| 56025 | 245 | val type_space = Name_Space.space_of_table o #types o rep_tsig; | 
| 35669 
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
 wenzelm parents: 
35359diff
changeset | 246 | |
| 56025 | 247 | fun type_alias naming binding name = map_tsig (fn (classes, default, types) => | 
| 77979 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 wenzelm parents: 
77970diff
changeset | 248 | (classes, default, (Name_Space.alias_table naming binding name types))); | 
| 35680 | 249 | |
| 27313 | 250 | |
| 251 | fun undecl_type c = "Undeclared type constructor: " ^ quote c; | |
| 252 | ||
| 59884 | 253 | fun lookup_type (TSig {types, ...}) = Name_Space.lookup types;
 | 
| 27313 | 254 | |
| 55956 
94d384d621b0
reject internal term names outright, and complete consts instead;
 wenzelm parents: 
55922diff
changeset | 255 | fun check_decl context (TSig {types, ...}) (c, pos) =
 | 
| 
94d384d621b0
reject internal term names outright, and complete consts instead;
 wenzelm parents: 
55922diff
changeset | 256 | Name_Space.check_reports context types (c, [pos]); | 
| 55841 
a232c0ff3c20
prefer Name_Space.check with its builtin reports (including completion);
 wenzelm parents: 
51930diff
changeset | 257 | |
| 42468 | 258 | fun the_decl tsig (c, pos) = | 
| 35359 
3ec03a3cd9d0
provide direct access to the different kinds of type declarations;
 wenzelm parents: 
34272diff
changeset | 259 | (case lookup_type tsig c of | 
| 48992 | 260 | NONE => error (undecl_type c ^ Position.here pos) | 
| 35359 
3ec03a3cd9d0
provide direct access to the different kinds of type declarations;
 wenzelm parents: 
34272diff
changeset | 261 | | SOME decl => decl); | 
| 
3ec03a3cd9d0
provide direct access to the different kinds of type declarations;
 wenzelm parents: 
34272diff
changeset | 262 | |
| 27313 | 263 | |
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 264 | (* certified types *) | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 265 | |
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 266 | fun bad_nargs t = "Bad number of arguments for type constructor: " ^ quote t; | 
| 14830 
faa4865ba1ce
removed norm_typ; improved output; refer to Pretty.pp;
 wenzelm parents: 
14790diff
changeset | 267 | |
| 14998 | 268 | local | 
| 269 | ||
| 270 | fun inst_typ env (Type (c, Ts)) = Type (c, map (inst_typ env) Ts) | |
| 18957 | 271 | | inst_typ env (T as TFree (x, _)) = the_default T (AList.lookup (op =) env x) | 
| 14998 | 272 | | inst_typ _ T = T; | 
| 273 | ||
| 24274 
cb9236269af1
type mode: models certification mode (default, syntax, abbrev);
 wenzelm parents: 
23655diff
changeset | 274 | in | 
| 
cb9236269af1
type mode: models certification mode (default, syntax, abbrev);
 wenzelm parents: 
23655diff
changeset | 275 | |
| 
cb9236269af1
type mode: models certification mode (default, syntax, abbrev);
 wenzelm parents: 
23655diff
changeset | 276 | fun cert_typ_mode (Mode {normalize, logical}) tsig ty =
 | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 277 | let | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 278 | fun err msg = raise TYPE (msg, [ty], []); | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 279 | |
| 24274 
cb9236269af1
type mode: models certification mode (default, syntax, abbrev);
 wenzelm parents: 
23655diff
changeset | 280 | val check_logical = | 
| 
cb9236269af1
type mode: models certification mode (default, syntax, abbrev);
 wenzelm parents: 
23655diff
changeset | 281 |       if logical then fn c => err ("Illegal occurrence of syntactic type: " ^ quote c)
 | 
| 
cb9236269af1
type mode: models certification mode (default, syntax, abbrev);
 wenzelm parents: 
23655diff
changeset | 282 | else fn _ => (); | 
| 14989 | 283 | |
| 284 | fun cert (T as Type (c, Ts)) = | |
| 285 | let | |
| 286 | val Ts' = map cert Ts; | |
| 287 | fun nargs n = if length Ts <> n then err (bad_nargs c) else (); | |
| 288 | in | |
| 42468 | 289 | (case the_decl tsig (c, Position.none) of | 
| 35359 
3ec03a3cd9d0
provide direct access to the different kinds of type declarations;
 wenzelm parents: 
34272diff
changeset | 290 | LogicalType n => (nargs n; Type (c, Ts')) | 
| 
3ec03a3cd9d0
provide direct access to the different kinds of type declarations;
 wenzelm parents: 
34272diff
changeset | 291 | | Abbreviation (vs, U, syn) => | 
| 24274 
cb9236269af1
type mode: models certification mode (default, syntax, abbrev);
 wenzelm parents: 
23655diff
changeset | 292 | (nargs (length vs); | 
| 
cb9236269af1
type mode: models certification mode (default, syntax, abbrev);
 wenzelm parents: 
23655diff
changeset | 293 | if syn then check_logical c else (); | 
| 14993 | 294 | if normalize then inst_typ (vs ~~ Ts') U | 
| 14989 | 295 | else Type (c, Ts')) | 
| 35359 
3ec03a3cd9d0
provide direct access to the different kinds of type declarations;
 wenzelm parents: 
34272diff
changeset | 296 | | Nonterminal => (nargs 0; check_logical c; T)) | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 297 | end | 
| 19515 
9f650083da65
build classes/arities: refer to operations in sorts.ML;
 wenzelm parents: 
19464diff
changeset | 298 | | cert (TFree (x, S)) = TFree (x, cert_sort tsig S) | 
| 14989 | 299 | | cert (TVar (xi as (_, i), S)) = | 
| 14993 | 300 | if i < 0 then | 
| 301 |             err ("Malformed type variable: " ^ quote (Term.string_of_vname xi))
 | |
| 19515 
9f650083da65
build classes/arities: refer to operations in sorts.ML;
 wenzelm parents: 
19464diff
changeset | 302 | else TVar (xi, cert_sort tsig S); | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 303 | |
| 14989 | 304 | val ty' = cert ty; | 
| 14993 | 305 | in if ty = ty' then ty else ty' end; (*avoid copying of already normal type*) | 
| 14830 
faa4865ba1ce
removed norm_typ; improved output; refer to Pretty.pp;
 wenzelm parents: 
14790diff
changeset | 306 | |
| 24274 
cb9236269af1
type mode: models certification mode (default, syntax, abbrev);
 wenzelm parents: 
23655diff
changeset | 307 | val cert_typ = cert_typ_mode mode_default; | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 308 | |
| 14998 | 309 | end; | 
| 310 | ||
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 311 | |
| 19464 | 312 | (* type arities *) | 
| 313 | ||
| 27302 | 314 | fun arity_number tsig a = | 
| 315 | (case lookup_type tsig a of | |
| 33173 
b8ca12f6681a
eliminated obsolete tags for types/consts -- now handled via name space, in strongly typed fashion;
 wenzelm parents: 
33097diff
changeset | 316 | SOME (LogicalType n) => n | 
| 19464 | 317 | | _ => error (undecl_type a)); | 
| 318 | ||
| 319 | fun arity_sorts _ tsig a [] = replicate (arity_number tsig a) [] | |
| 61262 
7bd1eb4b056e
tuned signature: eliminated pointless type Context.pretty;
 wenzelm parents: 
59885diff
changeset | 320 |   | arity_sorts context (TSig {classes, ...}) a S =
 | 
| 47005 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 wenzelm parents: 
46649diff
changeset | 321 | Sorts.mg_domain (#2 classes) a S | 
| 61262 
7bd1eb4b056e
tuned signature: eliminated pointless type Context.pretty;
 wenzelm parents: 
59885diff
changeset | 322 | handle Sorts.CLASS_ERROR err => error (Sorts.class_error context err); | 
| 19464 | 323 | |
| 324 | ||
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 325 | |
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 326 | (** special treatment of type vars **) | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 327 | |
| 36621 
2fd4e2c76636
proof terms for strip_shyps, based on the version by krauss/schropp with some notable differences:
 wenzelm parents: 
36450diff
changeset | 328 | (* sort_of_atyp *) | 
| 
2fd4e2c76636
proof terms for strip_shyps, based on the version by krauss/schropp with some notable differences:
 wenzelm parents: 
36450diff
changeset | 329 | |
| 
2fd4e2c76636
proof terms for strip_shyps, based on the version by krauss/schropp with some notable differences:
 wenzelm parents: 
36450diff
changeset | 330 | fun sort_of_atyp (TFree (_, S)) = S | 
| 
2fd4e2c76636
proof terms for strip_shyps, based on the version by krauss/schropp with some notable differences:
 wenzelm parents: 
36450diff
changeset | 331 | | sort_of_atyp (TVar (_, S)) = S | 
| 
2fd4e2c76636
proof terms for strip_shyps, based on the version by krauss/schropp with some notable differences:
 wenzelm parents: 
36450diff
changeset | 332 |   | sort_of_atyp T = raise TYPE ("sort_of_atyp", [T], []);
 | 
| 
2fd4e2c76636
proof terms for strip_shyps, based on the version by krauss/schropp with some notable differences:
 wenzelm parents: 
36450diff
changeset | 333 | |
| 
2fd4e2c76636
proof terms for strip_shyps, based on the version by krauss/schropp with some notable differences:
 wenzelm parents: 
36450diff
changeset | 334 | |
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 335 | (* strip_sorts *) | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 336 | |
| 49687 
4b9034f089eb
use explicit Type.strip_sorts_dummy to suppress sort constraints in output;
 wenzelm parents: 
48992diff
changeset | 337 | val strip_sorts = map_atyps | 
| 
4b9034f089eb
use explicit Type.strip_sorts_dummy to suppress sort constraints in output;
 wenzelm parents: 
48992diff
changeset | 338 | (fn TFree (x, _) => TFree (x, []) | 
| 
4b9034f089eb
use explicit Type.strip_sorts_dummy to suppress sort constraints in output;
 wenzelm parents: 
48992diff
changeset | 339 | | TVar (xi, _) => TVar (xi, [])); | 
| 
4b9034f089eb
use explicit Type.strip_sorts_dummy to suppress sort constraints in output;
 wenzelm parents: 
48992diff
changeset | 340 | |
| 
4b9034f089eb
use explicit Type.strip_sorts_dummy to suppress sort constraints in output;
 wenzelm parents: 
48992diff
changeset | 341 | val strip_sorts_dummy = map_atyps | 
| 
4b9034f089eb
use explicit Type.strip_sorts_dummy to suppress sort constraints in output;
 wenzelm parents: 
48992diff
changeset | 342 | (fn TFree (x, _) => TFree (x, dummyS) | 
| 
4b9034f089eb
use explicit Type.strip_sorts_dummy to suppress sort constraints in output;
 wenzelm parents: 
48992diff
changeset | 343 | | TVar (xi, _) => TVar (xi, dummyS)); | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 344 | |
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 345 | |
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 346 | (* no_tvars *) | 
| 621 | 347 | |
| 348 | fun no_tvars T = | |
| 29275 
9fa69e3858d6
moved old add_type_XXX, add_term_XXX etc. to structure OldTerm;
 wenzelm parents: 
29269diff
changeset | 349 | (case Term.add_tvarsT T [] of [] => T | 
| 12501 | 350 |   | vs => raise TYPE ("Illegal schematic type variable(s): " ^
 | 
| 29275 
9fa69e3858d6
moved old add_type_XXX, add_term_XXX etc. to structure OldTerm;
 wenzelm parents: 
29269diff
changeset | 351 | commas_quote (map (Term.string_of_vname o #1) (rev vs)), [T], [])); | 
| 621 | 352 | |
| 7641 | 353 | |
| 35845 
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
 wenzelm parents: 
35680diff
changeset | 354 | (* varify_global *) | 
| 621 | 355 | |
| 35845 
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
 wenzelm parents: 
35680diff
changeset | 356 | fun varify_global fixed t = | 
| 621 | 357 | let | 
| 74233 | 358 | val fs = | 
| 74234 | 359 | build (t |> (Term.fold_types o Term.fold_atyps) | 
| 74266 | 360 | (fn TFree v => if TFrees.defined fixed v then I else insert (op =) v | _ => I)); | 
| 74411 | 361 | val used = | 
| 362 | Name.build_context (t |> | |
| 363 | (fold_types o fold_atyps) (fn TVar ((a, _), _) => Name.declare a | _ => I)); | |
| 43326 
47cf4bc789aa
simplified Name.variant -- discontinued builtin fold_map;
 wenzelm parents: 
43324diff
changeset | 364 | val fmap = fs ~~ map (rpair 0) (#1 (fold_map Name.variant (map fst fs) used)); | 
| 32784 | 365 | fun thaw (f as (_, S)) = | 
| 17184 | 366 | (case AList.lookup (op =) fmap f of | 
| 15531 | 367 | NONE => TFree f | 
| 16946 | 368 | | SOME xi => TVar (xi, S)); | 
| 21116 | 369 | in (fmap, map_types (map_type_tfree thaw) t) end; | 
| 2964 | 370 | |
| 371 | ||
| 7641 | 372 | (* freeze_thaw: freeze TVars in a term; return the "thaw" inverse *) | 
| 3411 
163f8f4a42d7
Removal of freeze_vars and thaw_vars.  New freeze_thaw
 paulson parents: 
3175diff
changeset | 373 | |
| 7641 | 374 | local | 
| 375 | ||
| 44116 
c70257b4cb7e
avoid OldTerm operations -- with subtle changes of semantics;
 wenzelm parents: 
43552diff
changeset | 376 | fun new_name ix (pairs, used) = | 
| 43324 
2b47822868e4
discontinued Name.variant to emphasize that this is old-style / indirect;
 wenzelm parents: 
42468diff
changeset | 377 | let val v = singleton (Name.variant_list used) (string_of_indexname ix) | 
| 16289 | 378 | in ((ix, v) :: pairs, v :: used) end; | 
| 621 | 379 | |
| 16289 | 380 | fun freeze_one alist (ix, sort) = | 
| 17184 | 381 | TFree (the (AList.lookup (op =) alist ix), sort) | 
| 51930 
52fd62618631
prefer explicitly qualified exceptions, which is particular important for robust handlers;
 wenzelm parents: 
51701diff
changeset | 382 | handle Option.Option => | 
| 3790 | 383 |       raise TYPE ("Failure during freezing of ?" ^ string_of_indexname ix, [], []);
 | 
| 2964 | 384 | |
| 17184 | 385 | fun thaw_one alist (a, sort) = TVar (the (AList.lookup (op =) alist a), sort) | 
| 51930 
52fd62618631
prefer explicitly qualified exceptions, which is particular important for robust handlers;
 wenzelm parents: 
51701diff
changeset | 386 | handle Option.Option => TFree (a, sort); | 
| 416 | 387 | |
| 10495 | 388 | in | 
| 389 | ||
| 33832 | 390 | fun legacy_freeze_thaw_type T = | 
| 7641 | 391 | let | 
| 44116 
c70257b4cb7e
avoid OldTerm operations -- with subtle changes of semantics;
 wenzelm parents: 
43552diff
changeset | 392 | val used = Term.add_tfree_namesT T []; | 
| 
c70257b4cb7e
avoid OldTerm operations -- with subtle changes of semantics;
 wenzelm parents: 
43552diff
changeset | 393 | val (alist, _) = fold_rev new_name (map #1 (Term.add_tvarsT T [])) ([], used); | 
| 7641 | 394 | in (map_type_tvar (freeze_one alist) T, map_type_tfree (thaw_one (map swap alist))) end; | 
| 395 | ||
| 33832 | 396 | val legacy_freeze_type = #1 o legacy_freeze_thaw_type; | 
| 16289 | 397 | |
| 33832 | 398 | fun legacy_freeze_thaw t = | 
| 7641 | 399 | let | 
| 44116 
c70257b4cb7e
avoid OldTerm operations -- with subtle changes of semantics;
 wenzelm parents: 
43552diff
changeset | 400 | val used = Term.add_tfree_names t []; | 
| 
c70257b4cb7e
avoid OldTerm operations -- with subtle changes of semantics;
 wenzelm parents: 
43552diff
changeset | 401 | val (alist, _) = fold_rev new_name (map #1 (Term.add_tvars t [])) ([], used); | 
| 7641 | 402 | in | 
| 403 | (case alist of | |
| 404 | [] => (t, fn x => x) (*nothing to do!*) | |
| 20548 
8ef25fe585a8
renamed Term.map_term_types to Term.map_types (cf. Term.fold_types);
 wenzelm parents: 
20071diff
changeset | 405 | | _ => (map_types (map_type_tvar (freeze_one alist)) t, | 
| 
8ef25fe585a8
renamed Term.map_term_types to Term.map_types (cf. Term.fold_types);
 wenzelm parents: 
20071diff
changeset | 406 | map_types (map_type_tfree (thaw_one (map swap alist))))) | 
| 7641 | 407 | end; | 
| 408 | ||
| 33832 | 409 | val legacy_freeze = #1 o legacy_freeze_thaw; | 
| 16289 | 410 | |
| 7641 | 411 | end; | 
| 412 | ||
| 256 | 413 | |
| 414 | ||
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 415 | (** matching and unification of types **) | 
| 8899 | 416 | |
| 15797 | 417 | type tyenv = (sort * typ) Vartab.table; | 
| 256 | 418 | |
| 51701 
1e29891759c4
tuned exceptions -- avoid composing error messages in low-level situations;
 wenzelm parents: 
50201diff
changeset | 419 | fun tvar_clash ixn S S' = | 
| 
1e29891759c4
tuned exceptions -- avoid composing error messages in low-level situations;
 wenzelm parents: 
50201diff
changeset | 420 |   raise TYPE ("Type variable has two distinct sorts", [TVar (ixn, S), TVar (ixn, S')], []);
 | 
| 0 | 421 | |
| 26327 | 422 | fun lookup tye (ixn, S) = | 
| 17412 | 423 | (case Vartab.lookup tye ixn of | 
| 15797 | 424 | NONE => NONE | 
| 16289 | 425 | | SOME (S', T) => if S = S' then SOME T else tvar_clash ixn S S'); | 
| 426 | ||
| 0 | 427 | |
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 428 | (* matching *) | 
| 0 | 429 | |
| 2964 | 430 | exception TYPE_MATCH; | 
| 0 | 431 | |
| 16946 | 432 | fun typ_match tsig = | 
| 2964 | 433 | let | 
| 58942 
97f0ba373b1a
recovered type matching, which was broken in 8a765db7e0f8 (see also 8a765db7e0f8, 2db1d3d2ed54);
 wenzelm parents: 
56139diff
changeset | 434 | fun match (TVar (v, S), T) subs = | 
| 26327 | 435 | (case lookup subs (v, S) of | 
| 15531 | 436 | NONE => | 
| 58942 
97f0ba373b1a
recovered type matching, which was broken in 8a765db7e0f8 (see also 8a765db7e0f8, 2db1d3d2ed54);
 wenzelm parents: 
56139diff
changeset | 437 | if of_sort tsig (T, S) then Vartab.update_new (v, (S, T)) subs | 
| 14993 | 438 | else raise TYPE_MATCH | 
| 15531 | 439 | | SOME U => if U = T then subs else raise TYPE_MATCH) | 
| 16340 | 440 | | match (Type (a, Ts), Type (b, Us)) subs = | 
| 2964 | 441 | if a <> b then raise TYPE_MATCH | 
| 16885 | 442 | else matches (Ts, Us) subs | 
| 16340 | 443 | | match (TFree x, TFree y) subs = | 
| 2964 | 444 | if x = y then subs else raise TYPE_MATCH | 
| 16885 | 445 | | match _ _ = raise TYPE_MATCH | 
| 446 | and matches (T :: Ts, U :: Us) subs = matches (Ts, Us) (match (T, U) subs) | |
| 447 | | matches _ subs = subs; | |
| 16946 | 448 | in match end; | 
| 0 | 449 | |
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 450 | fun typ_instance tsig (T, U) = | 
| 74232 | 451 | (Vartab.build (typ_match tsig (U, T)); true) handle TYPE_MATCH => false; | 
| 16946 | 452 | |
| 453 | (*purely structural matching*) | |
| 58942 
97f0ba373b1a
recovered type matching, which was broken in 8a765db7e0f8 (see also 8a765db7e0f8, 2db1d3d2ed54);
 wenzelm parents: 
56139diff
changeset | 454 | fun raw_match (TVar (v, S), T) subs = | 
| 26327 | 455 | (case lookup subs (v, S) of | 
| 58942 
97f0ba373b1a
recovered type matching, which was broken in 8a765db7e0f8 (see also 8a765db7e0f8, 2db1d3d2ed54);
 wenzelm parents: 
56139diff
changeset | 456 | NONE => Vartab.update_new (v, (S, T)) subs | 
| 16946 | 457 | | SOME U => if U = T then subs else raise TYPE_MATCH) | 
| 458 | | raw_match (Type (a, Ts), Type (b, Us)) subs = | |
| 459 | if a <> b then raise TYPE_MATCH | |
| 460 | else raw_matches (Ts, Us) subs | |
| 461 | | raw_match (TFree x, TFree y) subs = | |
| 462 | if x = y then subs else raise TYPE_MATCH | |
| 463 | | raw_match _ _ = raise TYPE_MATCH | |
| 464 | and raw_matches (T :: Ts, U :: Us) subs = raw_matches (Ts, Us) (raw_match (T, U) subs) | |
| 19694 | 465 | | raw_matches ([], []) subs = subs | 
| 466 | | raw_matches _ _ = raise TYPE_MATCH; | |
| 16946 | 467 | |
| 56050 
fdccbb97915a
minor performance tuning via fast matching filter;
 wenzelm parents: 
56025diff
changeset | 468 | (*fast matching filter*) | 
| 
fdccbb97915a
minor performance tuning via fast matching filter;
 wenzelm parents: 
56025diff
changeset | 469 | fun could_match (Type (a, Ts), Type (b, Us)) = a = b andalso could_matches (Ts, Us) | 
| 
fdccbb97915a
minor performance tuning via fast matching filter;
 wenzelm parents: 
56025diff
changeset | 470 | | could_match (TFree (a, _), TFree (b, _)) = a = b | 
| 
fdccbb97915a
minor performance tuning via fast matching filter;
 wenzelm parents: 
56025diff
changeset | 471 | | could_match (TVar _, _) = true | 
| 
fdccbb97915a
minor performance tuning via fast matching filter;
 wenzelm parents: 
56025diff
changeset | 472 | | could_match _ = false | 
| 
fdccbb97915a
minor performance tuning via fast matching filter;
 wenzelm parents: 
56025diff
changeset | 473 | and could_matches (T :: Ts, U :: Us) = could_match (T, U) andalso could_matches (Ts, Us) | 
| 
fdccbb97915a
minor performance tuning via fast matching filter;
 wenzelm parents: 
56025diff
changeset | 474 | | could_matches ([], []) = true | 
| 
fdccbb97915a
minor performance tuning via fast matching filter;
 wenzelm parents: 
56025diff
changeset | 475 | | could_matches _ = false; | 
| 
fdccbb97915a
minor performance tuning via fast matching filter;
 wenzelm parents: 
56025diff
changeset | 476 | |
| 16946 | 477 | fun raw_instance (T, U) = | 
| 56050 
fdccbb97915a
minor performance tuning via fast matching filter;
 wenzelm parents: 
56025diff
changeset | 478 | if could_match (U, T) then | 
| 74232 | 479 | (Vartab.build (raw_match (U, T)); true) handle TYPE_MATCH => false | 
| 56050 
fdccbb97915a
minor performance tuning via fast matching filter;
 wenzelm parents: 
56025diff
changeset | 480 | else false; | 
| 2964 | 481 | |
| 0 | 482 | |
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 483 | (* unification *) | 
| 2964 | 484 | |
| 0 | 485 | exception TUNIFY; | 
| 486 | ||
| 26641 | 487 | (*occurs check*) | 
| 2964 | 488 | fun occurs v tye = | 
| 489 | let | |
| 490 | fun occ (Type (_, Ts)) = exists occ Ts | |
| 491 | | occ (TFree _) = false | |
| 15797 | 492 | | occ (TVar (w, S)) = | 
| 29269 
5c25a2012975
moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
 wenzelm parents: 
29260diff
changeset | 493 | Term.eq_ix (v, w) orelse | 
| 26327 | 494 | (case lookup tye (w, S) of | 
| 15531 | 495 | NONE => false | 
| 496 | | SOME U => occ U); | |
| 0 | 497 | in occ end; | 
| 498 | ||
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 499 | (*chase variable assignments; if devar returns a type var then it must be unassigned*) | 
| 16885 | 500 | fun devar tye (T as TVar v) = | 
| 26327 | 501 | (case lookup tye v of | 
| 16885 | 502 | SOME U => devar tye U | 
| 15531 | 503 | | NONE => T) | 
| 32784 | 504 | | devar _ T = T; | 
| 0 | 505 | |
| 17804 | 506 | (*order-sorted unification*) | 
| 32784 | 507 | fun unify (TSig {classes = (_, classes), ...}) TU (tyenv, maxidx) =
 | 
| 2964 | 508 | let | 
| 32738 | 509 | val tyvar_count = Unsynchronized.ref maxidx; | 
| 510 | fun gen_tyvar S = TVar ((Name.aT, Unsynchronized.inc tyvar_count), S); | |
| 2964 | 511 | |
| 19642 | 512 | fun mg_domain a S = Sorts.mg_domain classes a S | 
| 513 | handle Sorts.CLASS_ERROR _ => raise TUNIFY; | |
| 2964 | 514 | |
| 16885 | 515 | fun meet (_, []) tye = tye | 
| 516 | | meet (TVar (xi, S'), S) tye = | |
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 517 | if Sorts.sort_le classes (S', S) then tye | 
| 17412 | 518 | else Vartab.update_new | 
| 17221 | 519 | (xi, (S', gen_tyvar (Sorts.inter_sort classes (S', S)))) tye | 
| 16885 | 520 | | meet (TFree (_, S'), S) tye = | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 521 | if Sorts.sort_le classes (S', S) then tye | 
| 2964 | 522 | else raise TUNIFY | 
| 16885 | 523 | | meet (Type (a, Ts), S) tye = meets (Ts, mg_domain a S) tye | 
| 524 | and meets (T :: Ts, S :: Ss) tye = meets (Ts, Ss) (meet (devar tye T, S) tye) | |
| 525 | | meets _ tye = tye; | |
| 2964 | 526 | |
| 16885 | 527 | fun unif (ty1, ty2) tye = | 
| 528 | (case (devar tye ty1, devar tye ty2) of | |
| 2964 | 529 | (T as TVar (v, S1), U as TVar (w, S2)) => | 
| 29269 
5c25a2012975
moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
 wenzelm parents: 
29260diff
changeset | 530 | if Term.eq_ix (v, w) then | 
| 15797 | 531 | if S1 = S2 then tye else tvar_clash v S1 S2 | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 532 | else if Sorts.sort_le classes (S1, S2) then | 
| 17412 | 533 | Vartab.update_new (w, (S2, T)) tye | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 534 | else if Sorts.sort_le classes (S2, S1) then | 
| 17412 | 535 | Vartab.update_new (v, (S1, U)) tye | 
| 2964 | 536 | else | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 537 | let val S = gen_tyvar (Sorts.inter_sort classes (S1, S2)) in | 
| 17412 | 538 | Vartab.update_new (v, (S1, S)) (Vartab.update_new (w, (S2, S)) tye) | 
| 2964 | 539 | end | 
| 540 | | (TVar (v, S), T) => | |
| 541 | if occurs v tye T then raise TUNIFY | |
| 17412 | 542 | else meet (T, S) (Vartab.update_new (v, (S, T)) tye) | 
| 2964 | 543 | | (T, TVar (v, S)) => | 
| 544 | if occurs v tye T then raise TUNIFY | |
| 17412 | 545 | else meet (T, S) (Vartab.update_new (v, (S, T)) tye) | 
| 2964 | 546 | | (Type (a, Ts), Type (b, Us)) => | 
| 547 | if a <> b then raise TUNIFY | |
| 16885 | 548 | else unifs (Ts, Us) tye | 
| 549 | | (T, U) => if T = U then tye else raise TUNIFY) | |
| 550 | and unifs (T :: Ts, U :: Us) tye = unifs (Ts, Us) (unif (T, U) tye) | |
| 551 | | unifs _ tye = tye; | |
| 552 | in (unif TU tyenv, ! tyvar_count) end; | |
| 0 | 553 | |
| 16946 | 554 | (*purely structural unification*) | 
| 555 | fun raw_unify (ty1, ty2) tye = | |
| 556 | (case (devar tye ty1, devar tye ty2) of | |
| 32784 | 557 | (T as TVar (v, S1), TVar (w, S2)) => | 
| 29269 
5c25a2012975
moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
 wenzelm parents: 
29260diff
changeset | 558 | if Term.eq_ix (v, w) then | 
| 16946 | 559 | if S1 = S2 then tye else tvar_clash v S1 S2 | 
| 17412 | 560 | else Vartab.update_new (w, (S2, T)) tye | 
| 16946 | 561 | | (TVar (v, S), T) => | 
| 562 | if occurs v tye T then raise TUNIFY | |
| 17412 | 563 | else Vartab.update_new (v, (S, T)) tye | 
| 16946 | 564 | | (T, TVar (v, S)) => | 
| 565 | if occurs v tye T then raise TUNIFY | |
| 17412 | 566 | else Vartab.update_new (v, (S, T)) tye | 
| 16946 | 567 | | (Type (a, Ts), Type (b, Us)) => | 
| 568 | if a <> b then raise TUNIFY | |
| 569 | else raw_unifys (Ts, Us) tye | |
| 570 | | (T, U) => if T = U then tye else raise TUNIFY) | |
| 571 | and raw_unifys (T :: Ts, U :: Us) tye = raw_unifys (Ts, Us) (raw_unify (T, U) tye) | |
| 19696 | 572 | | raw_unifys ([], []) tye = tye | 
| 573 | | raw_unifys _ _ = raise TUNIFY; | |
| 16946 | 574 | |
| 17804 | 575 | (*fast unification filter*) | 
| 576 | fun could_unify (Type (a, Ts), Type (b, Us)) = a = b andalso could_unifys (Ts, Us) | |
| 577 | | could_unify (TFree (a, _), TFree (b, _)) = a = b | |
| 578 | | could_unify (TVar _, _) = true | |
| 579 | | could_unify (_, TVar _) = true | |
| 580 | | could_unify _ = false | |
| 581 | and could_unifys (T :: Ts, U :: Us) = could_unify (T, U) andalso could_unifys (Ts, Us) | |
| 19696 | 582 | | could_unifys ([], []) = true | 
| 583 | | could_unifys _ = false; | |
| 450 | 584 | |
| 17804 | 585 | (*equality with respect to a type environment*) | 
| 58949 
e9559088ba29
clarified name of Type.unified, to emphasize its connection to the "unify" family;
 wenzelm parents: 
58942diff
changeset | 586 | fun unified tye = | 
| 
e9559088ba29
clarified name of Type.unified, to emphasize its connection to the "unify" family;
 wenzelm parents: 
58942diff
changeset | 587 | let | 
| 
e9559088ba29
clarified name of Type.unified, to emphasize its connection to the "unify" family;
 wenzelm parents: 
58942diff
changeset | 588 | fun unif (T, T') = | 
| 
e9559088ba29
clarified name of Type.unified, to emphasize its connection to the "unify" family;
 wenzelm parents: 
58942diff
changeset | 589 | (case (devar tye T, devar tye T') of | 
| 
e9559088ba29
clarified name of Type.unified, to emphasize its connection to the "unify" family;
 wenzelm parents: 
58942diff
changeset | 590 | (Type (s, Ts), Type (s', Ts')) => s = s' andalso unifs (Ts, Ts') | 
| 
e9559088ba29
clarified name of Type.unified, to emphasize its connection to the "unify" family;
 wenzelm parents: 
58942diff
changeset | 591 | | (U, U') => U = U') | 
| 
e9559088ba29
clarified name of Type.unified, to emphasize its connection to the "unify" family;
 wenzelm parents: 
58942diff
changeset | 592 | and unifs ([], []) = true | 
| 
e9559088ba29
clarified name of Type.unified, to emphasize its connection to the "unify" family;
 wenzelm parents: 
58942diff
changeset | 593 | | unifs (T :: Ts, T' :: Ts') = unif (T', T') andalso unifs (Ts, Ts') | 
| 
e9559088ba29
clarified name of Type.unified, to emphasize its connection to the "unify" family;
 wenzelm parents: 
58942diff
changeset | 594 | | unifs _ = false; | 
| 
e9559088ba29
clarified name of Type.unified, to emphasize its connection to the "unify" family;
 wenzelm parents: 
58942diff
changeset | 595 | in if Vartab.is_empty tye then op = else unif end; | 
| 32030 | 596 | |
| 450 | 597 | |
| 0 | 598 | |
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 599 | (** extend and merge type signatures **) | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 600 | |
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 601 | (* classes *) | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 602 | |
| 47005 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 wenzelm parents: 
46649diff
changeset | 603 | fun add_class context (c, cs) tsig = | 
| 19642 | 604 | tsig |> map_tsig (fn ((space, classes), default, types) => | 
| 16370 
033d890fe91f
name space of classes and types maintained in tsig;
 wenzelm parents: 
16340diff
changeset | 605 | let | 
| 
033d890fe91f
name space of classes and types maintained in tsig;
 wenzelm parents: 
16340diff
changeset | 606 | val cs' = map (cert_class tsig) cs | 
| 
033d890fe91f
name space of classes and types maintained in tsig;
 wenzelm parents: 
16340diff
changeset | 607 | handle TYPE (msg, _, _) => error msg; | 
| 41254 
78c3e472bb35
extra checking of name bindings for classes, types, consts;
 wenzelm parents: 
39997diff
changeset | 608 | val _ = Binding.check c; | 
| 47005 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 wenzelm parents: 
46649diff
changeset | 609 | val (c', space') = space |> Name_Space.declare context true c; | 
| 61262 
7bd1eb4b056e
tuned signature: eliminated pointless type Context.pretty;
 wenzelm parents: 
59885diff
changeset | 610 | val classes' = classes |> Sorts.add_class context (c', cs'); | 
| 19642 | 611 | in ((space', classes'), default, types) end); | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 612 | |
| 26669 | 613 | fun hide_class fully c = map_tsig (fn ((space, classes), default, types) => | 
| 33095 
bbd52d2f8696
renamed NameSpace to Name_Space -- also to emphasize its subtle change in semantics;
 wenzelm parents: 
33094diff
changeset | 614 | ((Name_Space.hide fully c space, classes), default, types)); | 
| 16370 
033d890fe91f
name space of classes and types maintained in tsig;
 wenzelm parents: 
16340diff
changeset | 615 | |
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 616 | |
| 19515 
9f650083da65
build classes/arities: refer to operations in sorts.ML;
 wenzelm parents: 
19464diff
changeset | 617 | (* arities *) | 
| 
9f650083da65
build classes/arities: refer to operations in sorts.ML;
 wenzelm parents: 
19464diff
changeset | 618 | |
| 61262 
7bd1eb4b056e
tuned signature: eliminated pointless type Context.pretty;
 wenzelm parents: 
59885diff
changeset | 619 | fun add_arity context (t, Ss, S) tsig = tsig |> map_tsig (fn ((space, classes), default, types) => | 
| 19515 
9f650083da65
build classes/arities: refer to operations in sorts.ML;
 wenzelm parents: 
19464diff
changeset | 620 | let | 
| 
9f650083da65
build classes/arities: refer to operations in sorts.ML;
 wenzelm parents: 
19464diff
changeset | 621 | val _ = | 
| 27302 | 622 | (case lookup_type tsig t of | 
| 33173 
b8ca12f6681a
eliminated obsolete tags for types/consts -- now handled via name space, in strongly typed fashion;
 wenzelm parents: 
33097diff
changeset | 623 | SOME (LogicalType n) => if length Ss <> n then error (bad_nargs t) else () | 
| 33094 
ef0d77b1e687
eliminated separate stamp -- NameSpace.define/merge etc. ensure uniqueness already;
 wenzelm parents: 
32784diff
changeset | 624 |       | SOME _ => error ("Logical type constructor expected: " ^ quote t)
 | 
| 19515 
9f650083da65
build classes/arities: refer to operations in sorts.ML;
 wenzelm parents: 
19464diff
changeset | 625 | | NONE => error (undecl_type t)); | 
| 
9f650083da65
build classes/arities: refer to operations in sorts.ML;
 wenzelm parents: 
19464diff
changeset | 626 | val (Ss', S') = (map (cert_sort tsig) Ss, cert_sort tsig S) | 
| 
9f650083da65
build classes/arities: refer to operations in sorts.ML;
 wenzelm parents: 
19464diff
changeset | 627 | handle TYPE (msg, _, _) => error msg; | 
| 61262 
7bd1eb4b056e
tuned signature: eliminated pointless type Context.pretty;
 wenzelm parents: 
59885diff
changeset | 628 | val classes' = classes |> Sorts.add_arities context ((t, map (fn c' => (c', Ss')) S')); | 
| 19642 | 629 | in ((space, classes'), default, types) end); | 
| 19515 
9f650083da65
build classes/arities: refer to operations in sorts.ML;
 wenzelm parents: 
19464diff
changeset | 630 | |
| 
9f650083da65
build classes/arities: refer to operations in sorts.ML;
 wenzelm parents: 
19464diff
changeset | 631 | |
| 
9f650083da65
build classes/arities: refer to operations in sorts.ML;
 wenzelm parents: 
19464diff
changeset | 632 | (* classrel *) | 
| 
9f650083da65
build classes/arities: refer to operations in sorts.ML;
 wenzelm parents: 
19464diff
changeset | 633 | |
| 61262 
7bd1eb4b056e
tuned signature: eliminated pointless type Context.pretty;
 wenzelm parents: 
59885diff
changeset | 634 | fun add_classrel context rel tsig = | 
| 19642 | 635 | tsig |> map_tsig (fn ((space, classes), default, types) => | 
| 19515 
9f650083da65
build classes/arities: refer to operations in sorts.ML;
 wenzelm parents: 
19464diff
changeset | 636 | let | 
| 59058 
a78612c67ec0
renamed "pairself" to "apply2", in accordance to @{apply 2};
 wenzelm parents: 
58949diff
changeset | 637 | val rel' = apply2 (cert_class tsig) rel | 
| 19515 
9f650083da65
build classes/arities: refer to operations in sorts.ML;
 wenzelm parents: 
19464diff
changeset | 638 | handle TYPE (msg, _, _) => error msg; | 
| 61262 
7bd1eb4b056e
tuned signature: eliminated pointless type Context.pretty;
 wenzelm parents: 
59885diff
changeset | 639 | val classes' = classes |> Sorts.add_classrel context rel'; | 
| 19642 | 640 | in ((space, classes'), default, types) end); | 
| 19515 
9f650083da65
build classes/arities: refer to operations in sorts.ML;
 wenzelm parents: 
19464diff
changeset | 641 | |
| 
9f650083da65
build classes/arities: refer to operations in sorts.ML;
 wenzelm parents: 
19464diff
changeset | 642 | |
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 643 | (* default sort *) | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 644 | |
| 19642 | 645 | fun set_defsort S tsig = tsig |> map_tsig (fn (classes, _, types) => | 
| 646 | (classes, cert_sort tsig S handle TYPE (msg, _, _) => error msg, types)); | |
| 0 | 647 | |
| 648 | ||
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 649 | (* types *) | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 650 | |
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 651 | local | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 652 | |
| 47005 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 wenzelm parents: 
46649diff
changeset | 653 | fun new_decl context (c, decl) types = | 
| 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 wenzelm parents: 
46649diff
changeset | 654 | (Binding.check c; #2 (Name_Space.define context true (c, decl) types)); | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 655 | |
| 19642 | 656 | fun map_types f = map_tsig (fn (classes, default, types) => | 
| 19579 
b802d1804b77
replaced Sorts.DOMAIN by general Sorts.CLASS_ERROR;
 wenzelm parents: 
19530diff
changeset | 657 | let | 
| 56025 | 658 | val types' = f types; | 
| 659 | val _ = | |
| 59885 
3470a265d404
subtle change of long-standing name space policy: unknown entries are treated as hidden, consequently "private" is understood in the strict sense;
 wenzelm parents: 
59884diff
changeset | 660 | not (Name_Space.defined types' "dummy") orelse | 
| 56025 | 661 | Name_Space.intern (Name_Space.space_of_table types') "dummy" = "dummy" orelse | 
| 59885 
3470a265d404
subtle change of long-standing name space policy: unknown entries are treated as hidden, consequently "private" is understood in the strict sense;
 wenzelm parents: 
59884diff
changeset | 662 | error "Illegal declaration of dummy type"; | 
| 56025 | 663 | in (classes, default, types') end); | 
| 2964 | 664 | |
| 56025 | 665 | fun syntactic tsig (Type (c, Ts)) = | 
| 666 | (case lookup_type tsig c of SOME Nonterminal => true | _ => false) | |
| 667 | orelse exists (syntactic tsig) Ts | |
| 14989 | 668 | | syntactic _ _ = false; | 
| 669 | ||
| 27302 | 670 | in | 
| 671 | ||
| 47005 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 wenzelm parents: 
46649diff
changeset | 672 | fun add_type context (c, n) = | 
| 42381 
309ec68442c6
added Binding.print convenience, which includes quote already;
 wenzelm parents: 
42375diff
changeset | 673 |   if n < 0 then error ("Bad type constructor declaration " ^ Binding.print c)
 | 
| 47005 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 wenzelm parents: 
46649diff
changeset | 674 | else map_types (new_decl context (c, LogicalType n)); | 
| 27302 | 675 | |
| 47005 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 wenzelm parents: 
46649diff
changeset | 676 | fun add_abbrev context (a, vs, rhs) tsig = tsig |> map_types (fn types => | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 677 | let | 
| 30343 
79f022df8527
replace old bstring by binding for logical primitives: class, type, const etc.;
 wenzelm parents: 
29275diff
changeset | 678 | fun err msg = | 
| 42381 
309ec68442c6
added Binding.print convenience, which includes quote already;
 wenzelm parents: 
42375diff
changeset | 679 |       cat_error msg ("The error(s) above occurred in type abbreviation " ^ Binding.print a);
 | 
| 24274 
cb9236269af1
type mode: models certification mode (default, syntax, abbrev);
 wenzelm parents: 
23655diff
changeset | 680 | val rhs' = strip_sorts (no_tvars (cert_typ_mode mode_syntax tsig rhs)) | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 681 | handle TYPE (msg, _, _) => err msg; | 
| 33094 
ef0d77b1e687
eliminated separate stamp -- NameSpace.define/merge etc. ensure uniqueness already;
 wenzelm parents: 
32784diff
changeset | 682 | val _ = | 
| 
ef0d77b1e687
eliminated separate stamp -- NameSpace.define/merge etc. ensure uniqueness already;
 wenzelm parents: 
32784diff
changeset | 683 | (case duplicates (op =) vs of | 
| 
ef0d77b1e687
eliminated separate stamp -- NameSpace.define/merge etc. ensure uniqueness already;
 wenzelm parents: 
32784diff
changeset | 684 | [] => [] | 
| 
ef0d77b1e687
eliminated separate stamp -- NameSpace.define/merge etc. ensure uniqueness already;
 wenzelm parents: 
32784diff
changeset | 685 |       | dups => err ("Duplicate variables on lhs: " ^ commas_quote dups));
 | 
| 
ef0d77b1e687
eliminated separate stamp -- NameSpace.define/merge etc. ensure uniqueness already;
 wenzelm parents: 
32784diff
changeset | 686 | val _ = | 
| 
ef0d77b1e687
eliminated separate stamp -- NameSpace.define/merge etc. ensure uniqueness already;
 wenzelm parents: 
32784diff
changeset | 687 | (case subtract (op =) vs (map #1 (Term.add_tfreesT rhs' [])) of | 
| 
ef0d77b1e687
eliminated separate stamp -- NameSpace.define/merge etc. ensure uniqueness already;
 wenzelm parents: 
32784diff
changeset | 688 | [] => [] | 
| 
ef0d77b1e687
eliminated separate stamp -- NameSpace.define/merge etc. ensure uniqueness already;
 wenzelm parents: 
32784diff
changeset | 689 |       | extras => err ("Extra variables on rhs: " ^ commas_quote extras));
 | 
| 56025 | 690 | in types |> new_decl context (a, Abbreviation (vs, rhs', syntactic tsig rhs')) end); | 
| 0 | 691 | |
| 47005 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 wenzelm parents: 
46649diff
changeset | 692 | fun add_nonterminal context = map_types o new_decl context o rpair Nonterminal; | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 693 | |
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 694 | end; | 
| 0 | 695 | |
| 56025 | 696 | fun hide_type fully c = map_tsig (fn (classes, default, types) => | 
| 697 | (classes, default, Name_Space.hide_table fully c types)); | |
| 16370 
033d890fe91f
name space of classes and types maintained in tsig;
 wenzelm parents: 
16340diff
changeset | 698 | |
| 3790 | 699 | |
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 700 | (* merge type signatures *) | 
| 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 701 | |
| 61262 
7bd1eb4b056e
tuned signature: eliminated pointless type Context.pretty;
 wenzelm parents: 
59885diff
changeset | 702 | fun merge_tsig context (tsig1, tsig2) = | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 703 | let | 
| 19515 
9f650083da65
build classes/arities: refer to operations in sorts.ML;
 wenzelm parents: 
19464diff
changeset | 704 |     val (TSig {classes = (space1, classes1), default = default1, types = types1,
 | 
| 26641 | 705 | log_types = _}) = tsig1; | 
| 19515 
9f650083da65
build classes/arities: refer to operations in sorts.ML;
 wenzelm parents: 
19464diff
changeset | 706 |     val (TSig {classes = (space2, classes2), default = default2, types = types2,
 | 
| 26641 | 707 | log_types = _}) = tsig2; | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 708 | |
| 33095 
bbd52d2f8696
renamed NameSpace to Name_Space -- also to emphasize its subtle change in semantics;
 wenzelm parents: 
33094diff
changeset | 709 | val space' = Name_Space.merge (space1, space2); | 
| 61262 
7bd1eb4b056e
tuned signature: eliminated pointless type Context.pretty;
 wenzelm parents: 
59885diff
changeset | 710 | val classes' = Sorts.merge_algebra context (classes1, classes2); | 
| 19515 
9f650083da65
build classes/arities: refer to operations in sorts.ML;
 wenzelm parents: 
19464diff
changeset | 711 | val default' = Sorts.inter_sort classes' (default1, default2); | 
| 33095 
bbd52d2f8696
renamed NameSpace to Name_Space -- also to emphasize its subtle change in semantics;
 wenzelm parents: 
33094diff
changeset | 712 | val types' = Name_Space.merge_tables (types1, types2); | 
| 19642 | 713 | in build_tsig ((space', classes'), default', types') end; | 
| 14790 
0d984ee030a1
major cleanup of tsig datastructures and extend/merge operations; fixes old bugs in classes/arities code; proper treatment of nonterminals and syntax-only types;
 wenzelm parents: 
13666diff
changeset | 714 | |
| 0 | 715 | end; |