208 end; |
208 end; |
209 |
209 |
210 |
210 |
211 (* applying instantiations *) |
211 (* applying instantiations *) |
212 |
212 |
213 fun build_algebra thy arities = |
|
214 let |
|
215 val pp = Syntax.pp_global thy; |
|
216 val thy_algebra = Sign.classes_of thy; |
|
217 val is_proper = can (AxClass.get_info thy); |
|
218 val classrels = Sorts.classrels_of thy_algebra |
|
219 |> filter (is_proper o fst) |
|
220 |> (map o apsnd) (filter is_proper); |
|
221 val instances = Sorts.instances_of thy_algebra |
|
222 |> filter (is_proper o snd) |
|
223 |> map swap (*FIXME*) |
|
224 fun add_class (class, superclasses) algebra = |
|
225 Sorts.add_class pp (class, Sorts.minimize_sort algebra superclasses) algebra; |
|
226 fun add_arity (class, tyco) algebra = case AList.lookup (op =) arities (class, tyco) |
|
227 of SOME sorts => Sorts.add_arities pp |
|
228 (tyco, [(class, map (Sorts.minimize_sort algebra) sorts)]) algebra |
|
229 | NONE => algebra; |
|
230 in |
|
231 Sorts.empty_algebra |
|
232 |> fold add_class classrels |
|
233 |> fold add_arity instances |
|
234 end; |
|
235 |
|
236 fun dicts_of thy (proj_sort, algebra) (T, sort) = |
213 fun dicts_of thy (proj_sort, algebra) (T, sort) = |
237 let |
214 let |
238 fun class_relation (x, _) _ = x; |
215 fun class_relation (x, _) _ = x; |
239 fun type_constructor tyco xs class = |
216 fun type_constructor tyco xs class = |
240 inst_params thy tyco (Sorts.complete_sort algebra [class]) |
217 inst_params thy tyco (Sorts.complete_sort algebra [class]) |
271 val cs_rhss' = (map o apsnd o map) (styp_of NONE) cs_rhss; |
248 val cs_rhss' = (map o apsnd o map) (styp_of NONE) cs_rhss; |
272 val (vardeps, (eqntab, insts)) = empty_vardeps_data |
249 val (vardeps, (eqntab, insts)) = empty_vardeps_data |
273 |> fold (assert_fun thy arities eqngr) cs |
250 |> fold (assert_fun thy arities eqngr) cs |
274 |> fold (assert_rhs thy arities eqngr) cs_rhss'; |
251 |> fold (assert_rhs thy arities eqngr) cs_rhss'; |
275 val arities' = fold (add_arity thy vardeps) insts arities; |
252 val arities' = fold (add_arity thy vardeps) insts arities; |
276 val algebra = build_algebra thy arities'; |
253 val pp = Syntax.pp_global thy; |
277 val proj_sort = complete_proper_sort thy #> Sorts.minimize_sort algebra; |
254 val is_proper_class = can (AxClass.get_info thy); |
|
255 val (proj_sort, algebra) = Sorts.subalgebra pp is_proper_class |
|
256 (AList.lookup (op =) arities') (Sign.classes_of thy); |
278 val (rhss, eqngr') = Symtab.fold |
257 val (rhss, eqngr') = Symtab.fold |
279 (add_eqs thy (proj_sort, algebra) vardeps) eqntab ([], eqngr); |
258 (add_eqs thy (proj_sort, algebra) vardeps) eqntab ([], eqngr); |
280 fun deps_of (c, rhs) = c :: |
259 fun deps_of (c, rhs) = c :: |
281 maps (dicts_of thy (proj_sort, algebra)) |
260 maps (dicts_of thy (proj_sort, algebra)) |
282 (rhs ~~ (map snd o fst o fst o Graph.get_node eqngr') c); |
261 (rhs ~~ (map snd o fst o fst o Graph.get_node eqngr') c); |