# HG changeset patch # User wenzelm # Date 1656144336 -7200 # Node ID be89ec4a452323a52205c6a6923930e80d9e80ce # Parent 986506233812496ea38eb5f3b8813e7dfe3ab76e tuned whitespace; diff -r 986506233812 -r be89ec4a4523 src/Doc/Implementation/ML.thy --- a/src/Doc/Implementation/ML.thy Fri Jun 24 23:38:41 2022 +0200 +++ b/src/Doc/Implementation/ML.thy Sat Jun 25 10:05:36 2022 +0200 @@ -140,11 +140,12 @@ paragraph \Scopes.\ text \ Apart from very basic library modules, ML structures are not ``opened'', but - names are referenced with explicit qualification, as in \<^ML>\Syntax.string_of_term\ for example. When devising names for structures and - their components it is important to aim at eye-catching compositions of both - parts, because this is how they are seen in the sources and documentation. - For the same reasons, aliases of well-known library functions should be - avoided. + names are referenced with explicit qualification, as in + \<^ML>\Syntax.string_of_term\ for example. When devising names for + structures and their components it is important to aim at eye-catching + compositions of both parts, because this is how they are seen in the sources + and documentation. For the same reasons, aliases of well-known library + functions should be avoided. Local names of function abstraction or case/let bindings are typically shorter, sometimes using only rudiments of ``words'', while still avoiding @@ -185,8 +186,10 @@ text \ Here are some specific name forms that occur frequently in the sources. - \<^item> A function that maps \<^ML_text>\foo\ to \<^ML_text>\bar\ is called \<^ML_text>\foo_to_bar\ or \<^ML_text>\bar_of_foo\ (never \<^ML_text>\foo2bar\, nor - \<^ML_text>\bar_from_foo\, nor \<^ML_text>\bar_for_foo\, nor \<^ML_text>\bar4foo\). + \<^item> A function that maps \<^ML_text>\foo\ to \<^ML_text>\bar\ is called + \<^ML_text>\foo_to_bar\ or \<^ML_text>\bar_of_foo\ (never + \<^ML_text>\foo2bar\, nor \<^ML_text>\bar_from_foo\, nor + \<^ML_text>\bar_for_foo\, nor \<^ML_text>\bar4foo\). \<^item> The name component \<^ML_text>\legacy\ means that the operation is about to be discontinued soon. @@ -206,7 +209,8 @@ \<^item> theories are called \<^ML_text>\thy\, rarely \<^ML_text>\theory\ (never \<^ML_text>\thry\) - \<^item> proof contexts are called \<^ML_text>\ctxt\, rarely \<^ML_text>\context\ (never \<^ML_text>\ctx\) + \<^item> proof contexts are called \<^ML_text>\ctxt\, rarely \<^ML_text>\context\ + (never \<^ML_text>\ctx\) \<^item> generic contexts are called \<^ML_text>\context\ @@ -547,9 +551,10 @@ \ text \ - Here the ML environment is already managed by Isabelle, i.e.\ the \<^ML>\factorial\ function is not yet accessible in the preceding paragraph, nor in - a different theory that is independent from the current one in the import - hierarchy. + Here the ML environment is already managed by Isabelle, i.e.\ the + \<^ML>\factorial\ function is not yet accessible in the preceding paragraph, + nor in a different theory that is independent from the current one in the + import hierarchy. Removing the above ML declaration from the source text will remove any trace of this definition, as expected. The Isabelle/ML toplevel environment is @@ -583,8 +588,9 @@ Two further ML commands are useful in certain situations: @{command_ref ML_val} and @{command_ref ML_command} are \<^emph>\diagnostic\ in the sense that there is no effect on the underlying environment, and can thus be used - anywhere. The examples below produce long strings of digits by invoking \<^ML>\factorial\: @{command ML_val} takes care of printing the ML toplevel result, - but @{command ML_command} is silent so we produce an explicit output + anywhere. The examples below produce long strings of digits by invoking + \<^ML>\factorial\: @{command ML_val} takes care of printing the ML toplevel + result, but @{command ML_command} is silent so we produce an explicit output message. \ @@ -894,9 +900,10 @@ \ text \ - Note how \<^ML>\fold (Buffer.add o string_of_int)\ above saves an extra \<^ML>\map\ over the given list. This kind of peephole optimization reduces both - the code size and the tree structures in memory (``deforestation''), but it - requires some practice to read and write fluently. + Note how \<^ML>\fold (Buffer.add o string_of_int)\ above saves an extra + \<^ML>\map\ over the given list. This kind of peephole optimization reduces + both the code size and the tree structures in memory (``deforestation''), + but it requires some practice to read and write fluently. \<^medskip> The next example elaborates the idea of canonical iteration, demonstrating @@ -939,10 +946,12 @@ buffers that can be continued in further linear transformations, folding etc. Thus it is more compositional than the naive \<^ML>\slow_content\. As realistic example, compare the old-style - \<^ML>\Term.maxidx_of_term: term -> int\ with the newer \<^ML>\Term.maxidx_term: term -> int -> int\ in Isabelle/Pure. + \<^ML>\Term.maxidx_of_term: term -> int\ with the newer + \<^ML>\Term.maxidx_term: term -> int -> int\ in Isabelle/Pure. Note that \<^ML>\fast_content\ above is only defined as example. In many - practical situations, it is customary to provide the incremental \<^ML>\add_content\ only and leave the initialization and termination to the + practical situations, it is customary to provide the incremental + \<^ML>\add_content\ only and leave the initialization and termination to the concrete application to the user. \ @@ -1007,8 +1016,9 @@ \begin{warn} Regular Isabelle/ML code should output messages exclusively by the official - channels. Using raw I/O on \<^emph>\stdout\ or \<^emph>\stderr\ instead (e.g.\ via \<^ML>\TextIO.output\) is apt to cause problems in the presence of parallel and - asynchronous processing of Isabelle theories. Such raw output might be + channels. Using raw I/O on \<^emph>\stdout\ or \<^emph>\stderr\ instead (e.g.\ via + \<^ML>\TextIO.output\) is apt to cause problems in the presence of parallel + and asynchronous processing of Isabelle theories. Such raw output might be displayed by the front-end in some system console log, with a low chance that the user will ever see it. Moreover, as a genuine side-effect on global process channels, there is no proper way to retract output when Isar command @@ -1304,12 +1314,15 @@ is mainly that of the list structure: individual symbols that happen to be a singleton string do not require extra memory in Poly/ML.\ - \<^descr> \<^ML>\Symbol.is_letter\, \<^ML>\Symbol.is_digit\, \<^ML>\Symbol.is_quasi\, \<^ML>\Symbol.is_blank\ classify standard symbols + \<^descr> \<^ML>\Symbol.is_letter\, \<^ML>\Symbol.is_digit\, + \<^ML>\Symbol.is_quasi\, \<^ML>\Symbol.is_blank\ classify standard symbols according to fixed syntactic conventions of Isabelle, cf.\ @{cite "isabelle-isar-ref"}. \<^descr> Type \<^ML_type>\Symbol.sym\ is a concrete datatype that represents the - different kinds of symbols explicitly, with constructors \<^ML>\Symbol.Char\, \<^ML>\Symbol.UTF8\, \<^ML>\Symbol.Sym\, \<^ML>\Symbol.Control\, \<^ML>\Symbol.Malformed\. + different kinds of symbols explicitly, with constructors + \<^ML>\Symbol.Char\, \<^ML>\Symbol.UTF8\, \<^ML>\Symbol.Sym\, + \<^ML>\Symbol.Control\, \<^ML>\Symbol.Malformed\. \<^descr> \<^ML>\Symbol.decode\ converts the string representation of a symbol into the datatype version. @@ -1336,7 +1349,8 @@ of its operations simply do not fit with important Isabelle/ML conventions (like ``canonical argument order'', see \secref{sec:canonical-argument-order}), others cause problems with the - parallel evaluation model of Isabelle/ML (such as \<^ML>\TextIO.print\ or \<^ML>\OS.Process.system\). + parallel evaluation model of Isabelle/ML (such as \<^ML>\TextIO.print\ or + \<^ML>\OS.Process.system\). Subsequently we give a brief overview of important operations on basic ML data types. @@ -1370,7 +1384,8 @@ Isabelle-specific purposes with the following implicit substructures packed into the string content: - \<^enum> sequence of Isabelle symbols (see also \secref{sec:symbols}), with \<^ML>\Symbol.explode\ as key operation; + \<^enum> sequence of Isabelle symbols (see also \secref{sec:symbols}), with + \<^ML>\Symbol.explode\ as key operation; \<^enum> XML tree structure via YXML (see also @{cite "isabelle-system"}), with \<^ML>\YXML.parse_body\ as key operation. @@ -1544,7 +1559,8 @@ text \ Here the first list is treated conservatively: only the new elements from - the second list are inserted. The inside-out order of insertion via \<^ML>\fold_rev\ attempts to preserve the order of elements in the result. + the second list are inserted. The inside-out order of insertion via + \<^ML>\fold_rev\ attempts to preserve the order of elements in the result. This way of merging lists is typical for context data (\secref{sec:context-data}). See also \<^ML>\merge\ as defined in @@ -2128,8 +2144,9 @@ \<^item> \pri : int\ (default \<^ML>\0\) specifies a priority within the task queue. - Typically there is only little deviation from the default priority \<^ML>\0\. As a rule of thumb, \<^ML>\~1\ means ``low priority" and \<^ML>\1\ means - ``high priority''. + Typically there is only little deviation from the default priority + \<^ML>\0\. As a rule of thumb, \<^ML>\~1\ means ``low priority" and + \<^ML>\1\ means ``high priority''. Note that the task priority only affects the position in the queue, not the thread priority. When a worker thread picks up a task for processing, @@ -2184,10 +2201,11 @@ There is very low overhead for this proforma wrapping of strict values as futures. - \<^descr> \<^ML>\Future.map\~\f x\ is a fast-path implementation of \<^ML>\Future.fork\~\(fn () => f (\\<^ML>\Future.join\~\x))\, which avoids the full - overhead of the task queue and worker-thread farm as far as possible. The - function \f\ is supposed to be some trivial post-processing or projection of - the future result. + \<^descr> \<^ML>\Future.map\~\f x\ is a fast-path implementation of + \<^ML>\Future.fork\~\(fn () => f (\\<^ML>\Future.join\~\x))\, which avoids + the full overhead of the task queue and worker-thread farm as far as + possible. The function \f\ is supposed to be some trivial post-processing or + projection of the future result. \<^descr> \<^ML>\Future.cancel\~\x\ cancels the task group of the given future, using \<^ML>\Future.cancel_group\ below.