src/Pure/theory.ML
changeset 1539 f21c8fab7c3c
parent 1526 6be6ea6f8b5d
child 1960 ae390b599213
equal deleted inserted replaced
1538:31ad553d018b 1539:f21c8fab7c3c
     9 signature THEORY =
     9 signature THEORY =
    10   sig
    10   sig
    11   type theory
    11   type theory
    12   exception THEORY of string * theory list
    12   exception THEORY of string * theory list
    13   val rep_theory        : theory ->
    13   val rep_theory        : theory ->
    14     {sign: Sign.sg, new_axioms: term Symtab.table, parents: theory list}
    14     {sign: Sign.sg, oraopt: (Sign.sg * exn -> term) option,
       
    15      new_axioms: term Symtab.table, parents: theory list}
    15   val sign_of           : theory -> Sign.sg
    16   val sign_of           : theory -> Sign.sg
    16   val syn_of            : theory -> Syntax.syntax
    17   val syn_of            : theory -> Syntax.syntax
    17   val stamps_of_thy     : theory -> string ref list
    18   val stamps_of_thy     : theory -> string ref list
    18   val parents_of        : theory -> theory list
    19   val parents_of        : theory -> theory list
    19   val subthy            : theory * theory -> bool
    20   val subthy            : theory * theory -> bool
    20   val eq_thy            : theory * theory -> bool
    21   val eq_thy            : theory * theory -> bool
    21   val proto_pure_thy    : theory
    22   val proto_pure_thy    : theory
    22   val pure_thy          : theory
    23   val pure_thy          : theory
    23   val cpure_thy         : theory
    24   val cpure_thy         : theory
    24   (*theory primitives*)
    25   (*theory primitives*)
    25   val add_classes     : (class * class list) list -> theory -> theory
    26   val add_classes	: (class * class list) list -> theory -> theory
    26   val add_classrel    : (class * class) list -> theory -> theory
    27   val add_classrel	: (class * class) list -> theory -> theory
    27   val add_defsort     : sort -> theory -> theory
    28   val add_defsort	: sort -> theory -> theory
    28   val add_types       : (string * int * mixfix) list -> theory -> theory
    29   val add_types		: (string * int * mixfix) list -> theory -> theory
    29   val add_tyabbrs     : (string * string list * string * mixfix) list
    30   val add_tyabbrs	: (string * string list * string * mixfix) list
    30     -> theory -> theory
    31     -> theory -> theory
    31   val add_tyabbrs_i   : (string * string list * typ * mixfix) list
    32   val add_tyabbrs_i	: (string * string list * typ * mixfix) list
    32     -> theory -> theory
    33     -> theory -> theory
    33   val add_arities     : (string * sort list * sort) list -> theory -> theory
    34   val add_arities	: (string * sort list * sort) list -> theory -> theory
    34   val add_consts      : (string * string * mixfix) list -> theory -> theory
    35   val add_consts	: (string * string * mixfix) list -> theory -> theory
    35   val add_consts_i    : (string * typ * mixfix) list -> theory -> theory
    36   val add_consts_i	: (string * typ * mixfix) list -> theory -> theory
    36   val add_syntax      : (string * string * mixfix) list -> theory -> theory
    37   val add_syntax	: (string * string * mixfix) list -> theory -> theory
    37   val add_syntax_i    : (string * typ * mixfix) list -> theory -> theory
    38   val add_syntax_i	: (string * typ * mixfix) list -> theory -> theory
    38   val add_trfuns      :
    39   val add_trfuns	:
    39     (string * (Syntax.ast list -> Syntax.ast)) list *
    40     (string * (Syntax.ast list -> Syntax.ast)) list *
    40     (string * (term list -> term)) list *
    41     (string * (term list -> term)) list *
    41     (string * (term list -> term)) list *
    42     (string * (term list -> term)) list *
    42     (string * (Syntax.ast list -> Syntax.ast)) list -> theory -> theory
    43     (string * (Syntax.ast list -> Syntax.ast)) list -> theory -> theory
    43   val add_trrules     : (string * string)Syntax.trrule list -> theory -> theory
    44   val add_trrules     : (string * string)Syntax.trrule list -> theory -> theory
    44   val add_trrules_i   : Syntax.ast Syntax.trrule list -> theory -> theory
    45   val add_trrules_i	: Syntax.ast Syntax.trrule list -> theory -> theory
    45   val cert_axm          : Sign.sg -> string * term -> string * term
    46   val cert_axm          : Sign.sg -> string * term -> string * term
    46   val read_axm          : Sign.sg -> string * string -> string * term
    47   val read_axm          : Sign.sg -> string * string -> string * term
    47   val inferT_axm        : Sign.sg -> string * term -> string * term
    48   val inferT_axm        : Sign.sg -> string * term -> string * term
    48   val add_axioms      : (string * string) list -> theory -> theory
    49   val add_axioms	: (string * string) list -> theory -> theory
    49   val add_axioms_i    : (string * term) list -> theory -> theory
    50   val add_axioms_i	: (string * term) list -> theory -> theory
    50   val add_thyname     : string -> theory -> theory
    51   val add_thyname	: string -> theory -> theory
       
    52 
       
    53   val set_oracle	: (Sign.sg * exn -> term) -> theory -> theory
    51 
    54 
    52   val merge_theories    : theory * theory -> theory
    55   val merge_theories    : theory * theory -> theory
    53   val merge_thy_list    : bool -> theory list -> theory
    56   val merge_thy_list    : bool -> theory list -> theory
    54 end;
    57 end;
    55 
    58 
    59 (*** Theories ***)
    62 (*** Theories ***)
    60 
    63 
    61 datatype theory =
    64 datatype theory =
    62   Theory of {
    65   Theory of {
    63     sign: Sign.sg,
    66     sign: Sign.sg,
       
    67     oraopt: (Sign.sg * exn -> term) option,
    64     new_axioms: term Symtab.table,
    68     new_axioms: term Symtab.table,
    65     parents: theory list};
    69     parents: theory list};
    66 
    70 
    67 fun rep_theory (Theory args) = args;
    71 fun rep_theory (Theory args) = args;
    68 
    72 
    86 
    90 
    87 
    91 
    88 (* the Pure theories *)
    92 (* the Pure theories *)
    89 
    93 
    90 val proto_pure_thy =
    94 val proto_pure_thy =
    91   Theory {sign = Sign.proto_pure, new_axioms = Symtab.null, parents = []};
    95   Theory {sign = Sign.proto_pure, oraopt = None, 
       
    96 	  new_axioms = Symtab.null, parents = []};
    92 
    97 
    93 val pure_thy =
    98 val pure_thy =
    94   Theory {sign = Sign.pure, new_axioms = Symtab.null, parents = []};
    99   Theory {sign = Sign.pure, oraopt = None, 
       
   100 	  new_axioms = Symtab.null, parents = []};
    95 
   101 
    96 val cpure_thy =
   102 val cpure_thy =
    97   Theory {sign = Sign.cpure, new_axioms = Symtab.null, parents = []};
   103   Theory {sign = Sign.cpure, oraopt = None, 
       
   104 	  new_axioms = Symtab.null, parents = []};
    98 
   105 
    99 
   106 
   100 
   107 
   101 (** extend theory **)
   108 (** extend theory **)
   102 
   109 
   103 fun err_dup_axms names =
   110 fun err_dup_axms names =
   104   error ("Duplicate axiom name(s) " ^ commas_quote names);
   111   error ("Duplicate axiom name(s) " ^ commas_quote names);
   105 
   112 
   106 fun ext_thy (thy as Theory {sign, new_axioms, parents}) sign1 new_axms =
   113 fun ext_thy (thy as Theory {sign, oraopt, new_axioms, parents}) 
       
   114             sign1 new_axms =
   107   let
   115   let
   108     val draft = Sign.is_draft sign;
   116     val draft = Sign.is_draft sign;
   109     val new_axioms1 =
   117     val new_axioms1 =
   110       Symtab.extend_new (if draft then new_axioms else Symtab.null, new_axms)
   118       Symtab.extend_new (if draft then new_axioms else Symtab.null, new_axms)
   111         handle Symtab.DUPS names => err_dup_axms names;
   119         handle Symtab.DUPS names => err_dup_axms names;
   112     val parents1 = if draft then parents else [thy];
   120     val parents1 = if draft then parents else [thy];
   113   in
   121   in
   114     Theory {sign = sign1, new_axioms = new_axioms1, parents = parents1}
   122     Theory {sign = sign1, oraopt = oraopt, 
       
   123 	    new_axioms = new_axioms1, parents = parents1}
   115   end;
   124   end;
   116 
   125 
   117 
   126 
   118 (* extend signature of a theory *)
   127 (* extend signature of a theory *)
   119 
   128 
   185 
   194 
   186 val add_axioms = ext_axms read_axm;
   195 val add_axioms = ext_axms read_axm;
   187 val add_axioms_i = ext_axms cert_axm;
   196 val add_axioms_i = ext_axms cert_axm;
   188 
   197 
   189 
   198 
       
   199 (** Set oracle of theory **)
       
   200 
       
   201 fun set_oracle oracle 
       
   202                (thy as Theory {sign, oraopt = None, new_axioms, parents}) =
       
   203       if Sign.is_draft sign then
       
   204 	Theory {sign = sign, 
       
   205 		oraopt = Some oracle, 
       
   206 		new_axioms = new_axioms, 
       
   207 		parents = parents}
       
   208       else raise THEORY ("Can only set oracle of a draft", [thy])
       
   209   | set_oracle _ thy = raise THEORY ("Oracle already set", [thy]);
       
   210 
   190 
   211 
   191 (** merge theories **)
   212 (** merge theories **)
   192 
   213 
   193 fun merge_thy_list mk_draft thys =
   214 fun merge_thy_list mk_draft thys =
   194   let
   215   let
   196     val is_draft = Sign.is_draft o sign_of;
   217     val is_draft = Sign.is_draft o sign_of;
   197 
   218 
   198     fun add_sign (sg, Theory {sign, ...}) =
   219     fun add_sign (sg, Theory {sign, ...}) =
   199       Sign.merge (sg, sign) handle TERM (msg, _) => error msg;
   220       Sign.merge (sg, sign) handle TERM (msg, _) => error msg;
   200   in
   221   in
   201     (case (find_first is_union thys, exists is_draft thys) of
   222     case (find_first is_union thys, exists is_draft thys) of
   202       (Some thy, _) => thy
   223       (Some thy, _) => thy
   203     | (None, true) => raise THEORY ("Illegal merge of draft theories", thys)
   224     | (None, true) => raise THEORY ("Illegal merge of draft theories", thys)
   204     | (None, false) => Theory {
   225     | (None, false) => Theory {
   205         sign =
   226         sign =
   206           (if mk_draft then Sign.make_draft else I)
   227           (if mk_draft then Sign.make_draft else I)
   207           (foldl add_sign (Sign.proto_pure, thys)),
   228           (foldl add_sign (Sign.proto_pure, thys)),
       
   229 	oraopt = None,
   208         new_axioms = Symtab.null,
   230         new_axioms = Symtab.null,
   209         parents = thys})
   231         parents = thys}
   210   end;
   232   end;
   211 
   233 
   212 fun merge_theories (thy1, thy2) = merge_thy_list false [thy1, thy2];
   234 fun merge_theories (thy1, thy2) = merge_thy_list false [thy1, thy2];
   213 
   235 
   214 
   236