src/Pure/Isar/proof_context.ML
changeset 22701 4346f230283d
parent 22678 23963361278c
child 22712 8f2ba236918b
equal deleted inserted replaced
22700:5a699d278cfa 22701:4346f230283d
    65   val read_term_abbrev: Proof.context -> string -> term
    65   val read_term_abbrev: Proof.context -> string -> term
    66   val cert_term: Proof.context -> term -> term
    66   val cert_term: Proof.context -> term -> term
    67   val cert_prop: Proof.context -> term -> term
    67   val cert_prop: Proof.context -> term -> term
    68   val cert_term_pats: typ -> Proof.context -> term list -> term list
    68   val cert_term_pats: typ -> Proof.context -> term list -> term list
    69   val cert_prop_pats: Proof.context -> term list -> term list
    69   val cert_prop_pats: Proof.context -> term list -> term list
       
    70   val infer_types: Proof.context -> (term * typ) list -> (term * typ) list
       
    71   val infer_types_pat: Proof.context -> (term * typ) list -> (term * typ) list
    70   val infer_type: Proof.context -> string -> typ
    72   val infer_type: Proof.context -> string -> typ
    71   val inferred_param: string -> Proof.context -> (string * typ) * Proof.context
    73   val inferred_param: string -> Proof.context -> (string * typ) * Proof.context
    72   val inferred_fixes: Proof.context -> (string * typ) list * Proof.context
    74   val inferred_fixes: Proof.context -> (string * typ) list * Proof.context
    73   val read_tyname: Proof.context -> string -> typ
    75   val read_tyname: Proof.context -> string -> typ
    74   val read_const: Proof.context -> string -> term
    76   val read_const: Proof.context -> string -> term
   433 
   435 
   434 
   436 
   435 (* read wrt. theory *)     (*exception ERROR*)
   437 (* read wrt. theory *)     (*exception ERROR*)
   436 
   438 
   437 fun read_def_termTs freeze pp syn ctxt (types, sorts, used) sTs =
   439 fun read_def_termTs freeze pp syn ctxt (types, sorts, used) sTs =
   438   Sign.read_def_terms' pp (Sign.is_logtype (theory_of ctxt)) syn (consts_of ctxt)
   440   Sign.read_def_terms' pp (Sign.is_logtype (theory_of ctxt)) syn (consts_of ctxt) (K NONE)
   439     ctxt (types, sorts) used freeze sTs;
   441     ctxt (types, sorts) used freeze sTs;
   440 
   442 
   441 fun read_def_termT freeze pp syn ctxt defaults sT =
   443 fun read_def_termT freeze pp syn ctxt defaults sT =
   442   apfst hd (read_def_termTs freeze pp syn ctxt defaults [sT]);
   444   apfst hd (read_def_termTs freeze pp syn ctxt defaults [sT]);
   443 
   445 
   548 val cert_prop_pats = map o gen_cert true true false;
   550 val cert_prop_pats = map o gen_cert true true false;
   549 
   551 
   550 end;
   552 end;
   551 
   553 
   552 
   554 
       
   555 (* type inference *)
       
   556 
       
   557 local
       
   558 
       
   559 fun gen_infer_types pattern ctxt =
       
   560   TypeInfer.infer_types (pp ctxt) (tsig_of ctxt) (try (Consts.the_constraint (consts_of ctxt)))
       
   561     (Variable.def_type ctxt pattern) (Variable.names_of ctxt) (not pattern) #> #1;
       
   562 
       
   563 in
       
   564 
       
   565 val infer_types = gen_infer_types false;
       
   566 val infer_types_pat = gen_infer_types true;
       
   567 
       
   568 end;
       
   569 
       
   570 
   553 (* inferred types of parameters *)
   571 (* inferred types of parameters *)
   554 
   572 
   555 fun infer_type ctxt x =
   573 fun infer_type ctxt x =
   556   (case try (fn () =>
   574   #2 (singleton (infer_types ctxt) (Free (x, dummyT), TypeInfer.logicT));
   557       Sign.infer_types (pp ctxt) (theory_of ctxt) (consts_of ctxt) (Variable.def_type ctxt false)
       
   558         (Variable.def_sort ctxt) (Variable.names_of ctxt) true
       
   559         ([Free (x, dummyT)], TypeInfer.logicT)) () of
       
   560     SOME (Free (_, T), _) => T
       
   561   | _ => error ("Failed to infer type of fixed variable " ^ quote x));
       
   562 
   575 
   563 fun inferred_param x ctxt =
   576 fun inferred_param x ctxt =
   564   let val T = infer_type ctxt x
   577   let val T = infer_type ctxt x
   565   in ((x, T), ctxt |> Variable.declare_term (Free (x, T))) end;
   578   in ((x, T), ctxt |> Variable.declare_term (Free (x, T))) end;
   566 
   579 
   827 (** parameters **)
   840 (** parameters **)
   828 
   841 
   829 (* variables *)
   842 (* variables *)
   830 
   843 
   831 fun declare_var (x, opt_T, mx) ctxt =
   844 fun declare_var (x, opt_T, mx) ctxt =
   832   let val T = (case opt_T of SOME T => T | NONE => TypeInfer.mixfixT mx)
   845   let val T = (case opt_T of SOME T => T | NONE => Syntax.mixfixT mx)
   833   in ((x, T, mx), ctxt |> Variable.declare_constraints (Free (x, T))) end;
   846   in ((x, T, mx), ctxt |> Variable.declare_constraints (Free (x, T))) end;
   834 
   847 
   835 local
   848 local
   836 
   849 
   837 fun prep_vars prep_typ internal legacy =
   850 fun prep_vars prep_typ internal legacy =