src/HOL/Tools/recfun_codegen.ML
changeset 19788 be3a84d22a58
parent 19600 2d969d9a233b
child 20597 65fe827aa595
equal deleted inserted replaced
19787:b949911ecff5 19788:be3a84d22a58
     7 
     7 
     8 signature RECFUN_CODEGEN =
     8 signature RECFUN_CODEGEN =
     9 sig
     9 sig
    10   val add: string option -> attribute
    10   val add: string option -> attribute
    11   val del: attribute
    11   val del: attribute
    12   val get_thm_equations: theory -> string * typ -> (thm list * typ) option
       
    13   val setup: theory -> theory
    12   val setup: theory -> theory
    14 end;
    13 end;
    15 
    14 
    16 structure RecfunCodegen : RECFUN_CODEGEN =
    15 structure RecfunCodegen : RECFUN_CODEGEN =
    17 struct
    16 struct
    83                NONE => (case get_defn thy defs s T of
    82                NONE => (case get_defn thy defs s T of
    84                    NONE => thyname_of_const s thy
    83                    NONE => thyname_of_const s thy
    85                  | SOME ((_, (thyname, _)), _) => thyname)
    84                  | SOME ((_, (thyname, _)), _) => thyname)
    86              | SOME thyname => thyname)
    85              | SOME thyname => thyname)
    87        end);
    86        end);
    88 
       
    89 fun get_thm_equations thy (c, ty) =
       
    90   Symtab.lookup (CodegenData.get thy) c
       
    91   |> Option.map (fn thms => 
       
    92        List.filter (fn (thm, _) => is_instance thy ty ((snd o const_of o prop_of) thm)) thms
       
    93        |> del_redundant thy [])
       
    94   |> Option.mapPartial (fn thms => if null thms then NONE else SOME thms)
       
    95   |> Option.map (fn thms =>
       
    96        (preprocess thy (map fst thms),
       
    97           (snd o const_of o prop_of o fst o hd) thms))
       
    98   |> (Option.map o apfst o map) (fn thm => thm RS HOL.eq_reflection);
       
    99 
    87 
   100 fun mk_suffix thy defs (s, T) = (case get_defn thy defs s T of
    88 fun mk_suffix thy defs (s, T) = (case get_defn thy defs s T of
   101   SOME (_, SOME i) => " def" ^ string_of_int i | _ => "");
    89   SOME (_, SOME i) => " def" ^ string_of_int i | _ => "");
   102 
    90 
   103 exception EQN of string * typ * string;
    91 exception EQN of string * typ * string;