neuper@52123
|
1 |
theory KEStore
|
neuper@52123
|
2 |
imports Complex_Main
|
neuper@52123
|
3 |
begin
|
neuper@52123
|
4 |
ML_file "~~/src/Tools/isac/library.sml"
|
neuper@52123
|
5 |
ML_file "~~/src/Tools/isac/calcelems.sml"
|
neuper@52123
|
6 |
|
neuper@52123
|
7 |
section {* Knowledge elements for problems and methods *}
|
neuper@52123
|
8 |
ML {*
|
neuper@52139
|
9 |
(* Knowledge (and Exercises) are held by "KEStore" in Isac's Java front-end.
|
neuper@52123
|
10 |
In the front-end Knowledge comprises theories, problems and methods.
|
neuper@52123
|
11 |
Elements of problems and methods are defined in theories alongside
|
neuper@52123
|
12 |
the development of respective language elements.
|
neuper@52123
|
13 |
However, the structure of methods and problems is independent from theories'
|
neuper@52123
|
14 |
deductive structure. Thus respective structures are built in Build_Thydata.thy.
|
neuper@52139
|
15 |
|
neuper@52139
|
16 |
Most elements of problems and methods are implemented in "Knowledge/", but some
|
neuper@52139
|
17 |
of them are implemented in "ProgLang/" already; thus "KEStore.thy" got this
|
neuper@52139
|
18 |
location in the directory structure.
|
neuper@52123
|
19 |
*)
|
neuper@52123
|
20 |
signature KESTORE_ELEMS =
|
neuper@52123
|
21 |
sig
|
neuper@52123
|
22 |
val get_rlss: theory -> (rls' * (theory' * rls)) list
|
neuper@52123
|
23 |
val add_rlss: (rls' * (theory' * rls)) list -> theory -> theory
|
neuper@52123
|
24 |
val get_calcs: theory -> (prog_calcID * (calID * eval_fn)) list
|
neuper@52123
|
25 |
val add_calcs: (prog_calcID * (calID * eval_fn)) list -> theory -> theory
|
neuper@52123
|
26 |
(*etc*)
|
neuper@52123
|
27 |
end;
|
neuper@52123
|
28 |
|
neuper@52123
|
29 |
structure KEStore_Elems: KESTORE_ELEMS =
|
neuper@52123
|
30 |
struct
|
neuper@52139
|
31 |
fun union_overwrite eq l1 l2 = fold (insert eq) l2 (*..swapped..*) l1;
|
neuper@52123
|
32 |
|
neuper@52123
|
33 |
structure Data = Theory_Data (
|
neuper@52123
|
34 |
type T = (rls' * (theory' * rls)) list;
|
neuper@52123
|
35 |
val empty = [];
|
neuper@52123
|
36 |
val extend = I;
|
neuper@52141
|
37 |
val merge = merge_rlss;
|
neuper@52123
|
38 |
);
|
neuper@52123
|
39 |
fun get_rlss thy = Data.get thy
|
neuper@52139
|
40 |
fun add_rlss rlss = Data.map (union_overwrite rls_eq rlss)
|
neuper@52123
|
41 |
|
neuper@52123
|
42 |
structure Data = Theory_Data (
|
neuper@52123
|
43 |
type T = (prog_calcID * (calID * eval_fn)) list;
|
neuper@52123
|
44 |
val empty = [];
|
neuper@52123
|
45 |
val extend = I;
|
neuper@52123
|
46 |
val merge = merge calc_eq;
|
neuper@52123
|
47 |
);
|
neuper@52123
|
48 |
fun get_calcs thy = Data.get thy
|
neuper@52139
|
49 |
fun add_calcs calcs = Data.map (union_overwrite calc_eq calcs)
|
neuper@52123
|
50 |
|
neuper@52123
|
51 |
(*etc*)
|
neuper@52123
|
52 |
end;
|
neuper@52123
|
53 |
*}
|
neuper@52123
|
54 |
|
neuper@52123
|
55 |
section {* Re-use existing access functions for knowledge elements *}
|
neuper@52123
|
56 |
text {*
|
neuper@52123
|
57 |
The independence of problems' and methods' structure enforces the accesse
|
neuper@52123
|
58 |
functions to use "Isac", the final theory which comprises all knowledge defined.
|
neuper@52123
|
59 |
*}
|
neuper@52124
|
60 |
ML {*
|
neuper@52142
|
61 |
(* in this phase of removing Unsynchornized.ref we do NOT overwrite the existing function! *)
|
neuper@52125
|
62 |
fun assoc_rls (rls' : rls') = (*SWITCH outcommented*)
|
neuper@52123
|
63 |
case AList.lookup (op =) (KEStore_Elems.get_rlss (Thy_Info.get_theory "Isac")) rls' of
|
neuper@52123
|
64 |
SOME (_, rls) => rls
|
neuper@52123
|
65 |
| NONE => raise ERROR ("rls \""^ rls' ^ "\" missing in KEStore.\n" ^
|
neuper@52123
|
66 |
"TODO exception hierarchy needs to be established.")
|
neuper@52142
|
67 |
|
neuper@52142
|
68 |
fun assoc_rls' thy (rls' : rls') = (*SWITCH outcommented*)
|
neuper@52142
|
69 |
case AList.lookup (op =) (KEStore_Elems.get_rlss thy) rls' of
|
neuper@52142
|
70 |
SOME (_, rls) => rls
|
neuper@52142
|
71 |
| NONE => raise ERROR ("rls \""^ rls' ^ "\" missing in KEStore.\n" ^
|
neuper@52142
|
72 |
"TODO exception hierarchy needs to be established.")
|
neuper@52142
|
73 |
|
s1210629013@52153
|
74 |
fun assoc_calc thy calID = let
|
s1210629013@52153
|
75 |
fun ass ([], key) =
|
s1210629013@52153
|
76 |
error ("assoc_calc: '" ^ key ^ "' not found in theory " ^ (Context.theory_name thy))
|
s1210629013@52153
|
77 |
| ass ((calc, (keyi, _)) :: pairs, key) =
|
s1210629013@52153
|
78 |
if key = keyi then calc else ass (pairs, key);
|
s1210629013@52153
|
79 |
in ass (thy |> KEStore_Elems.get_calcs, calID) end;
|
s1210629013@52145
|
80 |
|
s1210629013@52153
|
81 |
fun assoc_calc' thy key = let
|
s1210629013@52153
|
82 |
fun ass ([], key') =
|
s1210629013@52153
|
83 |
error ("assoc_calc': '" ^ key' ^ "' not found in theory " ^ (Context.theory_name thy))
|
s1210629013@52153
|
84 |
| ass ((all as (keyi, _)) :: pairs, key') =
|
s1210629013@52153
|
85 |
if key' = keyi then all else ass (pairs, key');
|
s1210629013@52153
|
86 |
in ass (KEStore_Elems.get_calcs thy, key) end;
|
neuper@52124
|
87 |
*}
|
neuper@52125
|
88 |
setup {* KEStore_Elems.add_rlss
|
neuper@52125
|
89 |
[("e_rls", (Context.theory_name @{theory}, e_rls)),
|
neuper@52125
|
90 |
("e_rrls", (Context.theory_name @{theory}, e_rrls))] *}
|
neuper@52123
|
91 |
|
neuper@52128
|
92 |
section {* Functions for checking KEStore_Elems *}
|
neuper@52128
|
93 |
ML {*
|
neuper@52128
|
94 |
fun short_string_of_rls Erls = "Erls"
|
neuper@52128
|
95 |
| short_string_of_rls (Rls {calc, rules, ...}) =
|
neuper@52128
|
96 |
"Rls {#calc = " ^ string_of_int (length calc) ^
|
neuper@52128
|
97 |
", #rules = " ^ string_of_int (length rules) ^ ", ..."
|
neuper@52128
|
98 |
| short_string_of_rls (Seq {calc, rules, ...}) =
|
neuper@52128
|
99 |
"Seq {#calc = " ^ string_of_int (length calc) ^
|
neuper@52128
|
100 |
", #rules = " ^ string_of_int (length rules) ^ ", ..."
|
neuper@52128
|
101 |
| short_string_of_rls (Rrls _) = "Rrls {...}";
|
neuper@52128
|
102 |
|
neuper@52128
|
103 |
fun check_kestore_rls (rls', (thyID, rls)) =
|
neuper@52128
|
104 |
"(" ^ rls' ^ ", (" ^ thyID ^ ", " ^ short_string_of_rls rls ^ "))";
|
s1210629013@52151
|
105 |
|
s1210629013@52151
|
106 |
fun string_of_calc ((id, (c, _)) : calc) = "(" ^ id ^ ", (" ^ c ^ ", fn))"
|
neuper@52128
|
107 |
*}
|
neuper@52123
|
108 |
end
|