src/HOL/Tools/Sledgehammer/sledgehammer_annotate.ML
changeset 52369 0b395800fdf0
parent 52366 ff89424b5094
child 52452 2207825d67f3
equal deleted inserted replaced
52368:13ca6876f748 52369:0b395800fdf0
     1 (*  Title:      HOL/Tools/Sledgehammer/sledgehammer_annotate.ML
     1 (*  Title:      HOL/Tools/Sledgehammer/sledgehammer_annotate.ML
     2     Author:     Jasmin Blanchette, TU Muenchen
     2     Author:     Jasmin Blanchette, TU Muenchen
     3     Author:     Steffen Juilf Smolka, TU Muenchen
     3     Author:     Steffen Juilf Smolka, TU Muenchen
     4 
     4 
     5 Supplement term with explicit type constraints that show up as
     5 Supplements term with a locally minmal, complete set of type constraints.
     6 type annotations when printing the term.
     6 Complete: The constraints suffice to infer the term's types.
       
     7 Minimal: Reducing the set of constraints further will make it incomplete.
       
     8 
       
     9 When configuring the pretty printer appropriately, the constraints will show up
       
    10 as type annotations when printing the term. This allows the term to be reparsed
       
    11 without a change of types.
       
    12 
       
    13 NOTE: Terms should be unchecked before calling annotate_types to avoid awkward
       
    14 syntax.
     7 *)
    15 *)
     8 
    16 
     9 signature SLEDGEHAMMER_ANNOTATE =
    17 signature SLEDGEHAMMER_ANNOTATE =
    10 sig
    18 sig
    11   val annotate_types : Proof.context -> term -> term
    19   val annotate_types : Proof.context -> term -> term
    40   type key = indexname list
    48   type key = indexname list
    41   val ord = list_ord Term_Ord.fast_indexname_ord)
    49   val ord = list_ord Term_Ord.fast_indexname_ord)
    42 
    50 
    43 (* (1) Generalize types *)
    51 (* (1) Generalize types *)
    44 fun generalize_types ctxt t =
    52 fun generalize_types ctxt t =
    45   t |> map_types (fn _ => dummyT)
    53   let
    46     |> Syntax.check_term
    54     val erase_types = map_types (fn _ => dummyT)
    47          (Proof_Context.set_mode Proof_Context.mode_pattern ctxt)
    55     (* use schematic type variables *)
       
    56     val ctxt = ctxt |> Proof_Context.set_mode Proof_Context.mode_pattern
       
    57     val infer_types = singleton (Type_Infer_Context.infer_types ctxt)
       
    58   in
       
    59      t |> erase_types |> infer_types
       
    60   end
    48 
    61 
    49 (* (2) Typing-spot table *)
    62 (* (2) Typing-spot table *)
    50 local
    63 local
    51 fun key_of_atype (TVar (z, _)) =
    64 fun key_of_atype (TVar (z, _)) =
    52     Ord_List.insert Term_Ord.fast_indexname_ord z
    65     Ord_List.insert Term_Ord.fast_indexname_ord z