equal
deleted
inserted
replaced
3 Author: Markus Wenzel, TU Muenchen |
3 Author: Markus Wenzel, TU Muenchen |
4 |
4 |
5 HOL theory data: datatypes. |
5 HOL theory data: datatypes. |
6 *) |
6 *) |
7 |
7 |
8 (*for datatypes*) |
|
9 type datatype_info = |
8 type datatype_info = |
10 {case_const: term, |
9 {case_const: term, |
11 case_rewrites: thm list, |
10 case_rewrites: thm list, |
12 constructors: term list, |
11 constructors: term list, |
13 induct_tac: string -> int -> tactic, |
12 induct_tac: string -> int -> tactic, |
27 |
26 |
28 structure ThyData: THY_DATA = |
27 structure ThyData: THY_DATA = |
29 struct |
28 struct |
30 |
29 |
31 |
30 |
32 (** datatypes **) |
|
33 |
|
34 (* data kind 'datatypes' *) |
31 (* data kind 'datatypes' *) |
35 |
32 |
36 val datatypesK = "HOL/datatypes"; |
33 local |
37 exception DatatypeInfo of datatype_info Symtab.table; |
34 val datatypesK = Object.kind "HOL/datatypes"; |
|
35 exception DatatypeInfo of datatype_info Symtab.table; |
38 |
36 |
39 local |
|
40 val empty = DatatypeInfo Symtab.empty; |
37 val empty = DatatypeInfo Symtab.empty; |
41 |
38 |
42 fun prep_ext (x as DatatypeInfo _) = x; |
39 fun prep_ext (x as DatatypeInfo _) = x; |
43 |
40 |
44 fun merge (DatatypeInfo tab1, DatatypeInfo tab2) = |
41 fun merge (DatatypeInfo tab1, DatatypeInfo tab2) = |
46 |
43 |
47 fun print sg (DatatypeInfo tab) = |
44 fun print sg (DatatypeInfo tab) = |
48 Pretty.writeln (Pretty.strs ("datatypes:" :: |
45 Pretty.writeln (Pretty.strs ("datatypes:" :: |
49 map (Sign.cond_extern sg Sign.typeK o fst) (Symtab.dest tab))); |
46 map (Sign.cond_extern sg Sign.typeK o fst) (Symtab.dest tab))); |
50 in |
47 in |
51 val datatypes_thy_data = (datatypesK, (empty, prep_ext, merge, print)); |
48 val init_datatypes = Theory.init_data datatypesK (empty, prep_ext, merge, print); |
|
49 val get_datatypes_sg = Sign.get_data datatypesK (fn DatatypeInfo tab => tab); |
|
50 val get_datatypes = get_datatypes_sg o sign_of; |
|
51 val put_datatypes = Theory.put_data datatypesK DatatypeInfo; |
52 end; |
52 end; |
53 |
53 |
54 |
54 |
55 (* get and put datatypes *) |
55 (* setup *) |
56 |
56 |
57 fun get_datatypes_sg sg = |
57 val setup = [init_datatypes]; |
58 (case Sign.get_data sg datatypesK of |
|
59 DatatypeInfo tab => tab |
|
60 | _ => type_error datatypesK); |
|
61 |
|
62 val get_datatypes = get_datatypes_sg o sign_of; |
|
63 |
|
64 fun put_datatypes tab thy = |
|
65 Theory.put_data (datatypesK, DatatypeInfo tab) thy; |
|
66 |
|
67 |
|
68 |
|
69 (** theory data setup **) |
|
70 |
|
71 val setup = [Theory.init_data [datatypes_thy_data]]; |
|
72 |
58 |
73 |
59 |
74 end; |
60 end; |