src/HOL/Tools/Lifting/lifting_def.ML
changeset 47566 c201a1fe0a81
parent 47545 a2850a16e30f
child 47607 5c17ef8feac7
equal deleted inserted replaced
47565:762eb0dacaa6 47566:c201a1fe0a81
   125     val code_cert = [repped_eq, abs_rep_eq] MRSL @{thm trans}
   125     val code_cert = [repped_eq, abs_rep_eq] MRSL @{thm trans}
   126   in
   126   in
   127     simplify_code_eq ctxt code_cert
   127     simplify_code_eq ctxt code_cert
   128   end
   128   end
   129 
   129 
       
   130 fun is_abstype ctxt typ =
       
   131   let
       
   132     val thy = Proof_Context.theory_of ctxt
       
   133     val type_name = (fst o dest_Type) typ
       
   134   in
       
   135     (snd oo Code.get_type) thy type_name
       
   136   end
       
   137   
       
   138 
   130 fun define_code_cert code_eqn_thm_name def_thm rsp_thm (rty, qty) lthy = 
   139 fun define_code_cert code_eqn_thm_name def_thm rsp_thm (rty, qty) lthy = 
   131   let
   140   let
   132     val quot_thm = Lifting_Term.prove_quot_thm lthy (get_body_types (rty, qty))
   141     val (rty_body, qty_body) = get_body_types (rty, qty)
       
   142     val quot_thm = Lifting_Term.prove_quot_thm lthy (rty_body, qty_body)
   133   in
   143   in
   134     if can_generate_code_cert quot_thm then
   144     if can_generate_code_cert quot_thm then
   135       let
   145       let
   136         val code_cert = generate_code_cert lthy def_thm rsp_thm (rty, qty)
   146         val code_cert = generate_code_cert lthy def_thm rsp_thm (rty, qty)
   137         val add_abs_eqn_attribute = 
   147         val add_abs_eqn_attribute = 
   138           Thm.declaration_attribute (fn thm => Context.mapping (Code.add_abs_eqn thm) I)
   148           Thm.declaration_attribute (fn thm => Context.mapping (Code.add_abs_eqn thm) I)
   139         val add_abs_eqn_attrib = Attrib.internal (K add_abs_eqn_attribute);
   149         val add_abs_eqn_attrib = Attrib.internal (K add_abs_eqn_attribute);
   140       in
   150         val lthy' = 
   141         lthy
   151           (snd oo Local_Theory.note) ((code_eqn_thm_name, []), [code_cert]) lthy
   142           |> (snd oo Local_Theory.note) ((code_eqn_thm_name, [add_abs_eqn_attrib]), [code_cert])
   152       in
       
   153         if is_abstype lthy qty_body then
       
   154           (snd oo Local_Theory.note) ((Binding.empty, [add_abs_eqn_attrib]), [code_cert]) lthy'
       
   155         else
       
   156           lthy'
   143       end
   157       end
   144     else
   158     else
   145       lthy
   159       lthy
   146   end
   160   end
   147 
   161