doc-src/IsarImplementation/Thy/document/ML.tex
changeset 26460 21504de31197
parent 26459 bb0e729be5a4
child 26854 9b4aec46ad78
equal deleted inserted replaced
26459:bb0e729be5a4 26460:21504de31197
   358 \isadelimML
   358 \isadelimML
   359 %
   359 %
   360 \endisadelimML
   360 \endisadelimML
   361 %
   361 %
   362 \begin{isamarkuptext}%
   362 \begin{isamarkuptext}%
   363 Many problems in functional programming can be thought of
   363 \noindent Many problems in functional programming can be thought of
   364   as linear transformations, i.e.~a caluclation starts with a
   364   as linear transformations, i.e.~a caluclation starts with a
   365   particular value \verb|x : foo| which is then transformed
   365   particular value \verb|x : foo| which is then transformed
   366   by application of a function \verb|f : foo -> foo|,
   366   by application of a function \verb|f : foo -> foo|,
   367   continued by an application of a function \verb|g : foo -> bar|,
   367   continued by an application of a function \verb|g : foo -> bar|,
   368   and so on.  As a canoncial example, take functions enriching
   368   and so on.  As a canoncial example, take functions enriching
   372   \verb|Sign.declare_const: Markup.property list -> bstring * typ * mixfix|\isasep\isanewline%
   372   \verb|Sign.declare_const: Markup.property list -> bstring * typ * mixfix|\isasep\isanewline%
   373 \verb|  -> theory -> term * theory| \\
   373 \verb|  -> theory -> term * theory| \\
   374   \verb|Thm.add_def: bool -> bool -> bstring * term -> theory -> thm * theory|
   374   \verb|Thm.add_def: bool -> bool -> bstring * term -> theory -> thm * theory|
   375   \end{mldecls}
   375   \end{mldecls}
   376 
   376 
   377   Written with naive application, an addition of constant
   377   \noindent Written with naive application, an addition of constant
   378   \isa{bar} with type \isa{foo\ {\isasymRightarrow}\ foo} and
   378   \isa{bar} with type \isa{foo\ {\isasymRightarrow}\ foo} and
   379   a corresponding definition \isa{bar\ {\isasymequiv}\ {\isasymlambda}x{\isachardot}\ x} would look like:
   379   a corresponding definition \isa{bar\ {\isasymequiv}\ {\isasymlambda}x{\isachardot}\ x} would look like:
   380 
   380 
   381   \smallskip\begin{mldecls}
   381   \smallskip\begin{mldecls}
   382   \verb|(fn (t, thy) => Thm.add_def false false|\isasep\isanewline%
   382   \verb|(fn (t, thy) => Thm.add_def false false|\isasep\isanewline%
   383 \verb|  ("bar_def", Logic.mk_equals (t, @{term "%x. x"})) thy)|\isasep\isanewline%
   383 \verb|  ("bar_def", Logic.mk_equals (t, @{term "%x. x"})) thy)|\isasep\isanewline%
   384 \verb|    (Sign.declare_const []|\isasep\isanewline%
   384 \verb|    (Sign.declare_const []|\isasep\isanewline%
   385 \verb|      ("bar", @{typ "foo => foo"}, NoSyn) thy)|
   385 \verb|      ("bar", @{typ "foo => foo"}, NoSyn) thy)|
   386   \end{mldecls}
   386   \end{mldecls}
   387 
   387 
   388   With increasing numbers of applications, this code gets quite
   388   \noindent With increasing numbers of applications, this code gets quite
   389   unreadable.  Further, it is unintuitive that things are
   389   unreadable.  Further, it is unintuitive that things are
   390   written down in the opposite order as they actually ``happen''.%
   390   written down in the opposite order as they actually ``happen''.%
   391 \end{isamarkuptext}%
   391 \end{isamarkuptext}%
   392 \isamarkuptrue%
   392 \isamarkuptrue%
   393 %
   393 %
   509   such that
   509   such that
   510   \begin{quote}\footnotesize
   510   \begin{quote}\footnotesize
   511     \verb|y |\verb,|,\verb|> fold f [x1, x2, ..., x_n]| \\
   511     \verb|y |\verb,|,\verb|> fold f [x1, x2, ..., x_n]| \\
   512     \hspace*{2ex}\isa{{\isasymleadsto}} \verb|y |\verb,|,\verb|> f x1 |\verb,|,\verb|> f x2 |\verb,|,\verb|> ... |\verb,|,\verb|> f x_n|
   512     \hspace*{2ex}\isa{{\isasymleadsto}} \verb|y |\verb,|,\verb|> f x1 |\verb,|,\verb|> f x2 |\verb,|,\verb|> ... |\verb,|,\verb|> f x_n|
   513   \end{quote}
   513   \end{quote}
   514   The second accumulates side results in a list by lifting
   514   \noindent The second accumulates side results in a list by lifting
   515   a single function
   515   a single function
   516   \begin{quote}\footnotesize
   516   \begin{quote}\footnotesize
   517     \verb|f : 'a -> 'b -> 'c * 'b| to \verb|'a list -> 'b -> 'c list * 'b|
   517     \verb|f : 'a -> 'b -> 'c * 'b| to \verb|'a list -> 'b -> 'c list * 'b|
   518   \end{quote}
   518   \end{quote}
   519   such that
   519   such that