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