src/Pure/Isar/locale.ML
changeset 29441 28d7d7572b81
parent 29392 aa3a30b625d1
child 29502 2cbc80397a17
equal deleted inserted replaced
29440:0f7031a3e692 29441:28d7d7572b81
    32   type locale
    32   type locale
    33 
    33 
    34   val register_locale: bstring ->
    34   val register_locale: bstring ->
    35     (string * sort) list * (Binding.T * typ option * mixfix) list ->
    35     (string * sort) list * (Binding.T * typ option * mixfix) list ->
    36     term option * term list ->
    36     term option * term list ->
       
    37     thm option * thm option -> thm list ->
    37     (declaration * stamp) list * (declaration * stamp) list ->
    38     (declaration * stamp) list * (declaration * stamp) list ->
    38     ((string * (Attrib.binding * (thm list * Attrib.src list) list) list) * stamp) list ->
    39     ((string * (Attrib.binding * (thm list * Attrib.src list) list) list) * stamp) list ->
    39     ((string * Morphism.morphism) * stamp) list -> theory -> theory
    40     ((string * Morphism.morphism) * stamp) list -> theory -> theory
    40 
    41 
    41   (* Locale name space *)
    42   (* Locale name space *)
    43   val extern: theory -> string -> xstring
    44   val extern: theory -> string -> xstring
    44 
    45 
    45   (* Specification *)
    46   (* Specification *)
    46   val defined: theory -> string -> bool
    47   val defined: theory -> string -> bool
    47   val params_of: theory -> string -> (Binding.T * typ option * mixfix) list
    48   val params_of: theory -> string -> (Binding.T * typ option * mixfix) list
       
    49   val intros_of: theory -> string -> thm option * thm option
       
    50   val axioms_of: theory -> string -> thm list
    48   val instance_of: theory -> string -> Morphism.morphism -> term list
    51   val instance_of: theory -> string -> Morphism.morphism -> term list
    49   val specification_of: theory -> string -> term option * term list
    52   val specification_of: theory -> string -> term option * term list
    50   val declarations_of: theory -> string -> declaration list * declaration list
    53   val declarations_of: theory -> string -> declaration list * declaration list
    51 
    54 
    52   (* Storing results *)
    55   (* Storing results *)
   116   (** static part **)
   119   (** static part **)
   117   parameters: (string * sort) list * (Binding.T * typ option * mixfix) list,
   120   parameters: (string * sort) list * (Binding.T * typ option * mixfix) list,
   118     (* type and term parameters *)
   121     (* type and term parameters *)
   119   spec: term option * term list,
   122   spec: term option * term list,
   120     (* assumptions (as a single predicate expression) and defines *)
   123     (* assumptions (as a single predicate expression) and defines *)
       
   124   intros: thm option * thm option,
       
   125   axioms: thm list,
   121   (** dynamic part **)
   126   (** dynamic part **)
   122   decls: (declaration * stamp) list * (declaration * stamp) list,
   127   decls: (declaration * stamp) list * (declaration * stamp) list,
   123     (* type and term syntax declarations *)
   128     (* type and term syntax declarations *)
   124   notes: ((string * (Attrib.binding * (thm list * Attrib.src list) list) list) * stamp) list,
   129   notes: ((string * (Attrib.binding * (thm list * Attrib.src list) list) list) * stamp) list,
   125     (* theorem declarations *)
   130     (* theorem declarations *)
   126   dependencies: ((string * Morphism.morphism) * stamp) list
   131   dependencies: ((string * Morphism.morphism) * stamp) list
   127     (* locale dependencies (sublocale relation) *)
   132     (* locale dependencies (sublocale relation) *)
   128 };
   133 };
   129 
   134 
   130 fun mk_locale ((parameters, spec), ((decls, notes), dependencies)) =
   135 fun mk_locale ((parameters, spec, intros, axioms), ((decls, notes), dependencies)) =
   131   Loc {parameters = parameters, spec = spec, decls = decls,
   136   Loc {parameters = parameters, intros = intros, axioms = axioms, spec = spec,
   132     notes = notes, dependencies = dependencies};
   137     decls = decls, notes = notes, dependencies = dependencies};
   133 fun map_locale f (Loc {parameters, spec, decls, notes, dependencies}) =
   138 fun map_locale f (Loc {parameters, spec, intros, axioms, decls, notes, dependencies}) =
   134   mk_locale (f ((parameters, spec), ((decls, notes), dependencies)));
   139   mk_locale (f ((parameters, spec, intros, axioms), ((decls, notes), dependencies)));
   135 fun merge_locale (Loc {parameters, spec, decls = (decls1, decls2), notes, dependencies},
   140 fun merge_locale (Loc {parameters, spec, intros, axioms, decls = (decls1, decls2),
   136   Loc {decls = (decls1', decls2'), notes = notes', dependencies = dependencies', ...}) =
   141   notes, dependencies}, Loc {decls = (decls1', decls2'), notes = notes',
   137     mk_locale ((parameters, spec),
   142     dependencies = dependencies', ...}) = mk_locale
   138       (((merge (eq_snd op =) (decls1, decls1'), merge (eq_snd op =) (decls2, decls2')),
   143       ((parameters, spec, intros, axioms),
   139         merge (eq_snd op =) (notes, notes')),
   144         (((merge (eq_snd op =) (decls1, decls1'), merge (eq_snd op =) (decls2, decls2')),
   140           merge (eq_snd op =) (dependencies, dependencies')));
   145           merge (eq_snd op =) (notes, notes')),
       
   146             merge (eq_snd op =) (dependencies, dependencies')));
   141 
   147 
   142 structure LocalesData = TheoryDataFun
   148 structure LocalesData = TheoryDataFun
   143 (
   149 (
   144   type T = locale NameSpace.table;
   150   type T = locale NameSpace.table;
   145   val empty = NameSpace.empty_table;
   151   val empty = NameSpace.empty_table;
   157 
   163 
   158 fun the_locale thy name = case get_locale thy name
   164 fun the_locale thy name = case get_locale thy name
   159  of SOME (Loc loc) => loc
   165  of SOME (Loc loc) => loc
   160   | NONE => error ("Unknown locale " ^ quote name);
   166   | NONE => error ("Unknown locale " ^ quote name);
   161 
   167 
   162 fun register_locale bname parameters spec decls notes dependencies thy =
   168 fun register_locale bname parameters spec intros axioms decls notes dependencies thy =
   163   thy |> LocalesData.map (NameSpace.bind (Sign.naming_of thy) (Binding.name bname,
   169   thy |> LocalesData.map (NameSpace.bind (Sign.naming_of thy) (Binding.name bname,
   164     mk_locale ((parameters, spec), ((decls, notes), dependencies))) #> snd);
   170     mk_locale ((parameters, spec, intros, axioms), ((decls, notes), dependencies))) #> snd);
   165 
   171 
   166 fun change_locale name =
   172 fun change_locale name =
   167   LocalesData.map o apsnd o Symtab.map_entry name o map_locale o apsnd;
   173   LocalesData.map o apsnd o Symtab.map_entry name o map_locale o apsnd;
   168 
   174 
   169 fun print_locales thy =
   175 fun print_locales thy =
   172 
   178 
   173 
   179 
   174 (*** Primitive operations ***)
   180 (*** Primitive operations ***)
   175 
   181 
   176 fun params_of thy = snd o #parameters o the_locale thy;
   182 fun params_of thy = snd o #parameters o the_locale thy;
       
   183 
       
   184 fun intros_of thy = #intros o the_locale thy;
       
   185 
       
   186 fun axioms_of thy = #axioms o the_locale thy;
   177 
   187 
   178 fun instance_of thy name morph = params_of thy name |>
   188 fun instance_of thy name morph = params_of thy name |>
   179   map ((fn (b, T, _) => Free (Binding.base_name b, the T)) #> Morphism.term morph);
   189   map ((fn (b, T, _) => Free (Binding.base_name b, the T)) #> Morphism.term morph);
   180 
   190 
   181 fun specification_of thy = #spec o the_locale thy;
   191 fun specification_of thy = #spec o the_locale thy;