doc-src/IsarImplementation/Thy/ML.thy
changeset 29612 4f68e0f8f4fd
parent 29581 b3b33e0298eb
child 29646 5941c156902d
equal deleted inserted replaced
29611:9891e3646809 29612:4f68e0f8f4fd
   317   a theory by constant declararion and primitive definitions:
   317   a theory by constant declararion and primitive definitions:
   318 
   318 
   319   \smallskip\begin{mldecls}
   319   \smallskip\begin{mldecls}
   320   @{ML "Sign.declare_const: Properties.T -> (binding * typ) * mixfix
   320   @{ML "Sign.declare_const: Properties.T -> (binding * typ) * mixfix
   321   -> theory -> term * theory"} \\
   321   -> theory -> term * theory"} \\
   322   @{ML "Thm.add_def: bool -> bool -> bstring * term -> theory -> thm * theory"}
   322   @{ML "Thm.add_def: bool -> bool -> binding * term -> theory -> thm * theory"}
   323   \end{mldecls}
   323   \end{mldecls}
   324 
   324 
   325   \noindent Written with naive application, an addition of constant
   325   \noindent Written with naive application, an addition of constant
   326   @{term bar} with type @{typ "foo \<Rightarrow> foo"} and
   326   @{term bar} with type @{typ "foo \<Rightarrow> foo"} and
   327   a corresponding definition @{term "bar \<equiv> \<lambda>x. x"} would look like:
   327   a corresponding definition @{term "bar \<equiv> \<lambda>x. x"} would look like:
   328 
   328 
   329   \smallskip\begin{mldecls}
   329   \smallskip\begin{mldecls}
   330   @{ML "(fn (t, thy) => Thm.add_def false false
   330   @{ML "(fn (t, thy) => Thm.add_def false false
   331   (\"bar_def\", Logic.mk_equals (t, @{term \"%x. x\"})) thy)
   331   (Binding.name \"bar_def\", Logic.mk_equals (t, @{term \"%x. x\"})) thy)
   332     (Sign.declare_const []
   332     (Sign.declare_const []
   333       ((Binding.name \"bar\", @{typ \"foo => foo\"}), NoSyn) thy)"}
   333       ((Binding.name \"bar\", @{typ \"foo => foo\"}), NoSyn) thy)"}
   334   \end{mldecls}
   334   \end{mldecls}
   335 
   335 
   336   \noindent With increasing numbers of applications, this code gets quite
   336   \noindent With increasing numbers of applications, this code gets quite
   345   \smallskip\begin{mldecls}
   345   \smallskip\begin{mldecls}
   346 @{ML "thy
   346 @{ML "thy
   347 |> Sign.declare_const [] ((Binding.name \"bar\", @{typ \"foo => foo\"}), NoSyn)
   347 |> Sign.declare_const [] ((Binding.name \"bar\", @{typ \"foo => foo\"}), NoSyn)
   348 |> (fn (t, thy) => thy
   348 |> (fn (t, thy) => thy
   349 |> Thm.add_def false false
   349 |> Thm.add_def false false
   350      (\"bar_def\", Logic.mk_equals (t, @{term \"%x. x\"})))"}
   350      (Binding.name \"bar_def\", Logic.mk_equals (t, @{term \"%x. x\"})))"}
   351   \end{mldecls}
   351   \end{mldecls}
   352 *}
   352 *}
   353 
   353 
   354 text %mlref {*
   354 text %mlref {*
   355   \begin{mldecls}
   355   \begin{mldecls}
   368 
   368 
   369   \smallskip\begin{mldecls}
   369   \smallskip\begin{mldecls}
   370 @{ML "thy
   370 @{ML "thy
   371 |> Sign.declare_const [] ((Binding.name \"bar\", @{typ \"foo => foo\"}), NoSyn)
   371 |> Sign.declare_const [] ((Binding.name \"bar\", @{typ \"foo => foo\"}), NoSyn)
   372 |-> (fn t => Thm.add_def false false
   372 |-> (fn t => Thm.add_def false false
   373       (\"bar_def\", Logic.mk_equals (t, @{term \"%x. x\"})))
   373       (Binding.name \"bar_def\", Logic.mk_equals (t, @{term \"%x. x\"})))
   374 "}
   374 "}
   375   \end{mldecls}
   375   \end{mldecls}
   376 
   376 
   377   \noindent @{ML "op |>>"} allows for processing side results on their own:
   377   \noindent @{ML "op |>>"} allows for processing side results on their own:
   378 
   378 
   379   \smallskip\begin{mldecls}
   379   \smallskip\begin{mldecls}
   380 @{ML "thy
   380 @{ML "thy
   381 |> Sign.declare_const [] ((Binding.name \"bar\", @{typ \"foo => foo\"}), NoSyn)
   381 |> Sign.declare_const [] ((Binding.name \"bar\", @{typ \"foo => foo\"}), NoSyn)
   382 |>> (fn t => Logic.mk_equals (t, @{term \"%x. x\"}))
   382 |>> (fn t => Logic.mk_equals (t, @{term \"%x. x\"}))
   383 |-> (fn def => Thm.add_def false false (\"bar_def\", def))
   383 |-> (fn def => Thm.add_def false false (Binding.name \"bar_def\", def))
   384 "}
   384 "}
   385   \end{mldecls}
   385   \end{mldecls}
   386 
   386 
   387   \noindent Orthogonally, @{ML "op ||>"} applies a transformation
   387   \noindent Orthogonally, @{ML "op ||>"} applies a transformation
   388   in the presence of side results which are left unchanged:
   388   in the presence of side results which are left unchanged:
   390   \smallskip\begin{mldecls}
   390   \smallskip\begin{mldecls}
   391 @{ML "thy
   391 @{ML "thy
   392 |> Sign.declare_const [] ((Binding.name \"bar\", @{typ \"foo => foo\"}), NoSyn)
   392 |> Sign.declare_const [] ((Binding.name \"bar\", @{typ \"foo => foo\"}), NoSyn)
   393 ||> Sign.add_path \"foobar\"
   393 ||> Sign.add_path \"foobar\"
   394 |-> (fn t => Thm.add_def false false
   394 |-> (fn t => Thm.add_def false false
   395       (\"bar_def\", Logic.mk_equals (t, @{term \"%x. x\"})))
   395       (Binding.name \"bar_def\", Logic.mk_equals (t, @{term \"%x. x\"})))
   396 ||> Sign.restore_naming thy
   396 ||> Sign.restore_naming thy
   397 "}
   397 "}
   398   \end{mldecls}
   398   \end{mldecls}
   399 
   399 
   400   \noindent @{ML "op ||>>"} accumulates side results:
   400   \noindent @{ML "op ||>>"} accumulates side results:
   402   \smallskip\begin{mldecls}
   402   \smallskip\begin{mldecls}
   403 @{ML "thy
   403 @{ML "thy
   404 |> Sign.declare_const [] ((Binding.name \"bar\", @{typ \"foo => foo\"}), NoSyn)
   404 |> Sign.declare_const [] ((Binding.name \"bar\", @{typ \"foo => foo\"}), NoSyn)
   405 ||>> Sign.declare_const [] ((Binding.name \"foobar\", @{typ \"foo => foo\"}), NoSyn)
   405 ||>> Sign.declare_const [] ((Binding.name \"foobar\", @{typ \"foo => foo\"}), NoSyn)
   406 |-> (fn (t1, t2) => Thm.add_def false false
   406 |-> (fn (t1, t2) => Thm.add_def false false
   407       (\"bar_def\", Logic.mk_equals (t1, t2)))
   407       (Binding.name \"bar_def\", Logic.mk_equals (t1, t2)))
   408 "}
   408 "}
   409   \end{mldecls}
   409   \end{mldecls}
   410 *}
   410 *}
   411 
   411 
   412 text %mlref {*
   412 text %mlref {*
   449   thy
   449   thy
   450   |> fold_map (fn const => Sign.declare_const []
   450   |> fold_map (fn const => Sign.declare_const []
   451        ((Binding.name const, @{typ \"foo => foo\"}), NoSyn)) consts
   451        ((Binding.name const, @{typ \"foo => foo\"}), NoSyn)) consts
   452   |>> map (fn t => Logic.mk_equals (t, @{term \"%x. x\"}))
   452   |>> map (fn t => Logic.mk_equals (t, @{term \"%x. x\"}))
   453   |-> (fn defs => fold_map (fn def =>
   453   |-> (fn defs => fold_map (fn def =>
   454        Thm.add_def false false (\"\", def)) defs)
   454        Thm.add_def false false (Binding.empty, def)) defs)
   455 end"}
   455 end"}
   456   \end{mldecls}
   456   \end{mldecls}
   457 *}
   457 *}
   458 
   458 
   459 text %mlref {*
   459 text %mlref {*