src/Pure/theory.ML
author paulson
Fri, 30 May 1997 15:14:59 +0200
changeset 3365 86c0d1988622
parent 2979 db6941221197
child 3767 e2bb53d8dd26
permissions -rw-r--r--
flushOut ensures that no recent error message are lost (not certain this is necessary)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
     1
(*  Title:      Pure/theory.ML
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
     2
    ID:         $Id$
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
     3
    Author:     Lawrence C Paulson and Markus Wenzel
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
     4
    Copyright   1996  University of Cambridge
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
     5
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
     6
Theories
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
     7
*)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
     8
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
     9
signature THEORY =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    10
  sig
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    11
  type theory
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    12
  exception THEORY of string * theory list
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    13
  val rep_theory        : theory ->
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    14
    {sign: Sign.sg, oraopt: (Sign.sg * exn -> term) option,
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    15
     new_axioms: term Symtab.table, parents: theory list}
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    16
  val sign_of           : theory -> Sign.sg
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    17
  val syn_of            : theory -> Syntax.syntax
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    18
  val stamps_of_thy     : theory -> string ref list
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    19
  val parents_of        : theory -> theory list
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    20
  val subthy            : theory * theory -> bool
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    21
  val eq_thy            : theory * theory -> bool
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    22
  val proto_pure_thy    : theory
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    23
  val pure_thy          : theory
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    24
  val cpure_thy         : theory
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    25
  (*theory primitives*)
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    26
  val add_classes	: (class * class list) list -> theory -> theory
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    27
  val add_classrel	: (class * class) list -> theory -> theory
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    28
  val add_defsort	: sort -> theory -> theory
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    29
  val add_types		: (string * int * mixfix) list -> theory -> theory
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    30
  val add_tyabbrs	: (string * string list * string * mixfix) list
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    31
    -> theory -> theory
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    32
  val add_tyabbrs_i	: (string * string list * typ * mixfix) list
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    33
    -> theory -> theory
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    34
  val add_arities	: (string * sort list * sort) list -> theory -> theory
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    35
  val add_consts	: (string * string * mixfix) list -> theory -> theory
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    36
  val add_consts_i	: (string * typ * mixfix) list -> theory -> theory
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    37
  val add_syntax	: (string * string * mixfix) list -> theory -> theory
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    38
  val add_syntax_i	: (string * typ * mixfix) list -> theory -> theory
2359
97b88cafe1e8 add_modesyntax(_i): added 'inout' argument;
wenzelm
parents: 2206
diff changeset
    39
  val add_modesyntax	: string * bool -> (string * string * mixfix) list -> theory -> theory
97b88cafe1e8 add_modesyntax(_i): added 'inout' argument;
wenzelm
parents: 2206
diff changeset
    40
  val add_modesyntax_i	: string * bool -> (string * typ * mixfix) list -> theory -> theory
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    41
  val add_trfuns	:
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    42
    (string * (Syntax.ast list -> Syntax.ast)) list *
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    43
    (string * (term list -> term)) list *
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    44
    (string * (term list -> term)) list *
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    45
    (string * (Syntax.ast list -> Syntax.ast)) list -> theory -> theory
2385
73d1435aa729 added typed print translations;
wenzelm
parents: 2359
diff changeset
    46
  val add_trfunsT	:
73d1435aa729 added typed print translations;
wenzelm
parents: 2359
diff changeset
    47
    (string * (typ -> term list -> term)) list -> theory -> theory
2693
8300bba275e3 added add_tokentrfuns;
wenzelm
parents: 2385
diff changeset
    48
  val add_tokentrfuns:
8300bba275e3 added add_tokentrfuns;
wenzelm
parents: 2385
diff changeset
    49
    (string * string * (string -> string * int)) list -> theory -> theory
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    50
  val add_trrules     : (string * string)Syntax.trrule list -> theory -> theory
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    51
  val add_trrules_i	: Syntax.ast Syntax.trrule list -> theory -> theory
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    52
  val cert_axm          : Sign.sg -> string * term -> string * term
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    53
  val read_axm          : Sign.sg -> string * string -> string * term
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    54
  val inferT_axm        : Sign.sg -> string * term -> string * term
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    55
  val add_axioms	: (string * string) list -> theory -> theory
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    56
  val add_axioms_i	: (string * term) list -> theory -> theory
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    57
  val add_thyname	: string -> theory -> theory
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    58
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    59
  val set_oracle	: (Sign.sg * exn -> term) -> theory -> theory
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    60
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    61
  val merge_theories    : theory * theory -> theory
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    62
  val merge_thy_list    : bool -> theory list -> theory
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    63
end;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    64
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    65
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    66
structure Theory : THEORY =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    67
struct
2206
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
    68
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
    69
