author | Lars Hupel <lars.hupel@mytum.de> |
Wed, 05 Apr 2017 10:26:28 +0200 | |
changeset 65387 | 5dbe02addca5 |
parent 63183 | 4d04e14d7ab8 |
child 67149 | e61557884799 |
permissions | -rw-r--r-- |
34232
36a2a3029fd3
new year's resolution: reindented code in function package
krauss
parents:
34231
diff
changeset
|
1 |
(* Title: HOL/Tools/Function/function_common.ML |
33099
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
2 |
Author: Alexander Krauss, TU Muenchen |
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
3 |
|
41114 | 4 |
Common definitions and other infrastructure for the function package. |
33099
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
5 |
*) |
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
6 |
|
34230 | 7 |
signature FUNCTION_DATA = |
8 |
sig |
|
59159 | 9 |
type info = |
10 |
{is_partial : bool, |
|
63004 | 11 |
defname : binding, |
59159 | 12 |
(*contains no logical entities: invariant under morphisms:*) |
13 |
add_simps : (binding -> binding) -> string -> (binding -> binding) -> |
|
14 |
Token.src list -> thm list -> local_theory -> thm list * local_theory, |
|
63004 | 15 |
fnames : binding list, |
59159 | 16 |
case_names : string list, |
17 |
fs : term list, |
|
18 |
R : term, |
|
19 |
dom: term, |
|
20 |
psimps: thm list, |
|
21 |
pinducts: thm list, |
|
22 |
simps : thm list option, |
|
23 |
inducts : thm list option, |
|
24 |
termination : thm, |
|
65387
5dbe02addca5
store totality fact in function info
Lars Hupel <lars.hupel@mytum.de>
parents:
63183
diff
changeset
|
25 |
totality : thm option, |
59159 | 26 |
cases : thm list, |
27 |
pelims: thm list list, |
|
28 |
elims: thm list list option} |
|
34230 | 29 |
end |
30 |
||
31 |
structure Function_Data : FUNCTION_DATA = |
|
32 |
struct |
|
33 |
||
34 |
type info = |
|
35 |
{is_partial : bool, |
|
63004 | 36 |
defname : binding, |
59159 | 37 |
(*contains no logical entities: invariant under morphisms:*) |
34230 | 38 |
add_simps : (binding -> binding) -> string -> (binding -> binding) -> |
58011
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
wenzelm
parents:
57959
diff
changeset
|
39 |
Token.src list -> thm list -> local_theory -> thm list * local_theory, |
63004 | 40 |
fnames : binding list, |
34230 | 41 |
case_names : string list, |
42 |
fs : term list, |
|
43 |
R : term, |
|
52384 | 44 |
dom: term, |
34230 | 45 |
psimps: thm list, |
46 |
pinducts: thm list, |
|
34231 | 47 |
simps : thm list option, |
48 |
inducts : thm list option, |
|
52383 | 49 |
termination : thm, |
65387
5dbe02addca5
store totality fact in function info
Lars Hupel <lars.hupel@mytum.de>
parents:
63183
diff
changeset
|
50 |
totality : thm option, |
53603
59ef06cda7b9
generate elim rules for elimination of function equalities;
Manuel Eberl
parents:
52384
diff
changeset
|
51 |
cases : thm list, |
59ef06cda7b9
generate elim rules for elimination of function equalities;
Manuel Eberl
parents:
52384
diff
changeset
|
52 |
pelims : thm list list, |
59ef06cda7b9
generate elim rules for elimination of function equalities;
Manuel Eberl
parents:
52384
diff
changeset
|
53 |
elims : thm list list option} |
34230 | 54 |
|
55 |
end |
|
56 |
||
49965 | 57 |
signature FUNCTION_COMMON = |
58 |
sig |
|
59 |
include FUNCTION_DATA |
|
60 |
val profile : bool Unsynchronized.ref |
|
61 |
val PROFILE : string -> ('a -> 'b) -> 'a -> 'b |
|
62 |
val mk_acc : typ -> term -> term |
|
59159 | 63 |
val split_def : Proof.context -> (string -> 'a) -> term -> |
64 |
string * (string * typ) list * term list * term list * term |
|
65 |
val check_defs : Proof.context -> ((string * typ) * 'a) list -> term list -> unit |
|
66 |
type fixes = ((string * typ) * mixfix) list |
|
67 |
type 'a spec = (Attrib.binding * 'a list) list |
|
68 |
datatype function_config = FunctionConfig of |
|
69 |
{sequential: bool, |
|
70 |
default: string option, |
|
71 |
domintros: bool, |
|
72 |
partials: bool} |
|
73 |
type preproc = function_config -> Proof.context -> fixes -> term spec -> |
|
63010 | 74 |
term list * (thm list -> thm spec) * (thm list -> thm list list) * string list |
59159 | 75 |
val fname_of : term -> string |
76 |
val mk_case_names : int -> string -> int -> string list |
|
77 |
val empty_preproc : (Proof.context -> ((string * typ) * mixfix) list -> term list -> 'c) -> |
|
78 |
preproc |
|
79 |
val termination_rule_tac : Proof.context -> int -> tactic |
|
80 |
val store_termination_rule : thm -> Context.generic -> Context.generic |
|
81 |
val get_functions : Proof.context -> (term * info) Item_Net.T |
|
82 |
val add_function_data : info -> Context.generic -> Context.generic |
|
60682
5a6cd2560549
have the installed termination prover take a 'quiet' flag
blanchet
parents:
59621
diff
changeset
|
83 |
val termination_prover_tac : bool -> Proof.context -> tactic |
5a6cd2560549
have the installed termination prover take a 'quiet' flag
blanchet
parents:
59621
diff
changeset
|
84 |
val set_termination_prover : (bool -> Proof.context -> tactic) -> Context.generic -> |
5a6cd2560549
have the installed termination prover take a 'quiet' flag
blanchet
parents:
59621
diff
changeset
|
85 |
Context.generic |
59159 | 86 |
val get_preproc: Proof.context -> preproc |
87 |
val set_preproc: preproc -> Context.generic -> Context.generic |
|
49965 | 88 |
datatype function_result = FunctionResult of |
89 |
{fs: term list, |
|
90 |
G: term, |
|
91 |
R: term, |
|
52384 | 92 |
dom: term, |
49965 | 93 |
psimps : thm list, |
94 |
simple_pinducts : thm list, |
|
53603
59ef06cda7b9
generate elim rules for elimination of function equalities;
Manuel Eberl
parents:
52384
diff
changeset
|
95 |
cases : thm list, |
59ef06cda7b9
generate elim rules for elimination of function equalities;
Manuel Eberl
parents:
52384
diff
changeset
|
96 |
pelims : thm list list, |
49965 | 97 |
termination : thm, |
98 |
domintros : thm list option} |
|
63004 | 99 |
val transform_function_data : morphism -> info -> info |
49965 | 100 |
val import_function_data : term -> Proof.context -> info option |
101 |
val import_last_function : Proof.context -> info option |
|
102 |
val default_config : function_config |
|
103 |
val function_parser : function_config -> |
|
63183 | 104 |
(function_config * ((binding * string option * mixfix) list * Specification.multi_specs_cmd)) parser |
49965 | 105 |
end |
106 |
||
107 |
structure Function_Common : FUNCTION_COMMON = |
|
33099
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
108 |
struct |
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
109 |
|
34230 | 110 |
open Function_Data |
111 |
||
33099
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
112 |
local open Function_Lib in |
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
113 |
|
59159 | 114 |
|
115 |
(* profiling *) |
|
116 |
||
117 |
val profile = Unsynchronized.ref false |
|
33099
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
118 |
|
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
119 |
fun PROFILE msg = if !profile then timeap_msg msg else I |
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
120 |
|
54295 | 121 |
val acc_const_name = @{const_name Wellfounded.accp} |
33099
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
122 |
fun mk_acc domT R = |
59159 | 123 |
Const (acc_const_name, (domT --> domT --> HOLogic.boolT) --> domT --> HOLogic.boolT) $ R |
33099
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
124 |
|
59159 | 125 |
|
126 |
(* analyzing function equations *) |
|
127 |
||
128 |
fun split_def ctxt check_head geq = |
|
129 |
let |
|
130 |
fun input_error msg = cat_lines [msg, Syntax.string_of_term ctxt geq] |
|
131 |
val qs = Term.strip_qnt_vars @{const_name Pure.all} geq |
|
132 |
val imp = Term.strip_qnt_body @{const_name Pure.all} geq |
|
133 |
val (gs, eq) = Logic.strip_horn imp |
|
134 |
||
135 |
val (f_args, rhs) = HOLogic.dest_eq (HOLogic.dest_Trueprop eq) |
|
136 |
handle TERM _ => error (input_error "Not an equation") |
|
137 |
||
138 |
val (head, args) = strip_comb f_args |
|
139 |
||
140 |
val fname = fst (dest_Free head) handle TERM _ => "" |
|
141 |
val _ = check_head fname |
|
142 |
in |
|
143 |
(fname, qs, gs, args, rhs) |
|
144 |
end |
|
145 |
||
63002
56cf1249ee20
removed pointless check (see Type_Infer.object_logic);
wenzelm
parents:
61112
diff
changeset
|
146 |
(*check for various errors in the input*) |
59159 | 147 |
fun check_defs ctxt fixes eqs = |
148 |
let |
|
149 |
val fnames = map (fst o fst) fixes |
|
150 |
||
151 |
fun check geq = |
|
152 |
let |
|
153 |
fun input_error msg = error (cat_lines [msg, Syntax.string_of_term ctxt geq]) |
|
154 |
||
155 |
fun check_head fname = |
|
156 |
member (op =) fnames fname orelse |
|
157 |
input_error ("Illegal equation head. Expected " ^ commas_quote fnames) |
|
158 |
||
159 |
val (fname, qs, gs, args, rhs) = split_def ctxt check_head geq |
|
160 |
||
161 |
val _ = length args > 0 orelse input_error "Function has no arguments:" |
|
162 |
||
163 |
fun add_bvs t is = add_loose_bnos (t, 0, is) |
|
164 |
val rvs = (subtract (op =) (fold add_bvs args []) (add_bvs rhs [])) |
|
165 |
|> map (fst o nth (rev qs)) |
|
33099
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
166 |
|
59159 | 167 |
val _ = null rvs orelse input_error |
168 |
("Variable" ^ plural " " "s " rvs ^ commas_quote rvs ^ |
|
169 |
" occur" ^ plural "s" "" rvs ^ " on right hand side only:") |
|
170 |
||
171 |
val _ = forall (not o Term.exists_subterm |
|
172 |
(fn Free (n, _) => member (op =) fnames n | _ => false)) (gs @ args) |
|
173 |
orelse input_error "Defined function may not occur in premises or arguments" |
|
174 |
||
175 |
val freeargs = map (fn t => subst_bounds (rev (map Free qs), t)) args |
|
176 |
val funvars = |
|
177 |
filter |
|
178 |
(fn q => exists (exists_subterm (fn (Free q') $ _ => q = q' | _ => false)) freeargs) qs |
|
179 |
val _ = null funvars orelse (warning (cat_lines |
|
180 |
["Bound variable" ^ plural " " "s " funvars ^ |
|
181 |
commas_quote (map fst funvars) ^ " occur" ^ plural "s" "" funvars ^ |
|
182 |
" in function position.", "Misspelled constructor???"]); true) |
|
183 |
in |
|
184 |
(fname, length args) |
|
185 |
end |
|
33099
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
186 |
|
59159 | 187 |
val grouped_args = AList.group (op =) (map check eqs) |
188 |
val _ = grouped_args |
|
189 |
|> map (fn (fname, ars) => |
|
190 |
length (distinct (op =) ars) = 1 orelse |
|
191 |
error ("Function " ^ quote fname ^ |
|
192 |
" has different numbers of arguments in different equations")) |
|
193 |
||
194 |
val not_defined = subtract (op =) (map fst grouped_args) fnames |
|
195 |
val _ = null not_defined |
|
196 |
orelse error ("No defining equations for function" ^ |
|
197 |
plural " " "s " not_defined ^ commas_quote not_defined) |
|
63002
56cf1249ee20
removed pointless check (see Type_Infer.object_logic);
wenzelm
parents:
61112
diff
changeset
|
198 |
in () end |
33099
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
199 |
|
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
200 |
|
59159 | 201 |
(* preprocessors *) |
202 |
||
203 |
type fixes = ((string * typ) * mixfix) list |
|
204 |
type 'a spec = (Attrib.binding * 'a list) list |
|
205 |
||
206 |
datatype function_config = FunctionConfig of |
|
207 |
{sequential: bool, |
|
208 |
default: string option, |
|
209 |
domintros: bool, |
|
210 |
partials: bool} |
|
211 |
||
212 |
type preproc = function_config -> Proof.context -> fixes -> term spec -> |
|
63010 | 213 |
term list * (thm list -> thm spec) * (thm list -> thm list list) * string list |
59159 | 214 |
|
215 |
val fname_of = fst o dest_Free o fst o strip_comb o fst o HOLogic.dest_eq o |
|
216 |
HOLogic.dest_Trueprop o Logic.strip_imp_concl o snd o dest_all_all |
|
217 |
||
218 |
fun mk_case_names i "" k = mk_case_names i (string_of_int (i + 1)) k |
|
219 |
| mk_case_names _ _ 0 = [] |
|
220 |
| mk_case_names _ n 1 = [n] |
|
221 |
| mk_case_names _ n k = map (fn i => n ^ "_" ^ string_of_int i) (1 upto k) |
|
222 |
||
223 |
fun empty_preproc check (_: function_config) (ctxt: Proof.context) (fixes: fixes) spec = |
|
224 |
let |
|
225 |
val (bnds, tss) = split_list spec |
|
226 |
val ts = flat tss |
|
227 |
val _ = check ctxt fixes ts |
|
228 |
val fnames = map (fst o fst) fixes |
|
229 |
val indices = map (fn eq => find_index (curry op = (fname_of eq)) fnames) ts |
|
230 |
||
231 |
fun sort xs = partition_list (fn i => fn (j,_) => i = j) 0 (length fnames - 1) |
|
232 |
(indices ~~ xs) |> map (map snd) |
|
233 |
||
234 |
(* using theorem names for case name currently disabled *) |
|
235 |
val cnames = map_index (fn (i, _) => mk_case_names i "" 1) bnds |> flat |
|
236 |
in |
|
237 |
(ts, curry op ~~ bnds o Library.unflat tss, sort, cnames) |
|
238 |
end |
|
239 |
||
240 |
||
241 |
(* context data *) |
|
242 |
||
243 |
structure Data = Generic_Data |
|
244 |
( |
|
245 |
type T = |
|
246 |
thm list * |
|
247 |
(term * info) Item_Net.T * |
|
60682
5a6cd2560549
have the installed termination prover take a 'quiet' flag
blanchet
parents:
59621
diff
changeset
|
248 |
(bool -> Proof.context -> tactic) * |
59159 | 249 |
preproc |
250 |
val empty: T = |
|
251 |
([], |
|
252 |
Item_Net.init (op aconv o apply2 fst) (single o fst), |
|
253 |
fn _ => error "Termination prover not configured", |
|
254 |
empty_preproc check_defs) |
|
255 |
val extend = I |
|
256 |
fun merge |
|
257 |
((termination_rules1, functions1, termination_prover1, preproc1), |
|
258 |
(termination_rules2, functions2, _, _)) : T = |
|
259 |
(Thm.merge_thms (termination_rules1, termination_rules2), |
|
260 |
Item_Net.merge (functions1, functions2), |
|
261 |
termination_prover1, |
|
262 |
preproc1) |
|
263 |
) |
|
264 |
||
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59159
diff
changeset
|
265 |
fun termination_rule_tac ctxt = resolve_tac ctxt (#1 (Data.get (Context.Proof ctxt))) |
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59159
diff
changeset
|
266 |
|
61112 | 267 |
val store_termination_rule = Data.map o @{apply 4(1)} o cons o Thm.trim_context |
59159 | 268 |
|
269 |
val get_functions = #2 o Data.get o Context.Proof |
|
270 |
fun add_function_data (info : info as {fs, termination, ...}) = |
|
271 |
(Data.map o @{apply 4(2)}) (fold (fn f => Item_Net.update (f, info)) fs) |
|
272 |
#> store_termination_rule termination |
|
273 |
||
60682
5a6cd2560549
have the installed termination prover take a 'quiet' flag
blanchet
parents:
59621
diff
changeset
|
274 |
fun termination_prover_tac quiet ctxt = #3 (Data.get (Context.Proof ctxt)) quiet ctxt |
59159 | 275 |
val set_termination_prover = Data.map o @{apply 4(3)} o K |
276 |
||
277 |
val get_preproc = #4 o Data.get o Context.Proof |
|
278 |
val set_preproc = Data.map o @{apply 4(4)} o K |
|
279 |
||
280 |
||
281 |
(* function definition result data *) |
|
33099
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
282 |
|
34232
36a2a3029fd3
new year's resolution: reindented code in function package
krauss
parents:
34231
diff
changeset
|
283 |
datatype function_result = FunctionResult of |
36a2a3029fd3
new year's resolution: reindented code in function package
krauss
parents:
34231
diff
changeset
|
284 |
{fs: term list, |
36a2a3029fd3
new year's resolution: reindented code in function package
krauss
parents:
34231
diff
changeset
|
285 |
G: term, |
36a2a3029fd3
new year's resolution: reindented code in function package
krauss
parents:
34231
diff
changeset
|
286 |
R: term, |
52384 | 287 |
dom: term, |
34232
36a2a3029fd3
new year's resolution: reindented code in function package
krauss
parents:
34231
diff
changeset
|
288 |
psimps : thm list, |
36a2a3029fd3
new year's resolution: reindented code in function package
krauss
parents:
34231
diff
changeset
|
289 |
simple_pinducts : thm list, |
53603
59ef06cda7b9
generate elim rules for elimination of function equalities;
Manuel Eberl
parents:
52384
diff
changeset
|
290 |
cases : thm list, |
59ef06cda7b9
generate elim rules for elimination of function equalities;
Manuel Eberl
parents:
52384
diff
changeset
|
291 |
pelims : thm list list, |
34232
36a2a3029fd3
new year's resolution: reindented code in function package
krauss
parents:
34231
diff
changeset
|
292 |
termination : thm, |
36a2a3029fd3
new year's resolution: reindented code in function package
krauss
parents:
34231
diff
changeset
|
293 |
domintros : thm list option} |
33099
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
294 |
|
63004 | 295 |
fun transform_function_data phi ({add_simps, case_names, fnames, fs, R, dom, psimps, pinducts, |
65387
5dbe02addca5
store totality fact in function info
Lars Hupel <lars.hupel@mytum.de>
parents:
63183
diff
changeset
|
296 |
simps, inducts, termination, totality, defname, is_partial, cases, pelims, elims} : info) = |
33099
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
297 |
let |
45290 | 298 |
val term = Morphism.term phi |
299 |
val thm = Morphism.thm phi |
|
300 |
val fact = Morphism.fact phi |
|
33099
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
301 |
in |
53603
59ef06cda7b9
generate elim rules for elimination of function equalities;
Manuel Eberl
parents:
52384
diff
changeset
|
302 |
{ add_simps = add_simps, case_names = case_names, fnames = fnames, |
52384 | 303 |
fs = map term fs, R = term R, dom = term dom, psimps = fact psimps, |
34231 | 304 |
pinducts = fact pinducts, simps = Option.map fact simps, |
305 |
inducts = Option.map fact inducts, termination = thm termination, |
|
65387
5dbe02addca5
store totality fact in function info
Lars Hupel <lars.hupel@mytum.de>
parents:
63183
diff
changeset
|
306 |
totality = Option.map thm totality, defname = Morphism.binding phi defname, |
5dbe02addca5
store totality fact in function info
Lars Hupel <lars.hupel@mytum.de>
parents:
63183
diff
changeset
|
307 |
is_partial = is_partial, cases = fact cases, |
53603
59ef06cda7b9
generate elim rules for elimination of function equalities;
Manuel Eberl
parents:
52384
diff
changeset
|
308 |
elims = Option.map (map fact) elims, pelims = map fact pelims } |
33099
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
309 |
end |
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
310 |
|
59618 | 311 |
fun lift_morphism ctxt f = |
34232
36a2a3029fd3
new year's resolution: reindented code in function package
krauss
parents:
34231
diff
changeset
|
312 |
let |
59621
291934bac95e
Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents:
59618
diff
changeset
|
313 |
fun term t = Thm.term_of (Drule.cterm_rule f (Thm.cterm_of ctxt t)) |
34232
36a2a3029fd3
new year's resolution: reindented code in function package
krauss
parents:
34231
diff
changeset
|
314 |
in |
54740 | 315 |
Morphism.morphism "lift_morphism" |
316 |
{binding = [], |
|
317 |
typ = [Logic.type_map term], |
|
318 |
term = [term], |
|
319 |
fact = [map f]} |
|
34232
36a2a3029fd3
new year's resolution: reindented code in function package
krauss
parents:
34231
diff
changeset
|
320 |
end |
33099
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
321 |
|
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
322 |
fun import_function_data t ctxt = |
34232
36a2a3029fd3
new year's resolution: reindented code in function package
krauss
parents:
34231
diff
changeset
|
323 |
let |
59621
291934bac95e
Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents:
59618
diff
changeset
|
324 |
val ct = Thm.cterm_of ctxt t |
59618 | 325 |
val inst_morph = lift_morphism ctxt o Thm.instantiate |
33099
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
326 |
|
34232
36a2a3029fd3
new year's resolution: reindented code in function package
krauss
parents:
34231
diff
changeset
|
327 |
fun match (trm, data) = |
63004 | 328 |
SOME (transform_function_data (inst_morph (Thm.match (Thm.cterm_of ctxt trm, ct))) data) |
59618 | 329 |
handle Pattern.MATCH => NONE |
34232
36a2a3029fd3
new year's resolution: reindented code in function package
krauss
parents:
34231
diff
changeset
|
330 |
in |
59159 | 331 |
get_first match (Item_Net.retrieve (get_functions ctxt) t) |
34232
36a2a3029fd3
new year's resolution: reindented code in function package
krauss
parents:
34231
diff
changeset
|
332 |
end |
33099
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
333 |
|
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
334 |
fun import_last_function ctxt = |
59159 | 335 |
(case Item_Net.content (get_functions ctxt) of |
34232
36a2a3029fd3
new year's resolution: reindented code in function package
krauss
parents:
34231
diff
changeset
|
336 |
[] => NONE |
49966 | 337 |
| (t, _) :: _ => |
59159 | 338 |
let val ([t'], ctxt') = Variable.import_terms true [t] ctxt |
339 |
in import_function_data t' ctxt' end) |
|
33099
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
340 |
|
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
341 |
|
59159 | 342 |
(* configuration management *) |
33099
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
343 |
|
59159 | 344 |
datatype function_opt = |
345 |
Sequential |
|
33099
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
346 |
| Default of string |
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
347 |
| DomIntros |
33101 | 348 |
| No_Partials |
33099
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
349 |
|
59159 | 350 |
fun apply_opt Sequential (FunctionConfig {sequential = _, default, domintros, partials}) = |
351 |
FunctionConfig |
|
352 |
{sequential = true, default = default, domintros = domintros, partials = partials} |
|
353 |
| apply_opt (Default d) (FunctionConfig {sequential, default = _, domintros, partials}) = |
|
354 |
FunctionConfig |
|
355 |
{sequential = sequential, default = SOME d, domintros = domintros, partials = partials} |
|
356 |
| apply_opt DomIntros (FunctionConfig {sequential, default, domintros = _, partials}) = |
|
357 |
FunctionConfig |
|
358 |
{sequential = sequential, default = default, domintros = true, partials = partials} |
|
359 |
| apply_opt No_Partials (FunctionConfig {sequential, default, domintros, partials = _}) = |
|
360 |
FunctionConfig |
|
361 |
{sequential = sequential, default = default, domintros = domintros, partials = false} |
|
33099
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
362 |
|
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
363 |
val default_config = |
41417 | 364 |
FunctionConfig { sequential=false, default=NONE, |
41846
b368a7aee46a
removed support for tail-recursion from function package (now implemented by partial_function)
krauss
parents:
41417
diff
changeset
|
365 |
domintros=false, partials=true} |
33099
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
366 |
|
34232
36a2a3029fd3
new year's resolution: reindented code in function package
krauss
parents:
34231
diff
changeset
|
367 |
local |
44357 | 368 |
val option_parser = Parse.group (fn () => "option") |
36960
01594f816e3a
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents:
36954
diff
changeset
|
369 |
((Parse.reserved "sequential" >> K Sequential) |
01594f816e3a
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents:
36954
diff
changeset
|
370 |
|| ((Parse.reserved "default" |-- Parse.term) >> Default) |
01594f816e3a
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents:
36954
diff
changeset
|
371 |
|| (Parse.reserved "domintros" >> K DomIntros) |
41846
b368a7aee46a
removed support for tail-recursion from function package (now implemented by partial_function)
krauss
parents:
41417
diff
changeset
|
372 |
|| (Parse.reserved "no_partials" >> K No_Partials)) |
33099
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
373 |
|
34232
36a2a3029fd3
new year's resolution: reindented code in function package
krauss
parents:
34231
diff
changeset
|
374 |
fun config_parser default = |
46949 | 375 |
(Scan.optional (@{keyword "("} |-- Parse.!!! (Parse.list1 option_parser) --| @{keyword ")"}) []) |
34232
36a2a3029fd3
new year's resolution: reindented code in function package
krauss
parents:
34231
diff
changeset
|
376 |
>> (fn opts => fold apply_opt opts default) |
33099
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
377 |
in |
34232
36a2a3029fd3
new year's resolution: reindented code in function package
krauss
parents:
34231
diff
changeset
|
378 |
fun function_parser default_cfg = |
63183 | 379 |
config_parser default_cfg -- Parse_Spec.specification |
33099
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
380 |
end |
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
381 |
|
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
382 |
|
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
383 |
end |
b8cdd3d73022
function package: more standard names for structures and files
krauss
parents:
diff
changeset
|
384 |
end |