676 and translate_case ctxt algbr eqngr permissive some_thm (t_pos, case_pats) (c_ty, ts) = |
676 and translate_case ctxt algbr eqngr permissive some_thm (t_pos, case_pats) (c_ty, ts) = |
677 let |
677 let |
678 val thy = Proof_Context.theory_of ctxt; |
678 val thy = Proof_Context.theory_of ctxt; |
679 val ty = nth (binder_types (snd c_ty)) t_pos; |
679 val ty = nth (binder_types (snd c_ty)) t_pos; |
680 val is_let = null case_pats; |
680 val is_let = null case_pats; |
681 fun mk_constr NONE _ = NONE |
681 fun select_clauses xs = |
682 | mk_constr (SOME c) t = |
682 xs |
683 let |
683 |> nth_drop t_pos |
684 val n = Code.args_number thy c; |
684 |> curry (op ~~) case_pats |
685 in SOME ((c, (take n o binder_types o fastype_of o untag_term) t ---> ty), n) end; |
685 |> map_filter (fn (NONE, _) => NONE | (SOME _, x) => SOME x); |
|
686 fun mk_constr c t = |
|
687 let |
|
688 val n = Code.args_number thy c; |
|
689 in ((c, (take n o binder_types o fastype_of o untag_term) t ---> ty), n) end; |
686 val constrs = |
690 val constrs = |
687 if is_let then [] |
691 if is_let then [] |
688 else map_filter I (map2 mk_constr case_pats (nth_drop t_pos ts)); |
692 else map2 mk_constr (case_pats |> map_filter I) (select_clauses ts); |
689 val split_clauses = |
693 val split_clauses = |
690 if is_let then (fn ts => (nth ts t_pos, nth_drop t_pos ts)) |
694 if is_let then (fn ts => (nth ts t_pos, nth_drop t_pos ts)) |
691 else (fn ts => (nth ts t_pos, ts |> nth_drop t_pos |> curry (op ~~) case_pats |
695 else (fn ts => (nth ts t_pos, select_clauses ts)); |
692 |> map_filter (fn (NONE, _) => NONE | (SOME _, t) => SOME t))); |
|
693 fun disjunctive_varnames ts = |
696 fun disjunctive_varnames ts = |
694 let |
697 let |
695 val vs = (fold o fold_varnames) (insert (op =)) ts []; |
698 val vs = (fold o fold_varnames) (insert (op =)) ts []; |
696 in fn pat => null (inter (op =) vs (fold_varnames (insert (op =)) pat [])) end; |
699 in fn pat => null (inter (op =) vs (fold_varnames (insert (op =)) pat [])) end; |
697 fun purge_unused_vars_in t = |
700 fun purge_unused_vars_in t = |