(** datatype theory **)
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    70
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    71
datatype theory =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    72
  Theory of {
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    73
    sign: Sign.sg,
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
    74
    oraopt: (Sign.sg * exn -> term) option,
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    75
    new_axioms: term Symtab.table,
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    76
    parents: theory list};
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    77
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    78
fun rep_theory (Theory args) = args;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    79
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    80
(*errors involving theories*)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    81
exception THEORY of string * theory list;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    82
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    83
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    84
val sign_of = #sign o rep_theory;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    85
val syn_of = #syn o Sign.rep_sg o sign_of;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    86
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    87
(*stamps associated with a theory*)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    88
val stamps_of_thy = #stamps o Sign.rep_sg o sign_of;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    89
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    90
(*return the immediate ancestors*)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    91
val parents_of = #parents o rep_theory;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    92
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    93
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    94
(*compare theories*)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    95
val subthy = Sign.subsig o pairself sign_of;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    96
val eq_thy = Sign.eq_sg o pairself sign_of;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    97
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    98
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
    99
(* the Pure theories *)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   100
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   101
val proto_pure_thy =
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   102
  Theory {sign = Sign.proto_pure, oraopt = None, 
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   103
	  new_axioms = Symtab.null, parents = []};
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   104
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   105
val pure_thy =
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   106
  Theory {sign = Sign.pure, oraopt = None, 
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   107
	  new_axioms = Symtab.null, parents = []};
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   108
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   109
val cpure_thy =
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   110
  Theory {sign = Sign.cpure, oraopt = None, 
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   111
	  new_axioms = Symtab.null, parents = []};
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   112
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   113
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   114
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   115
(** extend theory **)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   116
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   117
fun err_dup_axms names =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   118
  error ("Duplicate axiom name(s) " ^ commas_quote names);
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   119
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   120
fun ext_thy (thy as Theory {sign, oraopt, new_axioms, parents}) 
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   121
            sign1 new_axms =
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   122
  let
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   123
    val draft = Sign.is_draft sign;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   124
    val new_axioms1 =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   125
      Symtab.extend_new (if draft then new_axioms else Symtab.null, new_axms)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   126
        handle Symtab.DUPS names => err_dup_axms names;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   127
    val parents1 = if draft then parents else [thy];
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   128
  in
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   129
    Theory {sign = sign1, oraopt = oraopt, 
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   130
	    new_axioms = new_axioms1, parents = parents1}
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   131
  end;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   132
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   133
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   134
(* extend signature of a theory *)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   135
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   136
fun ext_sg extfun decls (thy as Theory {sign, ...}) =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   137
  ext_thy thy (extfun decls sign) [];
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   138
2206
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   139
val add_classes      = ext_sg Sign.add_classes;
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   140
val add_classrel     = ext_sg Sign.add_classrel;
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   141
val add_defsort      = ext_sg Sign.add_defsort;
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   142
val add_types        = ext_sg Sign.add_types;
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   143
val add_tyabbrs      = ext_sg Sign.add_tyabbrs;
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   144
val add_tyabbrs_i    = ext_sg Sign.add_tyabbrs_i;
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   145
val add_arities      = ext_sg Sign.add_arities;
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   146
val add_consts       = ext_sg Sign.add_consts;
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   147
val add_consts_i     = ext_sg Sign.add_consts_i;
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   148
val add_syntax       = ext_sg Sign.add_syntax;
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   149
val add_syntax_i     = ext_sg Sign.add_syntax_i;
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   150
val add_modesyntax   = curry (ext_sg Sign.add_modesyntax);
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   151
val add_modesyntax_i = curry (ext_sg Sign.add_modesyntax_i);
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   152
val add_trfuns       = ext_sg Sign.add_trfuns;
2385
73d1435aa729 added typed print translations;
wenzelm
parents: 2359
diff changeset
   153
val add_trfunsT      = ext_sg Sign.add_trfunsT;
2693
8300bba275e3 added add_tokentrfuns;
wenzelm
parents: 2385
diff changeset
   154
val add_tokentrfuns  = ext_sg Sign.add_tokentrfuns;
2206
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   155
val add_trrules      = ext_sg Sign.add_trrules;
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   156
val add_trrules_i    = ext_sg Sign.add_trrules_i;
a9419797e196 added add_modesyntax(_i);
wenzelm
parents: 1960
diff changeset
   157
