src/Pure/consts.ML
author wenzelm
Tue, 07 Feb 2006 19:56:47 +0100
changeset 18965 3b76383e3ab3
parent 18935 f22be3d61ed5
child 18992 910fbe64033c
permissions -rw-r--r--
renamed space to space_of; removed expansion; added abbrevs_of; added read_const; certify: substitute arguments into expanded const; tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/consts.ML
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
     3
    Author:     Makarius
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
     4
18935
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
     5
Polymorphic constants: declarations, abbreviations, additional type
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
     6
constraints.
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
     7
*)
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
     8
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
     9
signature CONSTS =
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    10
sig
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    11
  type T
18935
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
    12
  val dest: T ->
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
    13
   {constants: (typ * term option) NameSpace.table,
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
    14
    constraints: typ NameSpace.table}
18965
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    15
  val space_of: T -> NameSpace.T
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    16
  val abbrevs_of: T -> (term * term) list
18935
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
    17
  val declaration: T -> string -> typ                           (*exception TYPE*)
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
    18
  val monomorphic: T -> string -> bool                          (*exception TYPE*)
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
    19
  val constraint: T -> string -> typ                            (*exception TYPE*)
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
    20
  val certify: Pretty.pp -> Type.tsig -> T -> term -> term      (*exception TYPE*)
18965
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    21
  val read_const: T -> string -> term
18146
47463b1825c6 uncurried Consts.typargs;
wenzelm
parents: 18117
diff changeset
    22
  val typargs: T -> string * typ -> typ list
18163
9b729737bf14 added instance;
wenzelm
parents: 18146
diff changeset
    23
  val instance: T -> string * typ list -> typ
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    24
  val declare: NameSpace.naming -> bstring * typ -> T -> T
18965
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    25
  val abbreviate: Pretty.pp -> Type.tsig -> NameSpace.naming -> bool -> string * term -> T -> T
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    26
  val constrain: string * typ -> T -> T
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    27
  val hide: bool -> string -> T -> T
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    28
  val empty: T
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    29
  val merge: T * T -> T
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    30
end
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    31
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    32
structure Consts: CONSTS =
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    33
struct
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    34
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    35
(** datatype T **)
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    36
18935
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
    37
datatype decl =
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
    38
  LogicalConst of typ * int list list |
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
    39
  Abbreviation of typ * term;
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
    40
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    41
datatype T = Consts of
18935
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
    42
 {decls: (decl * serial) NameSpace.table,
18965
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    43
  abbrevs: (term * term) list,
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    44
  constraints: typ Symtab.table};
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    45
18965
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    46
fun make_consts (decls, abbrevs, constraints) =
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    47
  Consts {decls = decls, abbrevs = abbrevs, constraints = constraints};
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    48
18965
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    49
fun map_consts f (Consts {decls, abbrevs, constraints}) =
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    50
  make_consts (f (decls, abbrevs, constraints));
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    51
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    52
fun dest (Consts {decls = (space, decls), abbrevs = _, constraints}) =
18935
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
    53
 {constants = (space, Symtab.fold
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
    54
    (fn (c, (LogicalConst (T, _), _)) => Symtab.update (c, (T, NONE))
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
    55
      | (c, (Abbreviation (T, t), _)) => Symtab.update (c, (T, SOME t))) decls Symtab.empty),
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    56
  constraints = (space, constraints)};
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    57
18965
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    58
fun space_of (Consts {decls = (space, _), ...}) = space;
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    59
fun abbrevs_of (Consts {abbrevs, ...}) = abbrevs;
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    60
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    61
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    62
(* lookup consts *)
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    63
18935
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
    64
fun err_undeclared c = raise TYPE ("Undeclared constant: " ^ quote c, [], []);
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
    65
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
    66
fun the_const (Consts {decls = (_, tab), ...}) c =
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
    67
  (case Symtab.lookup tab c of SOME (decl, _) => decl | NONE => err_undeclared c);
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
    68
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
    69
