src/Pure/Isar/locale.ML
changeset 19293 a67b9916c58e
parent 19282 89949d8652c3
child 19296 ad96f1095dca
equal deleted inserted replaced
19292:a5b56c1be618 19293:a67b9916c58e
    70   val print_global_registrations: bool -> string -> theory -> unit
    70   val print_global_registrations: bool -> string -> theory -> unit
    71   val print_local_registrations': bool -> string -> Proof.context -> unit
    71   val print_local_registrations': bool -> string -> Proof.context -> unit
    72   val print_local_registrations: bool -> string -> Proof.context -> unit
    72   val print_local_registrations: bool -> string -> Proof.context -> unit
    73 
    73 
    74   val add_locale: bool -> bstring -> expr -> Element.context list -> theory
    74   val add_locale: bool -> bstring -> expr -> Element.context list -> theory
    75     -> string * Proof.context (*body context!*) * theory
    75     -> (string * Proof.context (*body context!*)) * theory
    76   val add_locale_i: bool -> bstring -> expr -> Element.context_i list -> theory
    76   val add_locale_i: bool -> bstring -> expr -> Element.context_i list -> theory
    77     -> string * Proof.context (*body context!*) * theory
    77     -> (string * Proof.context (*body context!*)) * theory
    78 
    78 
    79   (* Storing results *)
    79   (* Storing results *)
    80   val note_thmss: string -> xstring ->
    80   val note_thmss: string -> xstring ->
    81     ((string * Attrib.src list) * (thmref * Attrib.src list) list) list ->
    81     ((string * Attrib.src list) * (thmref * Attrib.src list) list) list ->
    82     theory -> ((string * thm list) list * (string * thm list) list) * (Proof.context * theory)
    82     theory -> ((string * thm list) list * (string * thm list) list) * (Proof.context * theory)
   927 (* expressions *)
   927 (* expressions *)
   928 
   928 
   929 fun intern_expr thy (Locale xname) = Locale (intern thy xname)
   929 fun intern_expr thy (Locale xname) = Locale (intern thy xname)
   930   | intern_expr thy (Merge exprs) = Merge (map (intern_expr thy) exprs)
   930   | intern_expr thy (Merge exprs) = Merge (map (intern_expr thy) exprs)
   931   | intern_expr thy (Rename (expr, xs)) = Rename (intern_expr thy expr, xs);
   931   | intern_expr thy (Rename (expr, xs)) = Rename (intern_expr thy expr, xs);
       
   932 
       
   933 
       
   934 (* experimental code for type inference *)
       
   935 
       
   936 local
       
   937 
       
   938 fun declare_int_elem (ctxt, Fixes fixes) =
       
   939       (ctxt |> ProofContext.add_fixes_i (map (fn (x, T, mx) =>
       
   940         (x, Option.map (Term.map_type_tfree (TypeInfer.param 0)) T, mx)) fixes) |> snd, [])
       
   941   | declare_int_elem (ctxt, _) = (ctxt, []);
       
   942 
       
   943 fun declare_ext_elem prep_vars (ctxt, Fixes fixes) =
       
   944       let val (vars, _) = prep_vars fixes ctxt
       
   945       in (ctxt |> ProofContext.add_fixes_i vars |> snd, []) end
       
   946   | declare_ext_elem prep_vars (ctxt, Constrains csts) =
       
   947       let val (_, ctxt') = prep_vars (map (fn (x, T) => (x, SOME T, NoSyn)) csts) ctxt
       
   948       in (ctxt', []) end
       
   949   | declare_ext_elem _ (ctxt, Assumes asms) = (ctxt, map #2 asms)
       
   950   | declare_ext_elem _ (ctxt, Defines defs) = (ctxt, map (fn (_, (t, ps)) => [(t, (ps, []))]) defs)
       
   951   | declare_ext_elem _ (ctxt, Notes facts) = (ctxt, []);
       
   952 
       
   953 fun declare_elems prep_vars (ctxt, (((name, ps), Assumed _), elems)) =
       
   954     let val (ctxt', propps) =
       
   955       (case elems of
       
   956         Int es => foldl_map declare_int_elem (ctxt, es)
       
   957       | Ext e => foldl_map (declare_ext_elem prep_vars) (ctxt, [e]))
       
   958       handle ERROR msg => err_in_locale ctxt msg [(name, map fst ps)]
       
   959     in (ctxt', propps) end
       
   960   | declare_elems _ (ctxt, ((_, Derived _), elems)) = (ctxt, []);
       
   961 
       
   962 in
       
   963 
       
   964 (* The Plan:
       
   965 - tell context about parameters and their syntax (possibly also types)
       
   966 - add declarations to context
       
   967 - retrieve parameter types
       
   968 *)
       
   969 
       
   970 end; (* local *)
   932 
   971 
   933 
   972 
   934 (* propositions and bindings *)
   973 (* propositions and bindings *)
   935 
   974 
   936 (* flatten (ctxt, prep_expr) ((ids, syn), expr)
   975 (* flatten (ctxt, prep_expr) ((ids, syn), expr)
  1706         elems = map (fn e => (e, stamp ())) elems',
  1745         elems = map (fn e => (e, stamp ())) elems',
  1707         params = params_of elemss' |> map (fn (x, SOME T) => ((x, T), the (Symtab.lookup syn x))),
  1746         params = params_of elemss' |> map (fn (x, SOME T) => ((x, T), the (Symtab.lookup syn x))),
  1708         lparams = map #1 (params_of body_elemss),
  1747         lparams = map #1 (params_of body_elemss),
  1709         abbrevs = [],
  1748         abbrevs = [],
  1710         regs = []};
  1749         regs = []};
  1711   in (name, ProofContext.transfer thy' body_ctxt, thy') end;
  1750   in ((name, ProofContext.transfer thy' body_ctxt), thy') end;
  1712 
  1751 
  1713 in
  1752 in
  1714 
  1753 
  1715 val add_locale = gen_add_locale read_context intern_expr;
  1754 val add_locale = gen_add_locale read_context intern_expr;
  1716 val add_locale_i = gen_add_locale cert_context (K I);
  1755 val add_locale_i = gen_add_locale cert_context (K I);
  1717 
  1756 
  1718 end;
  1757 end;
  1719 
  1758 
  1720 val _ = Context.add_setup
  1759 val _ = Context.add_setup
  1721  (add_locale_i true "var" empty [Fixes [(Syntax.internal "x", NONE, NoSyn)]] #> #3 #>
  1760  (add_locale_i true "var" empty [Fixes [(Syntax.internal "x", NONE, NoSyn)]] #> snd #>
  1722   add_locale_i true "struct" empty [Fixes [(Syntax.internal "S", NONE, Structure)]] #> #3);
  1761   add_locale_i true "struct" empty [Fixes [(Syntax.internal "S", NONE, Structure)]] #> snd);
  1723 
  1762 
  1724 
  1763 
  1725 
  1764 
  1726 (** locale goals **)
  1765 (** locale goals **)
  1727 
  1766