4 Theory extender for domain command, including theory syntax. |
4 Theory extender for domain command, including theory syntax. |
5 *) |
5 *) |
6 |
6 |
7 signature DOMAIN_EXTENDER = |
7 signature DOMAIN_EXTENDER = |
8 sig |
8 sig |
9 val add_domain_cmd: string -> (string list * binding * mixfix * |
9 val add_domain_cmd: string -> |
10 (binding * (bool * binding option * string) list * mixfix) list) list |
10 ((string * string option) list * binding * mixfix * |
|
11 (binding * (bool * binding option * string) list * mixfix) list) list |
11 -> theory -> theory |
12 -> theory -> theory |
12 val add_domain: string -> (string list * binding * mixfix * |
13 val add_domain: string -> |
13 (binding * (bool * binding option * typ) list * mixfix) list) list |
14 ((string * string option) list * binding * mixfix * |
|
15 (binding * (bool * binding option * typ) list * mixfix) list) list |
14 -> theory -> theory |
16 -> theory -> theory |
15 end; |
17 end; |
16 |
18 |
17 structure Domain_Extender :> DOMAIN_EXTENDER = |
19 structure Domain_Extender :> DOMAIN_EXTENDER = |
18 struct |
20 struct |
83 (* ----- calls for building new thy and thms -------------------------------- *) |
85 (* ----- calls for building new thy and thms -------------------------------- *) |
84 |
86 |
85 fun gen_add_domain |
87 fun gen_add_domain |
86 (prep_typ : theory -> 'a -> typ) |
88 (prep_typ : theory -> 'a -> typ) |
87 (comp_dnam : string) |
89 (comp_dnam : string) |
88 (eqs''' : (string list * binding * mixfix * |
90 (eqs''' : ((string * string option) list * binding * mixfix * |
89 (binding * (bool * binding option * 'a) list * mixfix) list) list) |
91 (binding * (bool * binding option * 'a) list * mixfix) list) list) |
90 (thy''' : theory) = |
92 (thy''' : theory) = |
91 let |
93 let |
|
94 fun readS (SOME s) = Syntax.read_sort_global thy''' s |
|
95 | readS NONE = Sign.defaultS thy'''; |
|
96 fun readTFree (a, s) = TFree (a, readS s); |
|
97 |
92 val dtnvs = map (fn (vs,dname:binding,mx,_) => |
98 val dtnvs = map (fn (vs,dname:binding,mx,_) => |
93 (dname, map (Syntax.read_typ_global thy''') vs, mx)) eqs'''; |
99 (dname, map readTFree vs, mx)) eqs'''; |
94 val cons''' = map (fn (_,_,_,cons) => cons) eqs'''; |
100 val cons''' = map (fn (_,_,_,cons) => cons) eqs'''; |
95 fun thy_type (dname,tvars,mx) = (dname, length tvars, mx); |
101 fun thy_type (dname,tvars,mx) = (dname, length tvars, mx); |
96 fun thy_arity (dname,tvars,mx) = (Sign.full_name thy''' dname, map (snd o dest_TFree) tvars, pcpoS); |
102 fun thy_arity (dname,tvars,mx) = (Sign.full_name thy''' dname, map (snd o dest_TFree) tvars, pcpoS); |
97 val thy'' = thy''' |> Sign.add_types (map thy_type dtnvs) |
103 val thy'' = thy''' |> Sign.add_types (map thy_type dtnvs) |
98 |> fold (AxClass.axiomatize_arity o thy_arity) dtnvs; |
104 |> fold (AxClass.axiomatize_arity o thy_arity) dtnvs; |
146 || P.typ >> (fn t => (false,NONE,t)); |
152 || P.typ >> (fn t => (false,NONE,t)); |
147 |
153 |
148 val cons_decl = |
154 val cons_decl = |
149 P.binding -- Scan.repeat dest_decl -- P.opt_mixfix; |
155 P.binding -- Scan.repeat dest_decl -- P.opt_mixfix; |
150 |
156 |
151 val type_var' = |
157 val type_var' : (string * string option) parser = |
152 (P.type_ident ^^ Scan.optional (P.$$$ "::" ^^ P.!!! P.sort) ""); |
158 (P.type_ident -- Scan.option (P.$$$ "::" |-- P.!!! P.sort)); |
153 |
159 |
154 val type_args' = |
160 val type_args' : (string * string option) list parser = |
155 type_var' >> single || |
161 type_var' >> single || |
156 P.$$$ "(" |-- P.!!! (P.list1 type_var' --| P.$$$ ")") || |
162 P.$$$ "(" |-- P.!!! (P.list1 type_var' --| P.$$$ ")") || |
157 Scan.succeed []; |
163 Scan.succeed []; |
158 |
164 |
159 val domain_decl = |
165 val domain_decl = |
162 |
168 |
163 val domains_decl = |
169 val domains_decl = |
164 Scan.option (P.$$$ "(" |-- P.name --| P.$$$ ")") -- |
170 Scan.option (P.$$$ "(" |-- P.name --| P.$$$ ")") -- |
165 P.and_list1 domain_decl; |
171 P.and_list1 domain_decl; |
166 |
172 |
167 fun mk_domain (opt_name : string option, doms : (((string list * binding) * mixfix) * |
173 fun mk_domain (opt_name : string option, |
|
174 doms : ((((string * string option) list * binding) * mixfix) * |
168 ((binding * (bool * binding option * string) list) * mixfix) list) list ) = |
175 ((binding * (bool * binding option * string) list) * mixfix) list) list ) = |
169 let |
176 let |
170 val names = map (fn (((_, t), _), _) => Binding.name_of t) doms; |
177 val names = map (fn (((_, t), _), _) => Binding.name_of t) doms; |
171 val specs : (string list * binding * mixfix * |
178 val specs : ((string * string option) list * binding * mixfix * |
172 (binding * (bool * binding option * string) list * mixfix) list) list = |
179 (binding * (bool * binding option * string) list * mixfix) list) list = |
173 map (fn (((vs, t), mx), cons) => |
180 map (fn (((vs, t), mx), cons) => |
174 (vs, t, mx, map (fn ((c, ds), mx) => (c, ds, mx)) cons)) doms; |
181 (vs, t, mx, map (fn ((c, ds), mx) => (c, ds, mx)) cons)) doms; |
175 val comp_dnam = |
182 val comp_dnam = |
176 case opt_name of NONE => space_implode "_" names | SOME s => s; |
183 case opt_name of NONE => space_implode "_" names | SOME s => s; |