fun logical_const consts c =
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
    70
  (case the_const consts c of LogicalConst d => d | _ => err_undeclared c);
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    71
18935
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
    72
fun declaration consts c = #1 (logical_const consts c);
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
    73
fun monomorphic consts c = null (#2 (logical_const consts c));
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
    74
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    75
fun constraint (consts as Consts {constraints, ...}) c =
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    76
  (case Symtab.lookup constraints c of
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    77
    SOME T => T
18935
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
    78
  | NONE => (case the_const consts c of LogicalConst (T, _) => T | Abbreviation (T, _) => T));
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
    79
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
    80
18965
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    81
(* certify: check/expand consts *)
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
    82
18965
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    83
fun certify pp tsig consts =
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    84
  let
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    85
    fun err msg (c, T) =
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    86
      raise TYPE (msg ^ " " ^ quote c ^ " :: " ^ Pretty.string_of_typ pp T, [], []);
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    87
    fun cert tm =
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    88
      let
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    89
        val (head, args) = Term.strip_comb tm;
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    90
        val args' = map cert args;
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    91
      in
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    92
        (case head of
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    93
          Const (c, T) =>
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    94
            (case the_const consts c of
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    95
              LogicalConst (U, _) =>
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    96
                if Type.typ_instance tsig (T, U) then Term.list_comb (head, args')
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    97
                else err "Illegal type for constant" (c, T)
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    98
            | Abbreviation (U, u) =>
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
    99
                Term.betapplys (Envir.expand_atom tsig T (U, u) handle TYPE _ =>
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   100
                  err "Illegal type for abbreviation" (c, T), args'))
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   101
        | Abs (x, T, t) => Term.list_comb (Abs (x, T, cert t), args')
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   102
        | _ => Term.list_comb (head, args'))
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   103
      end;
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   104
  in cert end;
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   105
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   106
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   107
(* read_const *)
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   108
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   109
fun read_const consts raw_c =
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   110
  let
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   111
    val c = NameSpace.intern (space_of consts) raw_c;
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   112
    val _ = the_const consts c handle TYPE (msg, _, _) => error msg;
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   113
  in Const (c, dummyT) end;
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   114
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   115
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   116
(* typargs -- view actual const type as instance of declaration *)
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   117
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   118
fun sub (Type (_, Ts)) (i :: is) = sub (nth Ts i) is
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   119
  | sub T [] = T
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   120
  | sub T _ = raise Subscript;
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   121
18935
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
   122
fun typargs consts (c, T) = map (sub T) (#2 (logical_const consts c));
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   123
18163
9b729737bf14 added instance;
wenzelm
parents: 18146
diff changeset
   124
fun instance consts (c, Ts) =
9b729737bf14 added instance;
wenzelm
parents: 18146
diff changeset
   125
  let
9b729737bf14 added instance;
wenzelm
parents: 18146
diff changeset
   126
    val declT = declaration consts c;
9b729737bf14 added instance;
wenzelm
parents: 18146
diff changeset
   127
    val vars = map Term.dest_TVar (typargs consts (c, declT));
9b729737bf14 added instance;
wenzelm
parents: 18146
diff changeset
   128
  in declT |> Term.instantiateT (vars ~~ Ts) end;
9b729737bf14 added instance;
wenzelm
parents: 18146
diff changeset
   129
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   130
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   131
18935
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
   132
(** declare consts **)
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   133
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   134
fun err_dup_consts cs =
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   135
  error ("Duplicate declaration of constant(s) " ^ commas_quote cs);
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   136
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   137
fun err_inconsistent_constraints cs =
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   138
  error ("Inconsistent type constraints for constant(s) " ^ commas_quote cs);
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   139
18935
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
   140
fun extend_decls naming decl tab = NameSpace.extend_table naming (tab, [decl])
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
   141
  handle Symtab.DUPS cs => err_dup_consts cs;
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   142
18935
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
   143
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
   144
(* name space *)
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   145
18965
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   146
fun hide fully c = map_consts (fn (decls, abbrevs, constraints) =>
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   147
  (apfst (NameSpace.hide fully c) decls, abbrevs, constraints));
18935
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
   148
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
   149
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
   150
(* declarations *)
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
   151
18965
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   152
fun declare naming (c, declT) = map_consts (fn (decls, abbrevs, constraints) =>
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   153
  let
18935
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
   154
    fun args_of (Type (_, Ts)) pos = args_of_list Ts 0 pos
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
   155
      | args_of (TVar v) pos = insert (eq_fst op =) (v, rev pos)
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
   156
      | args_of (TFree _) _ = I
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
   157
    and args_of_list (T :: Ts) i is = args_of T (i :: is) #> args_of_list Ts (i + 1) is
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
   158
      | args_of_list [] _ _ = I;
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
   159
    val decl = (c, (LogicalConst (declT, map #2 (rev (args_of declT [] []))), serial ()));
18965
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   160
  in (extend_decls naming decl decls, abbrevs, constraints) end);
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   161
18935
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
   162
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
   163
(* abbreviations *)
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
   164
18965
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   165
fun revert_abbrev const rhs =
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   166
  let
18965
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   167
    val (xs, body) = Term.strip_abs (Envir.beta_eta_contract rhs);
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   168
    val vars = fold (fn (x, T) => cons (Var ((x, 0), T))) (Term.rename_wrt_term body xs) [];
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   169
  in (Term.list_comb (Const const, vars), Term.subst_bounds (rev vars, body)) end;
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   170
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   171
fun abbreviate pp tsig naming revert (c, raw_rhs) consts =
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   172
    consts |> map_consts (fn (decls, abbrevs, constraints) =>
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   173
  let
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   174
    val rhs = certify pp tsig consts raw_rhs;
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   175
    val T = Term.fastype_of rhs;
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   176
    val decls' = decls |> extend_decls naming (c, (Abbreviation (T, rhs), serial ()));
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   177
    val abbrevs' =
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   178
      if revert then revert_abbrev (NameSpace.full naming c, T) rhs :: abbrevs else abbrevs;
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   179
  in (decls', abbrevs', constraints) end);
18935
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
   180
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   181
18935
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
   182
(* constraints *)
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   183
18965
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   184
fun constrain (c, T) = map_consts (fn (decls, abbrevs, constraints) =>
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   185
  (decls, abbrevs, Symtab.update (c, T) constraints));
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   186
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   187
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   188
(* empty and merge *)
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   189
18965
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   190
val empty = make_consts (NameSpace.empty_table, [], Symtab.empty);
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   191
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   192
fun merge
18965
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   193
   (Consts {decls = decls1, abbrevs = abbrevs1, constraints = constraints1},
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   194
    Consts {decls = decls2, abbrevs = abbrevs2, constraints = constraints2}) =
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   195
  let
18935
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
   196
    val decls' = NameSpace.merge_tables (eq_snd (op =)) (decls1, decls2)
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   197
      handle Symtab.DUPS cs => err_dup_consts cs;
18965
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   198
    val abbrevs' =
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   199
      Library.merge (fn ((t, u), (t', u')) => t aconv t' andalso u aconv u') (abbrevs1, abbrevs2);
18935
f22be3d61ed5 added abbreviations;
wenzelm
parents: 18163
diff changeset
   200
    val constraints' = Symtab.merge (op =) (constraints1, constraints2)
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   201
      handle Symtab.DUPS cs => err_inconsistent_constraints cs;
18965
3b76383e3ab3 renamed space to space_of;
wenzelm
parents: 18935
diff changeset
   202
  in make_consts (decls', abbrevs', constraints') end;
18060
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   203
afcc28d16629 Polymorphic constants.
wenzelm
parents:
diff changeset
   204
end;