2 Author: Stefan Berghofer, TU Muenchen |
2 Author: Stefan Berghofer, TU Muenchen |
3 |
3 |
4 Auxiliary functions for defining datatypes. |
4 Auxiliary functions for defining datatypes. |
5 *) |
5 *) |
6 |
6 |
|
7 signature DATATYPE_COMMON = |
|
8 sig |
|
9 type config |
|
10 val default_config : config |
|
11 datatype dtyp = |
|
12 DtTFree of string |
|
13 | DtType of string * (dtyp list) |
|
14 | DtRec of int; |
|
15 type descr |
|
16 type info |
|
17 end |
|
18 |
7 signature DATATYPE_AUX = |
19 signature DATATYPE_AUX = |
8 sig |
20 sig |
9 type datatype_config |
21 include DATATYPE_COMMON |
10 val default_datatype_config : datatype_config |
22 |
11 val message : datatype_config -> string -> unit |
23 val message : config -> string -> unit |
12 |
24 |
13 val add_path : bool -> string -> theory -> theory |
25 val add_path : bool -> string -> theory -> theory |
14 val parent_path : bool -> theory -> theory |
26 val parent_path : bool -> theory -> theory |
15 |
27 |
16 val store_thmss_atts : string -> string list -> attribute list list -> thm list list |
28 val store_thmss_atts : string -> string list -> attribute list list -> thm list list |
31 val exh_tac : (string -> thm) -> int -> tactic |
43 val exh_tac : (string -> thm) -> int -> tactic |
32 |
44 |
33 datatype simproc_dist = FewConstrs of thm list |
45 datatype simproc_dist = FewConstrs of thm list |
34 | ManyConstrs of thm * simpset; |
46 | ManyConstrs of thm * simpset; |
35 |
47 |
36 datatype dtyp = |
|
37 DtTFree of string |
|
38 | DtType of string * (dtyp list) |
|
39 | DtRec of int; |
|
40 type descr |
|
41 type datatype_info |
|
42 |
48 |
43 exception Datatype |
49 exception Datatype |
44 exception Datatype_Empty of string |
50 exception Datatype_Empty of string |
45 val name_of_typ : typ -> string |
51 val name_of_typ : typ -> string |
46 val dtyp_of_typ : (string * string list) list -> typ -> dtyp |
52 val dtyp_of_typ : (string * string list) list -> typ -> dtyp |
59 val interpret_construction : descr -> (string * sort) list |
65 val interpret_construction : descr -> (string * sort) list |
60 -> { atyp: typ -> 'a, dtyp: typ list -> int * bool -> string * typ list -> 'a } |
66 -> { atyp: typ -> 'a, dtyp: typ list -> int * bool -> string * typ list -> 'a } |
61 -> ((string * Term.typ list) * (string * 'a list) list) list |
67 -> ((string * Term.typ list) * (string * 'a list) list) list |
62 val check_nonempty : descr list -> unit |
68 val check_nonempty : descr list -> unit |
63 val unfold_datatypes : |
69 val unfold_datatypes : |
64 theory -> descr -> (string * sort) list -> datatype_info Symtab.table -> |
70 theory -> descr -> (string * sort) list -> info Symtab.table -> |
65 descr -> int -> descr list * int |
71 descr -> int -> descr list * int |
66 end; |
72 end; |
67 |
73 |
68 structure DatatypeAux : DATATYPE_AUX = |
74 structure DatatypeAux : DATATYPE_AUX = |
69 struct |
75 struct |
70 |
76 |
71 (* datatype option flags *) |
77 (* datatype option flags *) |
72 |
78 |
73 type datatype_config = { strict: bool, flat_names: bool, quiet: bool }; |
79 type config = { strict: bool, flat_names: bool, quiet: bool }; |
74 val default_datatype_config : datatype_config = |
80 val default_config : config = |
75 { strict = true, flat_names = false, quiet = false }; |
81 { strict = true, flat_names = false, quiet = false }; |
76 fun message ({ quiet, ...} : datatype_config) s = |
82 fun message ({ quiet, ...} : config) s = |
77 if quiet then () else writeln s; |
83 if quiet then () else writeln s; |
78 |
84 |
79 fun add_path flat_names s = if flat_names then I else Sign.add_path s; |
85 fun add_path flat_names s = if flat_names then I else Sign.add_path s; |
80 fun parent_path flat_names = if flat_names then I else Sign.parent_path; |
86 fun parent_path flat_names = if flat_names then I else Sign.parent_path; |
81 |
87 |
184 (* information about datatypes *) |
190 (* information about datatypes *) |
185 |
191 |
186 (* index, datatype name, type arguments, constructor name, types of constructor's arguments *) |
192 (* index, datatype name, type arguments, constructor name, types of constructor's arguments *) |
187 type descr = (int * (string * dtyp list * (string * dtyp list) list)) list; |
193 type descr = (int * (string * dtyp list * (string * dtyp list) list)) list; |
188 |
194 |
189 type datatype_info = |
195 type info = |
190 {index : int, |
196 {index : int, |
191 alt_names : string list option, |
197 alt_names : string list option, |
192 descr : descr, |
198 descr : descr, |
193 sorts : (string * sort) list, |
199 sorts : (string * sort) list, |
194 rec_names : string list, |
200 rec_names : string list, |
315 |
321 |
316 (* unfold a list of mutually recursive datatype specifications *) |
322 (* unfold a list of mutually recursive datatype specifications *) |
317 (* all types of the form DtType (dt_name, [..., DtRec _, ...]) *) |
323 (* all types of the form DtType (dt_name, [..., DtRec _, ...]) *) |
318 (* need to be unfolded *) |
324 (* need to be unfolded *) |
319 |
325 |
320 fun unfold_datatypes sign orig_descr sorts (dt_info : datatype_info Symtab.table) descr i = |
326 fun unfold_datatypes sign orig_descr sorts (dt_info : info Symtab.table) descr i = |
321 let |
327 let |
322 fun typ_error T msg = error ("Non-admissible type expression\n" ^ |
328 fun typ_error T msg = error ("Non-admissible type expression\n" ^ |
323 Syntax.string_of_typ_global sign (typ_of_dtyp (orig_descr @ descr) sorts T) ^ "\n" ^ msg); |
329 Syntax.string_of_typ_global sign (typ_of_dtyp (orig_descr @ descr) sorts T) ^ "\n" ^ msg); |
324 |
330 |
325 fun get_dt_descr T i tname dts = |
331 fun get_dt_descr T i tname dts = |