src/HOL/Tools/Sledgehammer/sledgehammer_util.ML
changeset 36555 8ff45c2076da
parent 36496 8b2dc9b4bf4c
child 36960 01594f816e3a
equal deleted inserted replaced
36554:2673979cb54d 36555:8ff45c2076da
    16   val parse_bool_option : bool -> string -> string -> bool option
    16   val parse_bool_option : bool -> string -> string -> bool option
    17   val parse_time_option : string -> string -> Time.time option
    17   val parse_time_option : string -> string -> Time.time option
    18   val nat_subscript : int -> string
    18   val nat_subscript : int -> string
    19   val unyxml : string -> string
    19   val unyxml : string -> string
    20   val maybe_quote : string -> string
    20   val maybe_quote : string -> string
       
    21   val monomorphic_term : Type.tyenv -> term -> term
       
    22   val specialize_type : theory -> (string * typ) -> term -> term
    21 end;
    23 end;
    22  
    24  
    23 structure Sledgehammer_Util : SLEDGEHAMMER_UTIL =
    25 structure Sledgehammer_Util : SLEDGEHAMMER_UTIL =
    24 struct
    26 struct
    25 
    27 
   101     y |> ((not (is_long_identifier (perhaps (try (unprefix "'")) s)) andalso
   103     y |> ((not (is_long_identifier (perhaps (try (unprefix "'")) s)) andalso
   102            not (is_long_identifier (perhaps (try (unprefix "?")) s))) orelse
   104            not (is_long_identifier (perhaps (try (unprefix "?")) s))) orelse
   103            OuterKeyword.is_keyword s) ? quote
   105            OuterKeyword.is_keyword s) ? quote
   104   end
   106   end
   105 
   107 
       
   108 fun monomorphic_term subst t =
       
   109   map_types (map_type_tvar (fn v =>
       
   110       case Type.lookup subst v of
       
   111         SOME typ => typ
       
   112       | NONE => raise TERM ("monomorphic_term: uninstanitated schematic type \
       
   113                             \variable", [t]))) t
       
   114 
       
   115 fun specialize_type thy (s, T) t =
       
   116   let
       
   117     fun subst_for (Const (s', T')) =
       
   118       if s = s' then
       
   119         SOME (Sign.typ_match thy (T', T) Vartab.empty)
       
   120         handle Type.TYPE_MATCH => NONE
       
   121       else
       
   122         NONE
       
   123     | subst_for (t1 $ t2) =
       
   124       (case subst_for t1 of SOME x => SOME x | NONE => subst_for t2)
       
   125     | subst_for (Abs (_, _, t')) = subst_for t'
       
   126     | subst_for _ = NONE
       
   127   in
       
   128     case subst_for t of
       
   129       SOME subst => monomorphic_term subst t
       
   130     | NONE => raise Type.TYPE_MATCH
       
   131   end
       
   132 
       
   133 
   106 end;
   134 end;