src/Pure/Isar/overloading.ML
changeset 25861 494d9301cc75
parent 25606 23d34f86b88f
child 26238 c30bb8182da2
equal deleted inserted replaced
25860:844ab7ace3db 25861:494d9301cc75
     5 Overloaded definitions without any discipline.
     5 Overloaded definitions without any discipline.
     6 *)
     6 *)
     7 
     7 
     8 signature OVERLOADING =
     8 signature OVERLOADING =
     9 sig
     9 sig
    10   val init: ((string * typ) * (string * bool)) list -> theory -> local_theory
    10   val init: (string * (string * typ) * bool) list -> theory -> local_theory
    11   val conclude: local_theory -> local_theory
    11   val conclude: local_theory -> local_theory
    12   val declare: string * typ -> theory -> term * theory
    12   val declare: string * typ -> theory -> term * theory
    13   val confirm: string -> local_theory -> local_theory
    13   val confirm: string -> local_theory -> local_theory
    14   val define: bool -> string -> string * term -> theory -> thm * theory
    14   val define: bool -> string -> string * term -> theory -> thm * theory
    15   val operation: Proof.context -> string -> (string * bool) option
    15   val operation: Proof.context -> string -> (string * bool) option
    73 (* target *)
    73 (* target *)
    74 
    74 
    75 fun init overloading thy =
    75 fun init overloading thy =
    76   let
    76   let
    77     val _ = if null overloading then error "At least one parameter must be given" else ();
    77     val _ = if null overloading then error "At least one parameter must be given" else ();
    78     fun declare ((_, ty), (v, _ )) = Variable.declare_term (Free (v, ty));
       
    79   in
    78   in
    80     thy
    79     thy
    81     |> ProofContext.init
    80     |> ProofContext.init
    82     |> OverloadingData.put overloading
    81     |> OverloadingData.put (map (fn (v, c_ty, checked) => (c_ty, (v, checked))) overloading)
    83     |> fold declare overloading
    82     |> fold (fn (v, (_, ty), _) => Variable.declare_term (Free (v, ty))) overloading
    84     |> Context.proof_map (
    83     |> Context.proof_map (
    85         Syntax.add_term_check 0 "overloading" term_check
    84         Syntax.add_term_check 0 "overloading" term_check
    86         #> Syntax.add_term_uncheck 0 "overloading" term_uncheck)
    85         #> Syntax.add_term_uncheck 0 "overloading" term_uncheck)
    87   end;
    86   end;
    88 
    87 
    99 fun pretty lthy =
    98 fun pretty lthy =
   100   let
    99   let
   101     val thy = ProofContext.theory_of lthy;
   100     val thy = ProofContext.theory_of lthy;
   102     val overloading = get_overloading lthy;
   101     val overloading = get_overloading lthy;
   103     fun pr_operation ((c, ty), (v, _)) =
   102     fun pr_operation ((c, ty), (v, _)) =
   104       (Pretty.block o Pretty.breaks) [Pretty.str (Sign.extern_const thy c), Pretty.str "::",
   103       (Pretty.block o Pretty.breaks) [Pretty.str v, Pretty.str "==",
   105         Sign.pretty_typ thy ty, Pretty.str "as", Pretty.str v];
   104         Pretty.str (Sign.extern_const thy c), Pretty.str "::", Sign.pretty_typ thy ty];
   106   in
   105   in
   107     (Pretty.block o Pretty.fbreaks)
   106     (Pretty.block o Pretty.fbreaks)
   108       (Pretty.str "overloading" :: map pr_operation overloading)
   107       (Pretty.str "overloading" :: map pr_operation overloading)
   109   end;
   108   end;
   110 
   109