val add_thyname      = ext_sg Sign.add_name;
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   158
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   159
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   160
(* prepare axioms *)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   161
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   162
fun err_in_axm name =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   163
  error ("The error(s) above occurred in axiom " ^ quote name);
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   164
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   165
fun no_vars tm =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   166
  if null (term_vars tm) andalso null (term_tvars tm) then tm
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   167
  else error "Illegal schematic variable(s) in term";
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   168
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   169
fun cert_axm sg (name, raw_tm) =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   170
  let
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   171
    val (t, T, _) = Sign.certify_term sg raw_tm
2979
db6941221197 improved type check error messages;
wenzelm
parents: 2693
diff changeset
   172
      handle TYPE (msg, _, _) => error msg
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   173
	   | TERM (msg, _) => error msg;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   174
  in
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   175
    assert (T = propT) "Term not of type prop";
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   176
    (name, no_vars t)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   177
  end
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   178
  handle ERROR => err_in_axm name;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   179
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   180
(*Some duplication of code with read_def_cterm*)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   181
fun read_axm sg (name, str) = 
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   182
  let val ts = Syntax.read (#syn (Sign.rep_sg sg)) propT str;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   183
      val (_, t, _) =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   184
          Sign.infer_types sg (K None) (K None) [] true (ts,propT);
1960
ae390b599213 Improved error handling: if there are syntax or type-checking
paulson
parents: 1539
diff changeset
   185
  in cert_axm sg (name,t) end
ae390b599213 Improved error handling: if there are syntax or type-checking
paulson
parents: 1539
diff changeset
   186
  handle ERROR => err_in_axm name;
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   187
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   188
fun inferT_axm sg (name, pre_tm) =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   189
  let val t = #2(Sign.infer_types sg (K None) (K None) [] true
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   190
                                     ([pre_tm], propT))
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   191
  in  (name, no_vars t) end
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   192
  handle ERROR => err_in_axm name;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   193
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   194
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   195
(* extend axioms of a theory *)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   196
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   197
fun ext_axms prep_axm axms (thy as Theory {sign, ...}) =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   198
  let
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   199
    val sign1 = Sign.make_draft sign;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   200
    val axioms = map (apsnd (Term.compress_term o Logic.varify) o 
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   201
		      prep_axm sign) 
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   202
	         axms;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   203
  in
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   204
    ext_thy thy sign1 axioms
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   205
  end;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   206
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   207
val add_axioms = ext_axms read_axm;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   208
val add_axioms_i = ext_axms cert_axm;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   209
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   210
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   211
(** Set oracle of theory **)
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   212
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   213
fun set_oracle oracle 
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   214
               (thy as Theory {sign, oraopt = None, new_axioms, parents}) =
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   215
      if Sign.is_draft sign then
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   216
	Theory {sign = sign, 
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   217
		oraopt = Some oracle, 
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   218
		new_axioms = new_axioms, 
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   219
		parents = parents}
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   220
      else raise THEORY ("Can only set oracle of a draft", [thy])
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   221
  | set_oracle _ thy = raise THEORY ("Oracle already set", [thy]);
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   222
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   223
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   224
(** merge theories **)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   225
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   226
fun merge_thy_list mk_draft thys =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   227
  let
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   228
    fun is_union thy = forall (fn t => subthy (t, thy)) thys;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   229
    val is_draft = Sign.is_draft o sign_of;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   230
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   231
    fun add_sign (sg, Theory {sign, ...}) =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   232
      Sign.merge (sg, sign) handle TERM (msg, _) => error msg;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   233
  in
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   234
    case (find_first is_union thys, exists is_draft thys) of
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   235
      (Some thy, _) => thy
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   236
    | (None, true) => raise THEORY ("Illegal merge of draft theories", thys)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   237
    | (None, false) => Theory {
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   238
        sign =
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   239
          (if mk_draft then Sign.make_draft else I)
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   240
          (foldl add_sign (Sign.proto_pure, thys)),
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   241
	oraopt = None,
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   242
        new_axioms = Symtab.null,
1539
f21c8fab7c3c Addition of oracles
paulson
parents: 1526
diff changeset
   243
        parents = thys}
1526
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   244
  end;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   245
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   246
fun merge_theories (thy1, thy2) = merge_thy_list false [thy1, thy2];
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   247
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   248
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   249
end;
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   250
6be6ea6f8b5d New file of just the theory primitives
paulson
parents:
diff changeset
   251
open Theory;