walther@59945
|
1 |
(* Title: BaseDefinitions/model-pattern.sml
|
walther@59882
|
2 |
Author: Walther Neuper
|
walther@59882
|
3 |
(c) due to copyright terms
|
walther@59882
|
4 |
|
walther@60004
|
5 |
A \<open>Model_Pattern\<close> defines a -> \<open>Problem\<close>-type: its \<open>variables\<close> are to be instantiated
|
walther@60004
|
6 |
by the values for particular \<open>Problem\<close>s.
|
walther@60004
|
7 |
The \<open>variables\<close> are used twice, in a model and as formal arguments in a \<open>Program\<close>.
|
walther@60004
|
8 |
The \<open>descriptor\<close>s are unique identifiers within one \<open>Model_Pattern\<close>.
|
walther@59945
|
9 |
*)
|
walther@59945
|
10 |
signature MODEL_PATTERN =
|
walther@59882
|
11 |
sig
|
walther@59945
|
12 |
type T
|
walther@59945
|
13 |
type single
|
walther@59945
|
14 |
val to_string: single list -> string
|
walther@59952
|
15 |
type m_field = string
|
walther@59952
|
16 |
type descriptor = term
|
walther@60004
|
17 |
|
walther@59987
|
18 |
val variables: T -> term list
|
walther@60004
|
19 |
val get_field: descriptor -> T -> m_field option
|
walther@59884
|
20 |
(* ---- for tests only: shifted from below to remove the Warning "unused" at fun.def. --------- *)
|
walther@59957
|
21 |
val to_string': T -> string
|
walther@59886
|
22 |
(*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
|
walther@59945
|
23 |
(*NONE*)
|
walther@59886
|
24 |
( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
|
walther@59882
|
25 |
end
|
walther@59882
|
26 |
|
walther@59882
|
27 |
(**)
|
walther@59945
|
28 |
structure Model_Pattern(**): MODEL_PATTERN(**) =
|
walther@59882
|
29 |
struct
|
walther@59882
|
30 |
(**)
|
walther@59882
|
31 |
|
walther@59884
|
32 |
(* the pattern for an item of a problems model or a methods guard *)
|
walther@59945
|
33 |
type m_field = string;
|
walther@59952
|
34 |
type descriptor = term;
|
walther@59945
|
35 |
type single =
|
walther@59952
|
36 |
(m_field * (* field Given, Find, Relate *)
|
walther@59952
|
37 |
(descriptor * (* for snd term *)
|
walther@59952
|
38 |
term)) (* id | arbitrary term *);
|
walther@59945
|
39 |
type T = single list;
|
walther@59945
|
40 |
|
walther@59945
|
41 |
fun pat2str (field, (dsc, id)) = pair2str (field, pair2str (UnparseC.term dsc, UnparseC.term id));
|
walther@59945
|
42 |
fun to_string pats = (strs2str o (map pat2str)) pats;
|
walther@59945
|
43 |
fun pat2str' (field, (dsc, id)) = pair2str (field, pair2str (UnparseC.term dsc, UnparseC.term id)) ^ "\n";
|
walther@59945
|
44 |
fun to_string' pats = (strs2str o (map pat2str')) pats;
|
walther@59882
|
45 |
|
walther@59987
|
46 |
(* get the variables out of a pbl_; FIXME.WN.0311: is_copy_named ...obscure!!! *)
|
walther@59987
|
47 |
fun variables pbl_ =
|
walther@59987
|
48 |
let
|
walther@59987
|
49 |
fun var_of_pbl_ (_, (_, t)) = t: term
|
walther@59987
|
50 |
in ((map var_of_pbl_)(* o (filter_out is_copy_named)*)) pbl_ end
|
walther@59987
|
51 |
|
walther@60004
|
52 |
fun get_field descriptor m_patt =
|
walther@60004
|
53 |
(filter ((curry (fn (desc, (_, (desc', _))) => desc = desc')) descriptor) m_patt
|
walther@60004
|
54 |
|> the_single
|
walther@60004
|
55 |
|> (fn (a, _) => SOME a))
|
walther@60004
|
56 |
handle List.Empty => NONE
|
walther@60004
|
57 |
|
walther@59882
|
58 |
(**)end(**)
|