5 Type classes and sorts. |
5 Type classes and sorts. |
6 *) |
6 *) |
7 |
7 |
8 signature SORTS = |
8 signature SORTS = |
9 sig |
9 sig |
10 val str_of_sort: sort -> string |
|
11 val str_of_arity: string * sort list * sort -> string |
|
12 val eq_sort: sort * sort -> bool |
10 val eq_sort: sort * sort -> bool |
13 val mem_sort: sort * sort list -> bool |
11 val mem_sort: sort * sort list -> bool |
14 val subset_sort: sort list * sort list -> bool |
12 val subset_sort: sort list * sort list -> bool |
15 val eq_set_sort: sort list * sort list -> bool |
13 val eq_set_sort: sort list * sort list -> bool |
16 val ins_sort: sort * sort list -> sort list |
14 val ins_sort: sort * sort list -> sort list |
29 val inter_sort: classes -> sort * sort -> sort |
27 val inter_sort: classes -> sort * sort -> sort |
30 val norm_sort: classes -> sort -> sort |
28 val norm_sort: classes -> sort -> sort |
31 val of_sort: classes * arities -> typ * sort -> bool |
29 val of_sort: classes * arities -> typ * sort -> bool |
32 exception DOMAIN of string * class |
30 exception DOMAIN of string * class |
33 val mg_domain: classes * arities -> string -> sort -> sort list (*exception DOMAIN*) |
31 val mg_domain: classes * arities -> string -> sort -> sort list (*exception DOMAIN*) |
34 val witness_sorts: classes * arities -> string list |
32 val witness_sorts: classes * arities -> string list -> |
35 -> sort list -> sort list -> (typ * sort) list |
33 sort list -> sort list -> (typ * sort) list |
36 end; |
34 end; |
37 |
35 |
38 structure Sorts: SORTS = |
36 structure Sorts: SORTS = |
39 struct |
37 struct |
40 |
38 |
49 represented by lists of classes. Normal forms of sorts are sorted |
47 represented by lists of classes. Normal forms of sorts are sorted |
50 lists of minimal classes (wrt. current class inclusion). |
48 lists of minimal classes (wrt. current class inclusion). |
51 |
49 |
52 (types already defined in Pure/term.ML) |
50 (types already defined in Pure/term.ML) |
53 *) |
51 *) |
54 |
|
55 |
|
56 (* simple printing -- lacks pretty printing, translations etc. *) |
|
57 |
|
58 fun str_of_sort [c] = c |
|
59 | str_of_sort cs = Library.enclose "{" "}" (Library.commas cs); |
|
60 |
|
61 fun str_of_arity (t, [], S) = t ^ " :: " ^ str_of_sort S |
|
62 | str_of_arity (t, Ss, S) = t ^ " :: " ^ |
|
63 Library.enclose "(" ")" (Library.commas (map str_of_sort Ss)) ^ " " ^ str_of_sort S; |
|
64 |
52 |
65 |
53 |
66 (* equality, membership and insertion of sorts *) |
54 (* equality, membership and insertion of sorts *) |
67 |
55 |
68 fun eq_sort ([]: sort, []) = true |
56 fun eq_sort ([]: sort, []) = true |
188 |
176 |
189 |
177 |
190 |
178 |
191 (** witness_sorts **) |
179 (** witness_sorts **) |
192 |
180 |
193 fun witness_sorts_aux (classes, arities) log_types hyps sorts = |
181 local |
|
182 |
|
183 fun witness_aux (classes, arities) log_types hyps sorts = |
194 let |
184 let |
195 val top_witn = (propT, []); |
185 val top_witn = (propT, []); |
196 fun le S1 S2 = sort_le classes (S1, S2); |
186 fun le S1 S2 = sort_le classes (S1, S2); |
197 fun get_solved S2 (T, S1) = if le S1 S2 then Some (T, S2) else None; |
187 fun get_solved S2 (T, S1) = if le S1 S2 then Some (T, S2) else None; |
198 fun get_hyp S2 S1 = if le S1 S2 then Some (TFree ("'hyp", S1), S2) else None; |
188 fun get_hyp S2 S1 = if le S1 S2 then Some (TFree ("'hyp", S1), S2) else None; |
227 end |
217 end |
228 | None => witn_types path ts (solved_failed, S)); |
218 | None => witn_types path ts (solved_failed, S)); |
229 |
219 |
230 in witn_sorts [] (([], []), sorts) end; |
220 in witn_sorts [] (([], []), sorts) end; |
231 |
221 |
|
222 fun str_of_sort [c] = c |
|
223 | str_of_sort cs = enclose "{" "}" (commas cs); |
|
224 |
|
225 in |
232 |
226 |
233 fun witness_sorts (classes, arities) log_types hyps sorts = |
227 fun witness_sorts (classes, arities) log_types hyps sorts = |
234 let |
228 let |
235 (*double check result of witness search*) |
229 (*double check result of witness search*) |
236 fun check_result None = None |
230 fun check_result None = None |
237 | check_result (Some (T, S)) = |
231 | check_result (Some (T, S)) = |
238 if of_sort (classes, arities) (T, S) then Some (T, S) |
232 if of_sort (classes, arities) (T, S) then Some (T, S) |
239 else sys_error ("Sorts.witness_sorts: bad witness for sort " ^ str_of_sort S); |
233 else sys_error ("Sorts.witness_sorts: bad witness for sort " ^ str_of_sort S); |
240 in mapfilter check_result (#2 (witness_sorts_aux (classes, arities) log_types hyps sorts)) end; |
234 in mapfilter check_result (#2 (witness_aux (classes, arities) log_types hyps sorts)) end; |
241 |
|
242 |
235 |
243 end; |
236 end; |
|
237 |
|
238 end; |