114 lthy) |
114 lthy) |
115 (transfers ~~ fun_names ~~ funs ~~ fun_defs); |
115 (transfers ~~ fun_names ~~ funs ~~ fun_defs); |
116 |
116 |
117 val lfp_rec_sugar_transfer_interpretation = fp_rec_sugar_transfer_interpretation |
117 val lfp_rec_sugar_transfer_interpretation = fp_rec_sugar_transfer_interpretation |
118 (fn _ => fn _ => fn f => fn def => fn lthy => |
118 (fn _ => fn _ => fn f => fn def => fn lthy => |
119 let val (goal, names_lthy) = mk_goal lthy f in |
119 let |
120 Goal.prove lthy [] [] goal (fn {context = ctxt, prems = _} => |
120 val (goal, _) = mk_goal lthy f; |
121 mk_lfp_rec_sugar_transfer_tac ctxt def) |
121 val vars = Variable.add_free_names lthy goal []; |
122 |> singleton (Proof_Context.export names_lthy lthy) |
122 in |
123 |> Thm.close_derivation |
123 Goal.prove lthy vars [] goal (fn {context = ctxt, prems = _} => |
124 end); |
124 mk_lfp_rec_sugar_transfer_tac ctxt def) |
|
125 |> Thm.close_derivation |
|
126 end); |
125 |
127 |
126 val gfp_rec_sugar_transfer_interpretation = fp_rec_sugar_transfer_interpretation |
128 val gfp_rec_sugar_transfer_interpretation = fp_rec_sugar_transfer_interpretation |
127 (fn kk => fn bnfs => fn f => fn def => fn lthy => |
129 (fn kk => fn bnfs => fn f => fn def => fn lthy => |
128 let |
130 let |
129 val fp_sugars = map (the o fp_sugar_of_bnf lthy) bnfs; |
131 val fp_sugars = map (the o fp_sugar_of_bnf lthy) bnfs; |
130 val (goal, names_lthy) = mk_goal lthy f; |
132 val (goal, _) = mk_goal lthy f; |
|
133 val vars = Variable.add_free_names lthy goal []; |
131 val (disc_eq_cases, case_thms, case_distribs, case_congs) = |
134 val (disc_eq_cases, case_thms, case_distribs, case_congs) = |
132 bnf_depth_first_traverse lthy (fn bnf => |
135 bnf_depth_first_traverse lthy (fn bnf => |
133 (case fp_sugar_of_bnf lthy bnf of |
136 (case fp_sugar_of_bnf lthy bnf of |
134 NONE => I |
137 NONE => I |
135 | SOME {fp_ctr_sugar = {ctr_sugar = {disc_eq_cases, case_thms, case_distribs, |
138 | SOME {fp_ctr_sugar = {ctr_sugar = {disc_eq_cases, case_thms, case_distribs, |
139 union Thm.eq_thm case_thms case_thms0, |
142 union Thm.eq_thm case_thms case_thms0, |
140 union Thm.eq_thm case_distribs case_distribs0, |
143 union Thm.eq_thm case_distribs case_distribs0, |
141 insert Thm.eq_thm case_cong case_congs0)))) |
144 insert Thm.eq_thm case_cong case_congs0)))) |
142 (fastype_of f) ([], [], [], []); |
145 (fastype_of f) ([], [], [], []); |
143 in |
146 in |
144 Goal.prove lthy [] [] goal (fn {context = ctxt, prems = _} => |
147 Goal.prove lthy vars [] goal (fn {context = ctxt, prems = _} => |
145 mk_gfp_rec_sugar_transfer_tac ctxt def |
148 mk_gfp_rec_sugar_transfer_tac ctxt def |
146 (#co_rec_def (#fp_co_induct_sugar (nth fp_sugars kk))) |
149 (#co_rec_def (#fp_co_induct_sugar (nth fp_sugars kk))) |
147 (map (#type_definition o #absT_info) fp_sugars) |
150 (map (#type_definition o #absT_info) fp_sugars) |
148 (maps (#xtor_co_rec_transfers o #fp_res) fp_sugars) |
151 (maps (#xtor_co_rec_transfers o #fp_res) fp_sugars) |
149 (map (rel_def_of_bnf o #pre_bnf) fp_sugars) |
152 (map (rel_def_of_bnf o #pre_bnf) fp_sugars) |
150 disc_eq_cases case_thms case_distribs case_congs) |
153 disc_eq_cases case_thms case_distribs case_congs) |
151 |> singleton (Proof_Context.export names_lthy lthy) |
|
152 |> Thm.close_derivation |
154 |> Thm.close_derivation |
153 end); |
155 end); |
154 |
156 |
155 val _ = Theory.setup (lfp_rec_sugar_interpretation Transfer_BNF.transfer_plugin |
157 val _ = Theory.setup (lfp_rec_sugar_interpretation Transfer_BNF.transfer_plugin |
156 lfp_rec_sugar_transfer_interpretation); |
158 lfp_rec_sugar_transfer_interpretation); |