17 } |
17 } |
18 val add_typecopy: bstring * string list -> typ -> (bstring * bstring) option |
18 val add_typecopy: bstring * string list -> typ -> (bstring * bstring) option |
19 -> theory -> (string * info) * theory |
19 -> theory -> (string * info) * theory |
20 val get_typecopies: theory -> string list |
20 val get_typecopies: theory -> string list |
21 val get_typecopy_info: theory -> string -> info option |
21 val get_typecopy_info: theory -> string -> info option |
22 val interpretation: (string * info -> theory -> theory) -> theory -> theory |
22 val interpretation: (string -> theory -> theory) -> theory -> theory |
23 val get_spec: theory -> string -> (string * sort) list * (string * typ list) list |
23 val get_spec: theory -> string -> (string * sort) list * (string * typ list) list |
24 val get_eq: theory -> string -> thm |
24 val get_eq: theory -> string -> thm |
25 val print_typecopies: theory -> unit |
25 val print_typecopies: theory -> unit |
26 val setup: theory -> theory |
26 val setup: theory -> theory |
27 end; |
27 end; |
66 |
66 |
67 val get_typecopies = Symtab.keys o TypecopyData.get; |
67 val get_typecopies = Symtab.keys o TypecopyData.get; |
68 val get_typecopy_info = Symtab.lookup o TypecopyData.get; |
68 val get_typecopy_info = Symtab.lookup o TypecopyData.get; |
69 |
69 |
70 |
70 |
71 (* interpretation *) |
71 (* interpretation of type copies *) |
72 |
72 |
73 structure TypecopyInterpretation = InterpretationFun(type T = string val eq = op =); |
73 structure TypecopyInterpretation = InterpretationFun(type T = string val eq = op =); |
74 |
74 val interpretation = TypecopyInterpretation.interpretation; |
75 fun interpretation interp = TypecopyInterpretation.interpretation |
|
76 (fn tyco => fn thy => interp (tyco, (the o get_typecopy_info thy) tyco) thy); |
|
77 |
75 |
78 |
76 |
79 (* add a type copy *) |
77 (* add a type copy *) |
80 |
78 |
81 local |
79 local |
121 val add_typecopy = gen_add_typecopy Sign.certify_typ; |
119 val add_typecopy = gen_add_typecopy Sign.certify_typ; |
122 |
120 |
123 end; |
121 end; |
124 |
122 |
125 |
123 |
126 (* equality function equation and datatype specification *) |
124 (* code generator setup *) |
127 |
|
128 fun get_eq thy tyco = |
|
129 (#inject o the o get_typecopy_info thy) tyco; |
|
130 |
125 |
131 fun get_spec thy tyco = |
126 fun get_spec thy tyco = |
132 let |
127 let |
133 val SOME { vs, constr, typ, ... } = get_typecopy_info thy tyco |
128 val SOME { vs, constr, typ, ... } = get_typecopy_info thy tyco |
134 in (vs, [(constr, [typ])]) end; |
129 in (vs, [(constr, [typ])]) end; |
135 |
130 |
|
131 fun get_eq thy tyco = |
|
132 (#inject o the o get_typecopy_info thy) tyco; |
136 |
133 |
137 (* interpretation for projection function code *) |
134 fun add_typecopy_spec tyco thy = |
|
135 let |
|
136 val c = (#constr o the o get_typecopy_info thy) tyco; |
|
137 val ty = Logic.unvarifyT (Sign.the_const_type thy c); |
|
138 in |
|
139 thy |> Code.add_datatype [(c, ty)] |
|
140 end; |
138 |
141 |
139 fun add_project (_, {proj_def, ...} : info) = Code.add_default_func proj_def; |
142 fun add_project tyco thy = thy |> Code.add_default_func |
|
143 ((#proj_def o the o get_typecopy_info thy) tyco); |
140 |
144 |
141 val setup = TypecopyInterpretation.init #> interpretation add_project; |
145 val setup = |
|
146 TypecopyInterpretation.init |
|
147 #> interpretation add_typecopy_spec |
|
148 #> interpretation add_project |
142 |
149 |
143 end; |
150 end; |