equal
deleted
inserted
replaced
509 first_lower (Long_Name.base_name Tcon) ^ space_implode "_" (map mk_relname Targs) |
509 first_lower (Long_Name.base_name Tcon) ^ space_implode "_" (map mk_relname Targs) |
510 | mk_relname _ = raise Fail "unexpected type" |
510 | mk_relname _ = raise Fail "unexpected type" |
511 |
511 |
512 fun mk_lim_relname T = "lim_" ^ mk_relname T |
512 fun mk_lim_relname T = "lim_" ^ mk_relname T |
513 |
513 |
514 (* This is copied from "pat_completeness.ML" *) |
|
515 fun inst_constrs_of thy (T as Type (name, _)) = |
|
516 map (fn (Cn,CT) => |
|
517 Envir.subst_term_types (Sign.typ_match thy (body_type CT, T) Vartab.empty) (Const (Cn, CT))) |
|
518 (the (Datatype.get_constrs thy name)) |
|
519 | inst_constrs_of thy T = raise TYPE ("inst_constrs_of", [T], []) |
|
520 |
|
521 fun is_recursive_constr T (Const (constr_name, T')) = member (op =) (binder_types T') T |
514 fun is_recursive_constr T (Const (constr_name, T')) = member (op =) (binder_types T') T |
522 |
515 |
523 fun mk_ground_impl ctxt limited_types (T as Type (Tcon, Targs)) (seen, constant_table) = |
516 fun mk_ground_impl ctxt limited_types (T as Type (Tcon, Targs)) (seen, constant_table) = |
524 if member (op =) seen T then ([], (seen, constant_table)) |
517 if member (op =) seen T then ([], (seen, constant_table)) |
525 else |
518 else |
547 ((rel_name, lim_var @ [maybe_AppF (translate_const constant_table'' constr_name, vars)]), |
540 ((rel_name, lim_var @ [maybe_AppF (translate_const constant_table'' constr_name, vars)]), |
548 Conj (map2 mk_prem vars Ts)) |
541 Conj (map2 mk_prem vars Ts)) |
549 in |
542 in |
550 (clause :: flat rec_clauses, (seen', constant_table'')) |
543 (clause :: flat rec_clauses, (seen', constant_table'')) |
551 end |
544 end |
552 val constrs = inst_constrs_of (Proof_Context.theory_of ctxt) T |
545 val constrs = Function_Lib.inst_constrs_of (Proof_Context.theory_of ctxt) T |
553 val constrs' = (constrs ~~ map (is_recursive_constr T) constrs) |
546 val constrs' = (constrs ~~ map (is_recursive_constr T) constrs) |
554 |> (fn cs => filter_out snd cs @ filter snd cs) |
547 |> (fn cs => filter_out snd cs @ filter snd cs) |
555 val (clauses, constant_table') = |
548 val (clauses, constant_table') = |
556 apfst flat (fold_map mk_impl constrs' (T :: seen, constant_table)) |
549 apfst flat (fold_map mk_impl constrs' (T :: seen, constant_table)) |
557 val size_term = funpow size (fn t => AppF ("suc", [t])) (Cons "zero") |
550 val size_term = funpow size (fn t => AppF ("suc", [t])) (Cons "zero") |