author | wenzelm |
Mon, 08 Nov 2010 00:00:47 +0100 | |
changeset 40406 | 313a24b66a8d |
parent 40310 | a0698ec82e6e |
child 40508 | 76894f975440 |
permissions | -rw-r--r-- |
18537 | 1 |
% |
2 |
\begin{isabellebody}% |
|
3 |
\def\isabellecontext{ML}% |
|
4 |
% |
|
5 |
\isadelimtheory |
|
6 |
% |
|
7 |
\endisadelimtheory |
|
8 |
% |
|
9 |
\isatagtheory |
|
10 |
\isacommand{theory}\isamarkupfalse% |
|
40406 | 11 |
\ {\isaliteral{22}{\isachardoublequoteopen}}ML{\isaliteral{22}{\isachardoublequoteclose}}\isanewline |
29756 | 12 |
\isakeyword{imports}\ Base\isanewline |
13 |
\isakeyword{begin}% |
|
18543 | 14 |
\endisatagtheory |
15 |
{\isafoldtheory}% |
|
16 |
% |
|
17 |
\isadelimtheory |
|
18 |
% |
|
19 |
\endisadelimtheory |
|
20 |
% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
21 |
\isamarkupchapter{Isabelle/ML% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
22 |
} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
23 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
24 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
25 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
26 |
Isabelle/ML is best understood as a certain culture based on |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
27 |
Standard ML. Thus it is not a new programming language, but a |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
28 |
certain way to use SML at an advanced level within the Isabelle |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
29 |
environment. This covers a variety of aspects that are geared |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
30 |
towards an efficient and robust platform for applications of formal |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
31 |
logic with fully foundational proof construction --- according to |
40126 | 32 |
the well-known \emph{LCF principle}. There is specific |
33 |
infrastructure with library modules to address the needs of this |
|
34 |
difficult task. For example, the raw parallel programming model of |
|
35 |
Poly/ML is presented as considerably more abstract concept of |
|
36 |
\emph{future values}, which is then used to augment the inference |
|
37 |
kernel, proof interpreter, and theory loader accordingly. |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
38 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
39 |
The main aspects of Isabelle/ML are introduced below. These |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
40 |
first-hand explanations should help to understand how proper |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
41 |
Isabelle/ML is to be read and written, and to get access to the |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
42 |
wealth of experience that is expressed in the source text and its |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
43 |
history of changes.\footnote{See |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
44 |
\url{http://isabelle.in.tum.de/repos/isabelle} for the full |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
45 |
Mercurial history. There are symbolic tags to refer to official |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
46 |
Isabelle releases, as opposed to arbitrary \emph{tip} versions that |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
47 |
merely reflect snapshots that are never really up-to-date.}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
48 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
49 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
50 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
51 |
\isamarkupsection{Style and orthography% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
52 |
} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
53 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
54 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
55 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
56 |
The sources of Isabelle/Isar are optimized for |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
57 |
\emph{readability} and \emph{maintainability}. The main purpose is |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
58 |
to tell an informed reader what is really going on and how things |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
59 |
really work. This is a non-trivial aim, but it is supported by a |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
60 |
certain style of writing Isabelle/ML that has emerged from long |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
61 |
years of system development.\footnote{See also the interesting style |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
62 |
guide for OCaml |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
63 |
\url{http://caml.inria.fr/resources/doc/guides/guidelines.en.html} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
64 |
which shares many of our means and ends.} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
65 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
66 |
The main principle behind any coding style is \emph{consistency}. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
67 |
For a single author of a small program this merely means ``choose |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
68 |
your style and stick to it''. A complex project like Isabelle, with |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
69 |
long years of development and different contributors, requires more |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
70 |
standardization. A coding style that is changed every few years or |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
71 |
with every new contributor is no style at all, because consistency |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
72 |
is quickly lost. Global consistency is hard to achieve, though. |
40126 | 73 |
Nonetheless, one should always strive at least for local consistency |
74 |
of modules and sub-systems, without deviating from some general |
|
75 |
principles how to write Isabelle/ML. |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
76 |
|
40126 | 77 |
In a sense, good coding style is like an \emph{orthography} for the |
78 |
sources: it helps to read quickly over the text and see through the |
|
79 |
main points, without getting distracted by accidental presentation |
|
80 |
of free-style code.% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
81 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
82 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
83 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
84 |
\isamarkupsubsection{Header and sectioning% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
85 |
} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
86 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
87 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
88 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
89 |
Isabelle source files have a certain standardized header |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
90 |
format (with precise spacing) that follows ancient traditions |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
91 |
reaching back to the earliest versions of the system by Larry |
40406 | 92 |
Paulson. See \hyperlink{file.~~/src/Pure/thm.ML}{\mbox{\isa{\isatt{{\isaliteral{7E}{\isachartilde}}{\isaliteral{7E}{\isachartilde}}{\isaliteral{2F}{\isacharslash}}src{\isaliteral{2F}{\isacharslash}}Pure{\isaliteral{2F}{\isacharslash}}thm{\isaliteral{2E}{\isachardot}}ML}}}}, for example. |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
93 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
94 |
The header includes at least \verb|Title| and \verb|Author| entries, followed by a prose description of the purpose of |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
95 |
the module. The latter can range from a single line to several |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
96 |
paragraphs of explanations. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
97 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
98 |
The rest of the file is divided into sections, subsections, |
40126 | 99 |
subsubsections, paragraphs etc.\ using a simple layout via ML |
100 |
comments as follows. |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
101 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
102 |
\begin{verbatim} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
103 |
(*** section ***) |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
104 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
105 |
(** subsection **) |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
106 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
107 |
(* subsubsection *) |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
108 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
109 |
(*short paragraph*) |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
110 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
111 |
(* |
40126 | 112 |
long paragraph, |
113 |
with more text |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
114 |
*) |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
115 |
\end{verbatim} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
116 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
117 |
As in regular typography, there is some extra space \emph{before} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
118 |
section headings that are adjacent to plain text (not other headings |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
119 |
as in the example above). |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
120 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
121 |
\medskip The precise wording of the prose text given in these |
40126 | 122 |
headings is chosen carefully to introduce the main theme of the |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
123 |
subsequent formal ML text.% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
124 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
125 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
126 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
127 |
\isamarkupsubsection{Naming conventions% |
18543 | 128 |
} |
129 |
\isamarkuptrue% |
|
130 |
% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
131 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
132 |
Since ML is the primary medium to express the meaning of the |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
133 |
source text, naming of ML entities requires special care. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
134 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
135 |
\paragraph{Notation.} A name consists of 1--3 \emph{words} (rarely |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
136 |
4, but not more) that are separated by underscore. There are three |
40126 | 137 |
variants concerning upper or lower case letters, which are used for |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
138 |
certain ML categories as follows: |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
139 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
140 |
\medskip |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
141 |
\begin{tabular}{lll} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
142 |
variant & example & ML categories \\\hline |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
143 |
lower-case & \verb|foo_bar| & values, types, record fields \\ |
40126 | 144 |
capitalized & \verb|Foo_Bar| & datatype constructors, structures, functors \\ |
145 |
upper-case & \verb|FOO_BAR| & special values, exception constructors, signatures \\ |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
146 |
\end{tabular} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
147 |
\medskip |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
148 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
149 |
For historical reasons, many capitalized names omit underscores, |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
150 |
e.g.\ old-style \verb|FooBar| instead of \verb|Foo_Bar|. |
40126 | 151 |
Genuine mixed-case names are \emph{not} used, bacause clear division |
152 |
of words is essential for readability.\footnote{Camel-case was |
|
153 |
invented to workaround the lack of underscore in some early |
|
154 |
non-ASCII character sets. Later it became habitual in some language |
|
155 |
communities that are now strong in numbers.} |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
156 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
157 |
A single (capital) character does not count as ``word'' in this |
40126 | 158 |
respect: some Isabelle/ML names are suffixed by extra markers like |
159 |
this: \verb|foo_barT|. |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
160 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
161 |
Name variants are produced by adding 1--3 primes, e.g.\ \verb|foo'|, \verb|foo''|, or \verb|foo'''|, but not \verb|foo''''| or more. Decimal digits scale better to larger numbers, |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
162 |
e.g.\ \verb|foo0|, \verb|foo1|, \verb|foo42|. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
163 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
164 |
\paragraph{Scopes.} Apart from very basic library modules, ML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
165 |
structures are not ``opened'', but names are referenced with |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
166 |
explicit qualification, as in \verb|Syntax.string_of_term| for |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
167 |
example. When devising names for structures and their components it |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
168 |
is important aim at eye-catching compositions of both parts, because |
40126 | 169 |
this is how they are seen in the sources and documentation. For the |
170 |
same reasons, aliases of well-known library functions should be |
|
171 |
avoided. |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
172 |
|
40126 | 173 |
Local names of function abstraction or case/let bindings are |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
174 |
typically shorter, sometimes using only rudiments of ``words'', |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
175 |
while still avoiding cryptic shorthands. An auxiliary function |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
176 |
called \verb|helper|, \verb|aux|, or \verb|f| is |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
177 |
considered bad style. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
178 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
179 |
Example: |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
180 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
181 |
\begin{verbatim} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
182 |
(* RIGHT *) |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
183 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
184 |
fun print_foo ctxt foo = |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
185 |
let |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
186 |
fun print t = ... Syntax.string_of_term ctxt t ... |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
187 |
in ... end; |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
188 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
189 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
190 |
(* RIGHT *) |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
191 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
192 |
fun print_foo ctxt foo = |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
193 |
let |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
194 |
val string_of_term = Syntax.string_of_term ctxt; |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
195 |
fun print t = ... string_of_term t ... |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
196 |
in ... end; |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
197 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
198 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
199 |
(* WRONG *) |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
200 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
201 |
val string_of_term = Syntax.string_of_term; |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
202 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
203 |
fun print_foo ctxt foo = |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
204 |
let |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
205 |
fun aux t = ... string_of_term ctxt t ... |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
206 |
in ... end; |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
207 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
208 |
\end{verbatim} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
209 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
210 |
|
40126 | 211 |
\paragraph{Specific conventions.} Here are some specific name forms |
212 |
that occur frequently in the sources. |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
213 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
214 |
\begin{itemize} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
215 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
216 |
\item A function that maps \verb|foo| to \verb|bar| is |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
217 |
called \verb|foo_to_bar| or \verb|bar_of_foo| (never |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
218 |
\verb|foo2bar|, \verb|bar_from_foo|, \verb|bar_for_foo|, or \verb|bar4foo|). |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
219 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
220 |
\item The name component \verb|legacy| means that the operation |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
221 |
is about to be discontinued soon. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
222 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
223 |
\item The name component \verb|old| means that this is historic |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
224 |
material that might disappear at some later stage. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
225 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
226 |
\item The name component \verb|global| means that this works |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
227 |
with the background theory instead of the regular local context |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
228 |
(\secref{sec:context}), sometimes for historical reasons, sometimes |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
229 |
due a genuine lack of locality of the concept involved, sometimes as |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
230 |
a fall-back for the lack of a proper context in the application |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
231 |
code. Whenever there is a non-global variant available, the |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
232 |
application should be migrated to use it with a proper local |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
233 |
context. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
234 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
235 |
\item Variables of the main context types of the Isabelle/Isar |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
236 |
framework (\secref{sec:context} and \chref{ch:local-theory}) have |
40126 | 237 |
firm naming conventions as follows: |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
238 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
239 |
\begin{itemize} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
240 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
241 |
\item theories are called \verb|thy|, rarely \verb|theory| |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
242 |
(never \verb|thry|) |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
243 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
244 |
\item proof contexts are called \verb|ctxt|, rarely \verb|context| (never \verb|ctx|) |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
245 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
246 |
\item generic contexts are called \verb|context|, rarely |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
247 |
\verb|ctxt| |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
248 |
|
40126 | 249 |
\item local theories are called \verb|lthy|, except for local |
250 |
theories that are treated as proof context (which is a semantic |
|
251 |
super-type) |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
252 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
253 |
\end{itemize} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
254 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
255 |
Variations with primed or decimal numbers are always possible, as |
40126 | 256 |
well as sematic prefixes like \verb|foo_thy| or \verb|bar_ctxt|, but the base conventions above need to be preserved. |
257 |
This allows to visualize the their data flow via plain regular |
|
258 |
expressions in the editor. |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
259 |
|
40126 | 260 |
\item The main logical entities (\secref{ch:logic}) have established |
261 |
naming convention as follows: |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
262 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
263 |
\begin{itemize} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
264 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
265 |
\item sorts are called \verb|S| |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
266 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
267 |
\item types are called \verb|T|, \verb|U|, or \verb|ty| (never \verb|t|) |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
268 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
269 |
\item terms are called \verb|t|, \verb|u|, or \verb|tm| (never \verb|trm|) |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
270 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
271 |
\item certified types are called \verb|cT|, rarely \verb|T|, with variants as for types |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
272 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
273 |
\item certified terms are called \verb|ct|, rarely \verb|t|, with variants as for terms |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
274 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
275 |
\item theorems are called \verb|th|, or \verb|thm| |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
276 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
277 |
\end{itemize} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
278 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
279 |
Proper semantic names override these conventions completely. For |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
280 |
example, the left-hand side of an equation (as a term) can be called |
40126 | 281 |
\verb|lhs| (not \verb|lhs_tm|). Or a term that is known |
282 |
to be a variable can be called \verb|v| or \verb|x|. |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
283 |
|
40310 | 284 |
\item Tactics (\secref{sec:tactics}) are sufficiently important to |
285 |
have specific naming conventions. The name of a basic tactic |
|
286 |
definition always has a \verb|_tac| suffix, the subgoal index |
|
287 |
(if applicable) is always called \verb|i|, and the goal state |
|
288 |
(if made explicit) is usually called \verb|st| instead of the |
|
289 |
somewhat misleading \verb|thm|. Any other arguments are given |
|
290 |
before the latter two, and the general context is given first. |
|
291 |
Example: |
|
292 |
||
293 |
\begin{verbatim} |
|
294 |
fun my_tac ctxt arg1 arg2 i st = ... |
|
295 |
\end{verbatim} |
|
296 |
||
297 |
Note that the goal state \verb|st| above is rarely made |
|
298 |
explicit, if tactic combinators (tacticals) are used as usual. |
|
299 |
||
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
300 |
\end{itemize}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
301 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
302 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
303 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
304 |
\isamarkupsubsection{General source layout% |
24089 | 305 |
} |
306 |
\isamarkuptrue% |
|
307 |
% |
|
18543 | 308 |
\begin{isamarkuptext}% |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
309 |
The general Isabelle/ML source layout imitates regular |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
310 |
type-setting to some extent, augmented by the requirements for |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
311 |
deeply nested expressions that are commonplace in functional |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
312 |
programming. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
313 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
314 |
\paragraph{Line length} is 80 characters according to ancient |
40126 | 315 |
standards, but we allow as much as 100 characters (not |
316 |
more).\footnote{Readability requires to keep the beginning of a line |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
317 |
in view while watching its end. Modern wide-screen displays do not |
40126 | 318 |
change the way how the human brain works. Sources also need to be |
319 |
printable on plain paper with reasonable font-size.} The extra 20 |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
320 |
characters acknowledge the space requirements due to qualified |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
321 |
library references in Isabelle/ML. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
322 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
323 |
\paragraph{White-space} is used to emphasize the structure of |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
324 |
expressions, following mostly standard conventions for mathematical |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
325 |
typesetting, as can be seen in plain {\TeX} or {\LaTeX}. This |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
326 |
defines positioning of spaces for parentheses, punctuation, and |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
327 |
infixes as illustrated here: |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
328 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
329 |
\begin{verbatim} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
330 |
val x = y + z * (a + b); |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
331 |
val pair = (a, b); |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
332 |
val record = {foo = 1, bar = 2}; |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
333 |
\end{verbatim} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
334 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
335 |
Lines are normally broken \emph{after} an infix operator or |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
336 |
punctuation character. For example: |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
337 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
338 |
\begin{verbatim} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
339 |
val x = |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
340 |
a + |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
341 |
b + |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
342 |
c; |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
343 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
344 |
val tuple = |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
345 |
(a, |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
346 |
b, |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
347 |
c); |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
348 |
\end{verbatim} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
349 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
350 |
Some special infixes (e.g.\ \verb||\verb,|,\verb|>|) work better at the |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
351 |
start of the line, but punctuation is always at the end. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
352 |
|
40406 | 353 |
Function application follows the tradition of \isa{{\isaliteral{5C3C6C616D6264613E}{\isasymlambda}}}-calculus, |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
354 |
not informal mathematics. For example: \verb|f a b| for a |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
355 |
curried function, or \verb|g (a, b)| for a tupled function. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
356 |
Note that the space between \verb|g| and the pair \verb|(a, b)| follows the important principle of |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
357 |
\emph{compositionality}: the layout of \verb|g p| does not |
40126 | 358 |
change when \verb|p| is refined to the concrete pair |
359 |
\verb|(a, b)|. |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
360 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
361 |
\paragraph{Indentation} uses plain spaces, never hard |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
362 |
tabulators.\footnote{Tabulators were invented to move the carriage |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
363 |
of a type-writer to certain predefined positions. In software they |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
364 |
could be used as a primitive run-length compression of consecutive |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
365 |
spaces, but the precise result would depend on non-standardized |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
366 |
editor configuration.} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
367 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
368 |
Each level of nesting is indented by 2 spaces, sometimes 1, very |
40126 | 369 |
rarely 4, never 8 or any other odd number. |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
370 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
371 |
Indentation follows a simple logical format that only depends on the |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
372 |
nesting depth, not the accidental length of the text that initiates |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
373 |
a level of nesting. Example: |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
374 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
375 |
\begin{verbatim} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
376 |
(* RIGHT *) |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
377 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
378 |
if b then |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
379 |
expr1_part1 |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
380 |
expr1_part2 |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
381 |
else |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
382 |
expr2_part1 |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
383 |
expr2_part2 |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
384 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
385 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
386 |
(* WRONG *) |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
387 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
388 |
if b then expr1_part1 |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
389 |
expr1_part2 |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
390 |
else expr2_part1 |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
391 |
expr2_part2 |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
392 |
\end{verbatim} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
393 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
394 |
The second form has many problems: it assumes a fixed-width font |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
395 |
when viewing the sources, it uses more space on the line and thus |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
396 |
makes it hard to observe its strict length limit (working against |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
397 |
\emph{readability}), it requires extra editing to adapt the layout |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
398 |
to changes of the initial text (working against |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
399 |
\emph{maintainability}) etc. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
400 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
401 |
\medskip For similar reasons, any kind of two-dimensional or tabular |
40126 | 402 |
layouts, ASCII-art with lines or boxes of asterisks etc.\ should be |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
403 |
avoided. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
404 |
|
40126 | 405 |
\paragraph{Complex expressions} that consist of multi-clausal |
406 |
function definitions, \verb|handle|, \verb|case|, |
|
407 |
\verb|let| (and combinations) require special attention. The |
|
408 |
syntax of Standard ML is quite ambitious and admits a lot of |
|
409 |
variance that can distort the meaning of the text. |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
410 |
|
40126 | 411 |
Clauses of \verb|fun|, \verb|fn|, \verb|handle|, |
412 |
\verb|case| get extra indentation to indicate the nesting |
|
413 |
clearly. Example: |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
414 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
415 |
\begin{verbatim} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
416 |
(* RIGHT *) |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
417 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
418 |
fun foo p1 = |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
419 |
expr1 |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
420 |
| foo p2 = |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
421 |
expr2 |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
422 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
423 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
424 |
(* WRONG *) |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
425 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
426 |
fun foo p1 = |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
427 |
expr1 |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
428 |
| foo p2 = |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
429 |
expr2 |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
430 |
\end{verbatim} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
431 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
432 |
Body expressions consisting of \verb|case| or \verb|let| |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
433 |
require care to maintain compositionality, to prevent loss of |
40126 | 434 |
logical indentation where it is especially important to see the |
435 |
structure of the text. Example: |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
436 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
437 |
\begin{verbatim} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
438 |
(* RIGHT *) |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
439 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
440 |
fun foo p1 = |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
441 |
(case e of |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
442 |
q1 => ... |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
443 |
| q2 => ...) |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
444 |
| foo p2 = |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
445 |
let |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
446 |
... |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
447 |
in |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
448 |
... |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
449 |
end |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
450 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
451 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
452 |
(* WRONG *) |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
453 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
454 |
fun foo p1 = case e of |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
455 |
q1 => ... |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
456 |
| q2 => ... |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
457 |
| foo p2 = |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
458 |
let |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
459 |
... |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
460 |
in |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
461 |
... |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
462 |
end |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
463 |
\end{verbatim} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
464 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
465 |
Extra parentheses around \verb|case| expressions are optional, |
40126 | 466 |
but help to analyse the nesting based on character matching in the |
467 |
editor. |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
468 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
469 |
\medskip There are two main exceptions to the overall principle of |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
470 |
compositionality in the layout of complex expressions. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
471 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
472 |
\begin{enumerate} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
473 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
474 |
\item \verb|if| expressions are iterated as if there would be |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
475 |
a multi-branch conditional in SML, e.g. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
476 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
477 |
\begin{verbatim} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
478 |
(* RIGHT *) |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
479 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
480 |
if b1 then e1 |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
481 |
else if b2 then e2 |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
482 |
else e3 |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
483 |
\end{verbatim} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
484 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
485 |
\item \verb|fn| abstractions are often layed-out as if they |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
486 |
would lack any structure by themselves. This traditional form is |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
487 |
motivated by the possibility to shift function arguments back and |
40126 | 488 |
forth wrt.\ additional combinators. Example: |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
489 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
490 |
\begin{verbatim} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
491 |
(* RIGHT *) |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
492 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
493 |
fun foo x y = fold (fn z => |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
494 |
expr) |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
495 |
\end{verbatim} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
496 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
497 |
Here the visual appearance is that of three arguments \verb|x|, |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
498 |
\verb|y|, \verb|z|. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
499 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
500 |
\end{enumerate} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
501 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
502 |
Such weakly structured layout should be use with great care. Here |
40153 | 503 |
are some counter-examples involving \verb|let| expressions: |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
504 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
505 |
\begin{verbatim} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
506 |
(* WRONG *) |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
507 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
508 |
fun foo x = let |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
509 |
val y = ... |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
510 |
in ... end |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
511 |
|
40153 | 512 |
fun foo x = let |
513 |
val y = ... |
|
514 |
in ... end |
|
515 |
||
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
516 |
fun foo x = |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
517 |
let |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
518 |
val y = ... |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
519 |
in ... end |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
520 |
\end{verbatim} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
521 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
522 |
\medskip In general the source layout is meant to emphasize the |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
523 |
structure of complex language expressions, not to pretend that SML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
524 |
had a completely different syntax (say that of Haskell or Java).% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
525 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
526 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
527 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
528 |
\isamarkupsection{SML embedded into Isabelle/Isar% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
529 |
} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
530 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
531 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
532 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
533 |
ML and Isar are intertwined via an open-ended bootstrap |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
534 |
process that provides more and more programming facilities and |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
535 |
logical content in an alternating manner. Bootstrapping starts from |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
536 |
the raw environment of existing implementations of Standard ML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
537 |
(mainly Poly/ML, but also SML/NJ). |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
538 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
539 |
Isabelle/Pure marks the point where the original ML toplevel is |
40126 | 540 |
superseded by the Isar toplevel that maintains a uniform context for |
541 |
arbitrary ML values (see also \secref{sec:context}). This formal |
|
542 |
environment holds ML compiler bindings, logical entities, and many |
|
543 |
other things. Raw SML is never encountered again after the initial |
|
544 |
bootstrap of Isabelle/Pure. |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
545 |
|
40126 | 546 |
Object-logics like Isabelle/HOL are built within the |
547 |
Isabelle/ML/Isar environment by introducing suitable theories with |
|
548 |
associated ML modules, either inlined or as separate files. Thus |
|
549 |
Isabelle/HOL is defined as a regular user-space application within |
|
550 |
the Isabelle framework. Further add-on tools can be implemented in |
|
551 |
ML within the Isar context in the same manner: ML is part of the |
|
552 |
standard repertoire of Isabelle, and there is no distinction between |
|
553 |
``user'' and ``developer'' in this respect.% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
554 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
555 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
556 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
557 |
\isamarkupsubsection{Isar ML commands% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
558 |
} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
559 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
560 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
561 |
\begin{isamarkuptext}% |
40126 | 562 |
The primary Isar source language provides facilities to ``open |
563 |
a window'' to the underlying ML compiler. Especially see the Isar |
|
564 |
commands \indexref{}{command}{use}\hyperlink{command.use}{\mbox{\isa{\isacommand{use}}}} and \indexref{}{command}{ML}\hyperlink{command.ML}{\mbox{\isa{\isacommand{ML}}}}: both work the |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
565 |
same way, only the source text is provided via a file vs.\ inlined, |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
566 |
respectively. Apart from embedding ML into the main theory |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
567 |
definition like that, there are many more commands that refer to ML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
568 |
source, such as \indexref{}{command}{setup}\hyperlink{command.setup}{\mbox{\isa{\isacommand{setup}}}} or \indexref{}{command}{declaration}\hyperlink{command.declaration}{\mbox{\isa{\isacommand{declaration}}}}. |
40126 | 569 |
Even more fine-grained embedding of ML into Isar is encountered in |
570 |
the proof method \indexref{}{method}{tactic}\hyperlink{method.tactic}{\mbox{\isa{tactic}}}, which refines the pending |
|
571 |
goal state via a given expression of type \verb|tactic|.% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
572 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
573 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
574 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
575 |
\isadelimmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
576 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
577 |
\endisadelimmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
578 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
579 |
\isatagmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
580 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
581 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
582 |
The following artificial example demonstrates some ML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
583 |
toplevel declarations within the implicit Isar theory context. This |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
584 |
is regular functional programming without referring to logical |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
585 |
entities yet.% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
586 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
587 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
588 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
589 |
\endisatagmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
590 |
{\isafoldmlex}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
591 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
592 |
\isadelimmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
593 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
594 |
\endisadelimmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
595 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
596 |
\isadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
597 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
598 |
\endisadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
599 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
600 |
\isatagML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
601 |
\isacommand{ML}\isamarkupfalse% |
40406 | 602 |
\ {\isaliteral{7B2A}{\isacharverbatimopen}}\isanewline |
603 |
\ \ fun\ factorial\ {\isadigit{0}}\ {\isaliteral{3D}{\isacharequal}}\ {\isadigit{1}}\isanewline |
|
604 |
\ \ \ \ {\isaliteral{7C}{\isacharbar}}\ factorial\ n\ {\isaliteral{3D}{\isacharequal}}\ n\ {\isaliteral{2A}{\isacharasterisk}}\ factorial\ {\isaliteral{28}{\isacharparenleft}}n\ {\isaliteral{2D}{\isacharminus}}\ {\isadigit{1}}{\isaliteral{29}{\isacharparenright}}\isanewline |
|
605 |
{\isaliteral{2A7D}{\isacharverbatimclose}}% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
606 |
\endisatagML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
607 |
{\isafoldML}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
608 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
609 |
\isadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
610 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
611 |
\endisadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
612 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
613 |
\begin{isamarkuptext}% |
40126 | 614 |
Here the ML environment is already managed by Isabelle, i.e.\ |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
615 |
the \verb|factorial| function is not yet accessible in the preceding |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
616 |
paragraph, nor in a different theory that is independent from the |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
617 |
current one in the import hierarchy. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
618 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
619 |
Removing the above ML declaration from the source text will remove |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
620 |
any trace of this definition as expected. The Isabelle/ML toplevel |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
621 |
environment is managed in a \emph{stateless} way: unlike the raw ML |
40126 | 622 |
toplevel there are no global side-effects involved |
623 |
here.\footnote{Such a stateless compilation environment is also a |
|
624 |
prerequisite for robust parallel compilation within independent |
|
625 |
nodes of the implicit theory development graph.} |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
626 |
|
40126 | 627 |
\medskip The next example shows how to embed ML into Isar proofs, using |
40406 | 628 |
\indexref{}{command}{ML\_prf}\hyperlink{command.ML-prf}{\mbox{\isa{\isacommand{ML{\isaliteral{5F}{\isacharunderscore}}prf}}}} instead of Instead of \indexref{}{command}{ML}\hyperlink{command.ML}{\mbox{\isa{\isacommand{ML}}}}. |
40126 | 629 |
As illustrated below, the effect on the ML environment is local to |
630 |
the whole proof body, ignoring the block structure.% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
631 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
632 |
\isamarkuptrue% |
40406 | 633 |
\isacommand{example{\isaliteral{5F}{\isacharunderscore}}proof}\isamarkupfalse% |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
634 |
\isanewline |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
635 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
636 |
\isadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
637 |
\ \ % |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
638 |
\endisadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
639 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
640 |
\isatagML |
40406 | 641 |
\isacommand{ML{\isaliteral{5F}{\isacharunderscore}}prf}\isamarkupfalse% |
642 |
\ {\isaliteral{7B2A}{\isacharverbatimopen}}\ val\ a\ {\isaliteral{3D}{\isacharequal}}\ {\isadigit{1}}\ {\isaliteral{2A7D}{\isacharverbatimclose}}\isanewline |
|
643 |
\ \ \isacommand{{\isaliteral{7B}{\isacharbraceleft}}}\isamarkupfalse% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
644 |
\isanewline |
40406 | 645 |
\ \ \ \ \isacommand{ML{\isaliteral{5F}{\isacharunderscore}}prf}\isamarkupfalse% |
646 |
\ {\isaliteral{7B2A}{\isacharverbatimopen}}\ val\ b\ {\isaliteral{3D}{\isacharequal}}\ a\ {\isaliteral{2B}{\isacharplus}}\ {\isadigit{1}}\ {\isaliteral{2A7D}{\isacharverbatimclose}}\isanewline |
|
647 |
\ \ \isacommand{{\isaliteral{7D}{\isacharbraceright}}}\isamarkupfalse% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
648 |
\ % |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
649 |
\isamarkupcmt{Isar block structure ignored by ML environment% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
650 |
} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
651 |
\isanewline |
40406 | 652 |
\ \ \isacommand{ML{\isaliteral{5F}{\isacharunderscore}}prf}\isamarkupfalse% |
653 |
\ {\isaliteral{7B2A}{\isacharverbatimopen}}\ val\ c\ {\isaliteral{3D}{\isacharequal}}\ b\ {\isaliteral{2B}{\isacharplus}}\ {\isadigit{1}}\ {\isaliteral{2A7D}{\isacharverbatimclose}}\isanewline |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
654 |
\isacommand{qed}\isamarkupfalse% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
655 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
656 |
\endisatagML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
657 |
{\isafoldML}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
658 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
659 |
\isadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
660 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
661 |
\endisadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
662 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
663 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
664 |
By side-stepping the normal scoping rules for Isar proof |
40126 | 665 |
blocks, embedded ML code can refer to the different contexts and |
666 |
manipulate corresponding entities, e.g.\ export a fact from a block |
|
667 |
context. |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
668 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
669 |
\medskip Two further ML commands are useful in certain situations: |
40406 | 670 |
\indexref{}{command}{ML\_val}\hyperlink{command.ML-val}{\mbox{\isa{\isacommand{ML{\isaliteral{5F}{\isacharunderscore}}val}}}} and \indexref{}{command}{ML\_command}\hyperlink{command.ML-command}{\mbox{\isa{\isacommand{ML{\isaliteral{5F}{\isacharunderscore}}command}}}} are |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
671 |
\emph{diagnostic} in the sense that there is no effect on the |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
672 |
underlying environment, and can thus used anywhere (even outside a |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
673 |
theory). The examples below produce long strings of digits by |
40406 | 674 |
invoking \verb|factorial|: \hyperlink{command.ML-val}{\mbox{\isa{\isacommand{ML{\isaliteral{5F}{\isacharunderscore}}val}}}} already takes care of |
675 |
printing the ML toplevel result, but \hyperlink{command.ML-command}{\mbox{\isa{\isacommand{ML{\isaliteral{5F}{\isacharunderscore}}command}}}} is silent |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
676 |
so we produce an explicit output message.% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
677 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
678 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
679 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
680 |
\isadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
681 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
682 |
\endisadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
683 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
684 |
\isatagML |
40406 | 685 |
\isacommand{ML{\isaliteral{5F}{\isacharunderscore}}val}\isamarkupfalse% |
686 |
\ {\isaliteral{7B2A}{\isacharverbatimopen}}\ factorial\ {\isadigit{1}}{\isadigit{0}}{\isadigit{0}}\ {\isaliteral{2A7D}{\isacharverbatimclose}}\isanewline |
|
687 |
\isacommand{ML{\isaliteral{5F}{\isacharunderscore}}command}\isamarkupfalse% |
|
688 |
\ {\isaliteral{7B2A}{\isacharverbatimopen}}\ writeln\ {\isaliteral{28}{\isacharparenleft}}string{\isaliteral{5F}{\isacharunderscore}}of{\isaliteral{5F}{\isacharunderscore}}int\ {\isaliteral{28}{\isacharparenleft}}factorial\ {\isadigit{1}}{\isadigit{0}}{\isadigit{0}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{2A7D}{\isacharverbatimclose}}% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
689 |
\endisatagML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
690 |
{\isafoldML}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
691 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
692 |
\isadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
693 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
694 |
\endisadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
695 |
\isanewline |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
696 |
\isanewline |
40406 | 697 |
\isacommand{example{\isaliteral{5F}{\isacharunderscore}}proof}\isamarkupfalse% |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
698 |
\isanewline |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
699 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
700 |
\isadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
701 |
\ \ % |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
702 |
\endisadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
703 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
704 |
\isatagML |
40406 | 705 |
\isacommand{ML{\isaliteral{5F}{\isacharunderscore}}val}\isamarkupfalse% |
706 |
\ {\isaliteral{7B2A}{\isacharverbatimopen}}\ factorial\ {\isadigit{1}}{\isadigit{0}}{\isadigit{0}}\ {\isaliteral{2A7D}{\isacharverbatimclose}}\ \ \isanewline |
|
707 |
\ \ \isacommand{ML{\isaliteral{5F}{\isacharunderscore}}command}\isamarkupfalse% |
|
708 |
\ {\isaliteral{7B2A}{\isacharverbatimopen}}\ writeln\ {\isaliteral{28}{\isacharparenleft}}string{\isaliteral{5F}{\isacharunderscore}}of{\isaliteral{5F}{\isacharunderscore}}int\ {\isaliteral{28}{\isacharparenleft}}factorial\ {\isadigit{1}}{\isadigit{0}}{\isadigit{0}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{2A7D}{\isacharverbatimclose}}% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
709 |
\endisatagML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
710 |
{\isafoldML}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
711 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
712 |
\isadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
713 |
\isanewline |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
714 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
715 |
\endisadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
716 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
717 |
\isadelimproof |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
718 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
719 |
\endisadelimproof |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
720 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
721 |
\isatagproof |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
722 |
\isacommand{qed}\isamarkupfalse% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
723 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
724 |
\endisatagproof |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
725 |
{\isafoldproof}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
726 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
727 |
\isadelimproof |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
728 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
729 |
\endisadelimproof |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
730 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
731 |
\isamarkupsubsection{Compile-time context% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
732 |
} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
733 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
734 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
735 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
736 |
Whenever the ML compiler is invoked within Isabelle/Isar, the |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
737 |
formal context is passed as a thread-local reference variable. Thus |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
738 |
ML code may access the theory context during compilation, by reading |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
739 |
or writing the (local) theory under construction. Note that such |
40126 | 740 |
direct access to the compile-time context is rare. In practice it |
741 |
is typically done via some derived ML functions instead.% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
742 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
743 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
744 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
745 |
\isadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
746 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
747 |
\endisadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
748 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
749 |
\isatagmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
750 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
751 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
752 |
\begin{mldecls} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
753 |
\indexdef{}{ML}{ML\_Context.the\_generic\_context}\verb|ML_Context.the_generic_context: unit -> Context.generic| \\ |
40126 | 754 |
\indexdef{}{ML}{Context.$>$$>$}\verb|Context.>> : (Context.generic -> Context.generic) -> unit| \\ |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
755 |
\indexdef{}{ML}{bind\_thms}\verb|bind_thms: string * thm list -> unit| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
756 |
\indexdef{}{ML}{bind\_thm}\verb|bind_thm: string * thm -> unit| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
757 |
\end{mldecls} |
21148 | 758 |
|
759 |
\begin{description} |
|
760 |
||
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
761 |
\item \verb|ML_Context.the_generic_context ()| refers to the theory |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
762 |
context of the ML toplevel --- at compile time. ML code needs to |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
763 |
take care to refer to \verb|ML_Context.the_generic_context ()| |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
764 |
correctly. Recall that evaluation of a function body is delayed |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
765 |
until actual run-time. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
766 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
767 |
\item \verb|Context.>>|~\isa{f} applies context transformation |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
768 |
\isa{f} to the implicit context of the ML toplevel. |
21148 | 769 |
|
40406 | 770 |
\item \verb|bind_thms|~\isa{{\isaliteral{28}{\isacharparenleft}}name{\isaliteral{2C}{\isacharcomma}}\ thms{\isaliteral{29}{\isacharparenright}}} stores a list of |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
771 |
theorems produced in ML both in the (global) theory context and the |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
772 |
ML toplevel, associating it with the provided name. Theorems are |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
773 |
put into a global ``standard'' format before being stored. |
21148 | 774 |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
775 |
\item \verb|bind_thm| is similar to \verb|bind_thms| but refers to a |
40126 | 776 |
singleton fact. |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
777 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
778 |
\end{description} |
21148 | 779 |
|
40126 | 780 |
It is important to note that the above functions are really |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
781 |
restricted to the compile time, even though the ML compiler is |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
782 |
invoked at run-time. The majority of ML code either uses static |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
783 |
antiquotations (\secref{sec:ML-antiq}) or refers to the theory or |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
784 |
proof context at run-time, by explicit functional abstraction.% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
785 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
786 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
787 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
788 |
\endisatagmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
789 |
{\isafoldmlref}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
790 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
791 |
\isadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
792 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
793 |
\endisadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
794 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
795 |
\isamarkupsubsection{Antiquotations \label{sec:ML-antiq}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
796 |
} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
797 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
798 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
799 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
800 |
A very important consequence of embedding SML into Isar is the |
40126 | 801 |
concept of \emph{ML antiquotation}. The standard token language of |
802 |
ML is augmented by special syntactic entities of the following form: |
|
21148 | 803 |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
804 |
\indexouternonterm{antiquote} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
805 |
\begin{rail} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
806 |
antiquote: atsign lbrace nameref args rbrace | lbracesym | rbracesym |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
807 |
; |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
808 |
\end{rail} |
21148 | 809 |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
810 |
Here \hyperlink{syntax.nameref}{\mbox{\isa{nameref}}} and \hyperlink{syntax.args}{\mbox{\isa{args}}} are regular outer syntax |
40126 | 811 |
categories \cite{isabelle-isar-ref}. Attributes and proof methods |
812 |
use similar syntax. |
|
21148 | 813 |
|
40406 | 814 |
\medskip A regular antiquotation \isa{{\isaliteral{40}{\isacharat}}{\isaliteral{7B}{\isacharbraceleft}}name\ args{\isaliteral{7D}{\isacharbraceright}}} processes |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
815 |
its arguments by the usual means of the Isar source language, and |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
816 |
produces corresponding ML source text, either as literal |
40406 | 817 |
\emph{inline} text (e.g. \isa{{\isaliteral{40}{\isacharat}}{\isaliteral{7B}{\isacharbraceleft}}term\ t{\isaliteral{7D}{\isacharbraceright}}}) or abstract |
818 |
\emph{value} (e.g. \isa{{\isaliteral{40}{\isacharat}}{\isaliteral{7B}{\isacharbraceleft}}thm\ th{\isaliteral{7D}{\isacharbraceright}}}). This pre-compilation |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
819 |
scheme allows to refer to formal entities in a robust manner, with |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
820 |
proper static scoping and with some degree of logical checking of |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
821 |
small portions of the code. |
21148 | 822 |
|
40406 | 823 |
Special antiquotations like \isa{{\isaliteral{40}{\isacharat}}{\isaliteral{7B}{\isacharbraceleft}}let\ {\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{7D}{\isacharbraceright}}} or \isa{{\isaliteral{40}{\isacharat}}{\isaliteral{7B}{\isacharbraceleft}}note\ {\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{7D}{\isacharbraceright}}} augment the compilation context without generating code. The |
824 |
non-ASCII braces \isa{{\isaliteral{5C3C6C62726163653E}{\isasymlbrace}}} and \isa{{\isaliteral{5C3C7262726163653E}{\isasymrbrace}}} allow to delimit the |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
825 |
effect by introducing local blocks within the pre-compilation |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
826 |
environment. |
21148 | 827 |
|
40126 | 828 |
\medskip See also \cite{Wenzel-Chaieb:2007b} for a broader |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
829 |
perspective on Isabelle/ML antiquotations.% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
830 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
831 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
832 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
833 |
\isadelimmlantiq |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
834 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
835 |
\endisadelimmlantiq |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
836 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
837 |
\isatagmlantiq |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
838 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
839 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
840 |
\begin{matharray}{rcl} |
40406 | 841 |
\indexdef{}{ML antiquotation}{let}\hypertarget{ML antiquotation.let}{\hyperlink{ML antiquotation.let}{\mbox{\isa{let}}}} & : & \isa{ML{\isaliteral{5F}{\isacharunderscore}}antiquotation} \\ |
842 |
\indexdef{}{ML antiquotation}{note}\hypertarget{ML antiquotation.note}{\hyperlink{ML antiquotation.note}{\mbox{\isa{note}}}} & : & \isa{ML{\isaliteral{5F}{\isacharunderscore}}antiquotation} \\ |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
843 |
\end{matharray} |
21148 | 844 |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
845 |
\begin{rail} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
846 |
'let' ((term + 'and') '=' term + 'and') |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
847 |
; |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
848 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
849 |
'note' (thmdef? thmrefs + 'and') |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
850 |
; |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
851 |
\end{rail} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
852 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
853 |
\begin{description} |
21148 | 854 |
|
40406 | 855 |
\item \isa{{\isaliteral{40}{\isacharat}}{\isaliteral{7B}{\isacharbraceleft}}let\ p\ {\isaliteral{3D}{\isacharequal}}\ t{\isaliteral{7D}{\isacharbraceright}}} binds schematic variables in the |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
856 |
pattern \isa{p} by higher-order matching against the term \isa{t}. This is analogous to the regular \indexref{}{command}{let}\hyperlink{command.let}{\mbox{\isa{\isacommand{let}}}} command |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
857 |
in the Isar proof language. The pre-compilation environment is |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
858 |
augmented by auxiliary term bindings, without emitting ML source. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
859 |
|
40406 | 860 |
\item \isa{{\isaliteral{40}{\isacharat}}{\isaliteral{7B}{\isacharbraceleft}}note\ a\ {\isaliteral{3D}{\isacharequal}}\ b\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ b\isaliteral{5C3C5E7375623E}{}\isactrlsub n{\isaliteral{7D}{\isacharbraceright}}} recalls existing facts \isa{b\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{2C}{\isacharcomma}}\ b\isaliteral{5C3C5E7375623E}{}\isactrlsub n}, binding the result as \isa{a}. This is analogous to |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
861 |
the regular \indexref{}{command}{note}\hyperlink{command.note}{\mbox{\isa{\isacommand{note}}}} command in the Isar proof language. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
862 |
The pre-compilation environment is augmented by auxiliary fact |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
863 |
bindings, without emitting ML source. |
21148 | 864 |
|
865 |
\end{description}% |
|
18543 | 866 |
\end{isamarkuptext}% |
867 |
\isamarkuptrue% |
|
868 |
% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
869 |
\endisatagmlantiq |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
870 |
{\isafoldmlantiq}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
871 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
872 |
\isadelimmlantiq |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
873 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
874 |
\endisadelimmlantiq |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
875 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
876 |
\isadelimmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
877 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
878 |
\endisadelimmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
879 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
880 |
\isatagmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
881 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
882 |
\begin{isamarkuptext}% |
40126 | 883 |
The following artificial example gives some impression |
884 |
about the antiquotation elements introduced so far, together with |
|
40406 | 885 |
the important \isa{{\isaliteral{40}{\isacharat}}{\isaliteral{7B}{\isacharbraceleft}}thm{\isaliteral{7D}{\isacharbraceright}}} antiquotation defined later.% |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
886 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
887 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
888 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
889 |
\endisatagmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
890 |
{\isafoldmlex}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
891 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
892 |
\isadelimmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
893 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
894 |
\endisadelimmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
895 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
896 |
\isadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
897 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
898 |
\endisadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
899 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
900 |
\isatagML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
901 |
\isacommand{ML}\isamarkupfalse% |
40406 | 902 |
\ {\isaliteral{7B2A}{\isacharverbatimopen}}\isanewline |
903 |
\ \ {\isaliteral{5C3C6C62726163653E}{\isaantiqopen}}\isanewline |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
904 |
\ \ \ \ % |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
905 |
\isaantiq |
40406 | 906 |
let\ {\isaliteral{3F}{\isacharquery}}t\ {\isaliteral{3D}{\isacharequal}}\ my{\isaliteral{5F}{\isacharunderscore}}term{}% |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
907 |
\endisaantiq |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
908 |
\isanewline |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
909 |
\ \ \ \ % |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
910 |
\isaantiq |
40406 | 911 |
note\ my{\isaliteral{5F}{\isacharunderscore}}refl\ {\isaliteral{3D}{\isacharequal}}\ reflexive\ {\isaliteral{5B}{\isacharbrackleft}}of\ {\isaliteral{3F}{\isacharquery}}t{\isaliteral{5D}{\isacharbrackright}}{}% |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
912 |
\endisaantiq |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
913 |
\isanewline |
40406 | 914 |
\ \ \ \ fun\ foo\ th\ {\isaliteral{3D}{\isacharequal}}\ Thm{\isaliteral{2E}{\isachardot}}transitive\ th\ % |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
915 |
\isaantiq |
40406 | 916 |
thm\ my{\isaliteral{5F}{\isacharunderscore}}refl{}% |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
917 |
\endisaantiq |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
918 |
\isanewline |
40406 | 919 |
\ \ {\isaliteral{5C3C7262726163653E}{\isaantiqclose}}\isanewline |
920 |
{\isaliteral{2A7D}{\isacharverbatimclose}}% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
921 |
\endisatagML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
922 |
{\isafoldML}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
923 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
924 |
\isadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
925 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
926 |
\endisadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
927 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
928 |
\begin{isamarkuptext}% |
40126 | 929 |
The extra block delimiters do not affect the compiled code |
930 |
itself, i.e.\ function \verb|foo| is available in the present context |
|
931 |
of this paragraph.% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
932 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
933 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
934 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
935 |
\isamarkupsection{Canonical argument order \label{sec:canonical-argument-order}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
936 |
} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
937 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
938 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
939 |
\begin{isamarkuptext}% |
40406 | 940 |
Standard ML is a language in the tradition of \isa{{\isaliteral{5C3C6C616D6264613E}{\isasymlambda}}}-calculus and \emph{higher-order functional programming}, |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
941 |
similar to OCaml, Haskell, or Isabelle/Pure and HOL as logical |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
942 |
languages. Getting acquainted with the native style of representing |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
943 |
functions in that setting can save a lot of extra boiler-plate of |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
944 |
redundant shuffling of arguments, auxiliary abstractions etc. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
945 |
|
40126 | 946 |
Functions are usually \emph{curried}: the idea of turning arguments |
40406 | 947 |
of type \isa{{\isaliteral{5C3C7461753E}{\isasymtau}}\isaliteral{5C3C5E7375623E}{}\isactrlsub i} (for \isa{i\ {\isaliteral{5C3C696E3E}{\isasymin}}\ {\isaliteral{7B}{\isacharbraceleft}}{\isadigit{1}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ n{\isaliteral{7D}{\isacharbraceright}}}) into a result of |
948 |
type \isa{{\isaliteral{5C3C7461753E}{\isasymtau}}} is represented by the iterated function space |
|
949 |
\isa{{\isaliteral{5C3C7461753E}{\isasymtau}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ {\isaliteral{5C3C7461753E}{\isasymtau}}\isaliteral{5C3C5E7375623E}{}\isactrlsub n\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ {\isaliteral{5C3C7461753E}{\isasymtau}}}. This is isomorphic to the well-known |
|
950 |
encoding via tuples \isa{{\isaliteral{5C3C7461753E}{\isasymtau}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}\ {\isaliteral{5C3C74696D65733E}{\isasymtimes}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{5C3C74696D65733E}{\isasymtimes}}\ {\isaliteral{5C3C7461753E}{\isasymtau}}\isaliteral{5C3C5E7375623E}{}\isactrlsub n\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ {\isaliteral{5C3C7461753E}{\isasymtau}}}, but the curried |
|
40126 | 951 |
version fits more smoothly into the basic calculus.\footnote{The |
952 |
difference is even more significant in higher-order logic, because |
|
953 |
the redundant tuple structure needs to be accommodated by formal |
|
954 |
reasoning.} |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
955 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
956 |
Currying gives some flexiblity due to \emph{partial application}. A |
40406 | 957 |
function \isa{f{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C7461753E}{\isasymtau}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ {\isaliteral{5C3C7461753E}{\isasymtau}}\isaliteral{5C3C5E627375623E}{}\isactrlbsub {\isadigit{2}}\isaliteral{5C3C5E657375623E}{}\isactrlesub \ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ {\isaliteral{5C3C7461753E}{\isasymtau}}} can be applied to \isa{x{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C7461753E}{\isasymtau}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}} |
958 |
and the remaining \isa{{\isaliteral{28}{\isacharparenleft}}f\ x{\isaliteral{29}{\isacharparenright}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C7461753E}{\isasymtau}}\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{2}}\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ {\isaliteral{5C3C7461753E}{\isasymtau}}} passed to another function |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
959 |
etc. How well this works in practice depends on the order of |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
960 |
arguments. In the worst case, arguments are arranged erratically, |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
961 |
and using a function in a certain situation always requires some |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
962 |
glue code. Thus we would get exponentially many oppurtunities to |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
963 |
decorate the code with meaningless permutations of arguments. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
964 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
965 |
This can be avoided by \emph{canonical argument order}, which |
40126 | 966 |
observes certain standard patterns and minimizes adhoc permutations |
40229 | 967 |
in their application. In Isabelle/ML, large portions of text can be |
40406 | 968 |
written without ever using \isa{swap{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C616C7068613E}{\isasymalpha}}\ {\isaliteral{5C3C74696D65733E}{\isasymtimes}}\ {\isaliteral{5C3C626574613E}{\isasymbeta}}\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ {\isaliteral{5C3C626574613E}{\isasymbeta}}\ {\isaliteral{5C3C74696D65733E}{\isasymtimes}}\ {\isaliteral{5C3C616C7068613E}{\isasymalpha}}}, or the |
969 |
combinator \isa{C{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{5C3C616C7068613E}{\isasymalpha}}\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ {\isaliteral{5C3C626574613E}{\isasymbeta}}\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ {\isaliteral{5C3C67616D6D613E}{\isasymgamma}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{5C3C626574613E}{\isasymbeta}}\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ {\isaliteral{5C3C616C7068613E}{\isasymalpha}}\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ {\isaliteral{5C3C67616D6D613E}{\isasymgamma}}{\isaliteral{29}{\isacharparenright}}} that is not even |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
970 |
defined in our library. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
971 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
972 |
\medskip The basic idea is that arguments that vary less are moved |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
973 |
further to the left than those that vary more. Two particularly |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
974 |
important categories of functions are \emph{selectors} and |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
975 |
\emph{updates}. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
976 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
977 |
The subsequent scheme is based on a hypothetical set-like container |
40406 | 978 |
of type \isa{{\isaliteral{5C3C626574613E}{\isasymbeta}}} that manages elements of type \isa{{\isaliteral{5C3C616C7068613E}{\isasymalpha}}}. Both |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
979 |
the names and types of the associated operations are canonical for |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
980 |
Isabelle/ML. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
981 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
982 |
\medskip |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
983 |
\begin{tabular}{ll} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
984 |
kind & canonical name and type \\\hline |
40406 | 985 |
selector & \isa{member{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C626574613E}{\isasymbeta}}\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ {\isaliteral{5C3C616C7068613E}{\isasymalpha}}\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ bool} \\ |
986 |
update & \isa{insert{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C616C7068613E}{\isasymalpha}}\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ {\isaliteral{5C3C626574613E}{\isasymbeta}}\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ {\isaliteral{5C3C626574613E}{\isasymbeta}}} \\ |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
987 |
\end{tabular} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
988 |
\medskip |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
989 |
|
40406 | 990 |
Given a container \isa{B{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C626574613E}{\isasymbeta}}}, the partially applied \isa{member\ B} is a predicate over elements \isa{{\isaliteral{5C3C616C7068613E}{\isasymalpha}}\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ bool}, and |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
991 |
thus represents the intended denotation directly. It is customary |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
992 |
to pass the abstract predicate to further operations, not the |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
993 |
concrete container. The argument order makes it easy to use other |
40406 | 994 |
combinators: \isa{forall\ {\isaliteral{28}{\isacharparenleft}}member\ B{\isaliteral{29}{\isacharparenright}}\ list} will check a list of |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
995 |
elements for membership in \isa{B} etc. Often the explicit |
40406 | 996 |
\isa{list} is pointless and can be contracted to \isa{forall\ {\isaliteral{28}{\isacharparenleft}}member\ B{\isaliteral{29}{\isacharparenright}}} to get directly a predicate again. |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
997 |
|
40126 | 998 |
In contrast, an update operation varies the container, so it moves |
40406 | 999 |
to the right: \isa{insert\ a} is a function \isa{{\isaliteral{5C3C626574613E}{\isasymbeta}}\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ {\isaliteral{5C3C626574613E}{\isasymbeta}}} to |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1000 |
insert a value \isa{a}. These can be composed naturally as |
40406 | 1001 |
\isa{insert\ c\ {\isaliteral{5C3C636972633E}{\isasymcirc}}\ insert\ b\ {\isaliteral{5C3C636972633E}{\isasymcirc}}\ insert\ a}. The slightly awkward |
40229 | 1002 |
inversion of the composition order is due to conventional |
40126 | 1003 |
mathematical notation, which can be easily amended as explained |
1004 |
below.% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1005 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1006 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1007 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1008 |
\isamarkupsubsection{Forward application and composition% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1009 |
} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1010 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1011 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1012 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1013 |
Regular function application and infix notation works best for |
40406 | 1014 |
relatively deeply structured expressions, e.g.\ \isa{h\ {\isaliteral{28}{\isacharparenleft}}f\ x\ y\ {\isaliteral{2B}{\isacharplus}}\ g\ z{\isaliteral{29}{\isacharparenright}}}. The important special case of \emph{linear transformation} |
1015 |
applies a cascade of functions \isa{f\isaliteral{5C3C5E7375623E}{}\isactrlsub n\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{28}{\isacharparenleft}}f\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}\ x{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}}. This |
|
40126 | 1016 |
becomes hard to read and maintain if the functions are themselves |
1017 |
given as complex expressions. The notation can be significantly |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1018 |
improved by introducing \emph{forward} versions of application and |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1019 |
composition as follows: |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1020 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1021 |
\medskip |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1022 |
\begin{tabular}{lll} |
40406 | 1023 |
\isa{x\ {\isaliteral{7C}{\isacharbar}}{\isaliteral{3E}{\isachargreater}}\ f} & \isa{{\isaliteral{5C3C65717569763E}{\isasymequiv}}} & \isa{f\ x} \\ |
1024 |
\isa{f\ {\isaliteral{23}{\isacharhash}}{\isaliteral{3E}{\isachargreater}}\ g} & \isa{{\isaliteral{5C3C65717569763E}{\isasymequiv}}} & \isa{x\ {\isaliteral{7C}{\isacharbar}}{\isaliteral{3E}{\isachargreater}}\ f\ {\isaliteral{7C}{\isacharbar}}{\isaliteral{3E}{\isachargreater}}\ g} \\ |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1025 |
\end{tabular} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1026 |
\medskip |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1027 |
|
40406 | 1028 |
This enables to write conveniently \isa{x\ {\isaliteral{7C}{\isacharbar}}{\isaliteral{3E}{\isachargreater}}\ f\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}\ {\isaliteral{7C}{\isacharbar}}{\isaliteral{3E}{\isachargreater}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{7C}{\isacharbar}}{\isaliteral{3E}{\isachargreater}}\ f\isaliteral{5C3C5E7375623E}{}\isactrlsub n} or |
1029 |
\isa{f\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}\ {\isaliteral{23}{\isacharhash}}{\isaliteral{3E}{\isachargreater}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{23}{\isacharhash}}{\isaliteral{3E}{\isachargreater}}\ f\isaliteral{5C3C5E7375623E}{}\isactrlsub n} for its functional abstraction over \isa{x}. |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1030 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1031 |
\medskip There is an additional set of combinators to accommodate |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1032 |
multiple results (via pairs) that are passed on as multiple |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1033 |
arguments (via currying). |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1034 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1035 |
\medskip |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1036 |
\begin{tabular}{lll} |
40406 | 1037 |
\isa{{\isaliteral{28}{\isacharparenleft}}x{\isaliteral{2C}{\isacharcomma}}\ y{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{7C}{\isacharbar}}{\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ f} & \isa{{\isaliteral{5C3C65717569763E}{\isasymequiv}}} & \isa{f\ x\ y} \\ |
1038 |
\isa{f\ {\isaliteral{23}{\isacharhash}}{\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ g} & \isa{{\isaliteral{5C3C65717569763E}{\isasymequiv}}} & \isa{x\ {\isaliteral{7C}{\isacharbar}}{\isaliteral{3E}{\isachargreater}}\ f\ {\isaliteral{7C}{\isacharbar}}{\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ g} \\ |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1039 |
\end{tabular} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1040 |
\medskip% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1041 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1042 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1043 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1044 |
\isadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1045 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1046 |
\endisadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1047 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1048 |
\isatagmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1049 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1050 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1051 |
\begin{mldecls} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1052 |
\indexdef{}{ML}{$\mid$$>$}\verb|op |\verb,|,\verb|> : 'a * ('a -> 'b) -> 'b| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1053 |
\indexdef{}{ML}{$\mid$-$>$}\verb|op |\verb,|,\verb|-> : ('c * 'a) * ('c -> 'a -> 'b) -> 'b| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1054 |
\indexdef{}{ML}{\#$>$}\verb|op #> : ('a -> 'b) * ('b -> 'c) -> 'a -> 'c| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1055 |
\indexdef{}{ML}{\#-$>$}\verb|op #-> : ('a -> 'c * 'b) * ('c -> 'b -> 'd) -> 'a -> 'd| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1056 |
\end{mldecls} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1057 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1058 |
%FIXME description!?% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1059 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1060 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1061 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1062 |
\endisatagmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1063 |
{\isafoldmlref}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1064 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1065 |
\isadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1066 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1067 |
\endisadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1068 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1069 |
\isamarkupsubsection{Canonical iteration% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1070 |
} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1071 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1072 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1073 |
\begin{isamarkuptext}% |
40406 | 1074 |
As explained above, a function \isa{f{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C616C7068613E}{\isasymalpha}}\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ {\isaliteral{5C3C626574613E}{\isasymbeta}}\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ {\isaliteral{5C3C626574613E}{\isasymbeta}}} can be |
1075 |
understood as update on a configuration of type \isa{{\isaliteral{5C3C626574613E}{\isasymbeta}}}, |
|
1076 |
parametrized by arguments of type \isa{{\isaliteral{5C3C616C7068613E}{\isasymalpha}}}. Given \isa{a{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C616C7068613E}{\isasymalpha}}} |
|
1077 |
the partial application \isa{{\isaliteral{28}{\isacharparenleft}}f\ a{\isaliteral{29}{\isacharparenright}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C626574613E}{\isasymbeta}}\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ {\isaliteral{5C3C626574613E}{\isasymbeta}}} operates |
|
1078 |
homogeneously on \isa{{\isaliteral{5C3C626574613E}{\isasymbeta}}}. This can be iterated naturally over a |
|
1079 |
list of parameters \isa{{\isaliteral{5B}{\isacharbrackleft}}a\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{2C}{\isacharcomma}}\ a\isaliteral{5C3C5E7375623E}{}\isactrlsub n{\isaliteral{5D}{\isacharbrackright}}} as \isa{f\ a\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}\ {\isaliteral{23}{\isacharhash}}{\isaliteral{3E}{\isachargreater}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ {\isaliteral{23}{\isacharhash}}{\isaliteral{3E}{\isachargreater}}\ f\ a\isaliteral{5C3C5E627375623E}{}\isactrlbsub n\isaliteral{5C3C5E657375623E}{}\isactrlesub \isaliteral{5C3C5E627375623E}{}\isactrlbsub \isaliteral{5C3C5E657375623E}{}\isactrlesub }. The latter expression is again a function \isa{{\isaliteral{5C3C626574613E}{\isasymbeta}}\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ {\isaliteral{5C3C626574613E}{\isasymbeta}}}. |
|
1080 |
It can be applied to an initial configuration \isa{b{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C626574613E}{\isasymbeta}}} to |
|
1081 |
start the iteration over the given list of arguments: each \isa{a} in \isa{a\isaliteral{5C3C5E7375623E}{}\isactrlsub {\isadigit{1}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}{\isaliteral{2C}{\isacharcomma}}\ a\isaliteral{5C3C5E7375623E}{}\isactrlsub n} is applied consecutively by updating a |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1082 |
cumulative configuration. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1083 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1084 |
The \isa{fold} combinator in Isabelle/ML lifts a function \isa{f} as above to its iterated version over a list of arguments. |
40406 | 1085 |
Lifting can be repeated, e.g.\ \isa{{\isaliteral{28}{\isacharparenleft}}fold\ {\isaliteral{5C3C636972633E}{\isasymcirc}}\ fold{\isaliteral{29}{\isacharparenright}}\ f} iterates |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1086 |
over a list of lists as expected. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1087 |
|
40406 | 1088 |
The variant \isa{fold{\isaliteral{5F}{\isacharunderscore}}rev} works inside-out over the list of |
1089 |
arguments, such that \isa{fold{\isaliteral{5F}{\isacharunderscore}}rev\ f\ {\isaliteral{5C3C65717569763E}{\isasymequiv}}\ fold\ f\ {\isaliteral{5C3C636972633E}{\isasymcirc}}\ rev} holds. |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1090 |
|
40406 | 1091 |
The \isa{fold{\isaliteral{5F}{\isacharunderscore}}map} combinator essentially performs \isa{fold} and \isa{map} simultaneously: each application of \isa{f} produces an updated configuration together with a side-result; |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1092 |
the iteration collects all such side-results as a separate list.% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1093 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1094 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1095 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1096 |
\isadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1097 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1098 |
\endisadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1099 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1100 |
\isatagmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1101 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1102 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1103 |
\begin{mldecls} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1104 |
\indexdef{}{ML}{fold}\verb|fold: ('a -> 'b -> 'b) -> 'a list -> 'b -> 'b| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1105 |
\indexdef{}{ML}{fold\_rev}\verb|fold_rev: ('a -> 'b -> 'b) -> 'a list -> 'b -> 'b| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1106 |
\indexdef{}{ML}{fold\_map}\verb|fold_map: ('a -> 'b -> 'c * 'b) -> 'a list -> 'b -> 'c list * 'b| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1107 |
\end{mldecls} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1108 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1109 |
\begin{description} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1110 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1111 |
\item \verb|fold|~\isa{f} lifts the parametrized update function |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1112 |
\isa{f} to a list of parameters. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1113 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1114 |
\item \verb|fold_rev|~\isa{f} is similar to \verb|fold|~\isa{f}, but works inside-out. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1115 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1116 |
\item \verb|fold_map|~\isa{f} lifts the parametrized update |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1117 |
function \isa{f} (with side-result) to a list of parameters and |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1118 |
cumulative side-results. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1119 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1120 |
\end{description} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1121 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1122 |
\begin{warn} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1123 |
The literature on functional programming provides a multitude of |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1124 |
combinators called \isa{foldl}, \isa{foldr} etc. SML97 |
40126 | 1125 |
provides its own variations as \verb|List.foldl| and \verb|List.foldr|, while the classic Isabelle library also has the |
1126 |
historic \verb|Library.foldl| and \verb|Library.foldr|. To avoid |
|
1127 |
further confusion, all of this should be ignored, and \verb|fold| (or |
|
1128 |
\verb|fold_rev|) used exclusively. |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1129 |
\end{warn}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1130 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1131 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1132 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1133 |
\endisatagmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1134 |
{\isafoldmlref}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1135 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1136 |
\isadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1137 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1138 |
\endisadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1139 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1140 |
\isadelimmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1141 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1142 |
\endisadelimmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1143 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1144 |
\isatagmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1145 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1146 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1147 |
The following example shows how to fill a text buffer |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1148 |
incrementally by adding strings, either individually or from a given |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1149 |
list.% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1150 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1151 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1152 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1153 |
\endisatagmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1154 |
{\isafoldmlex}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1155 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1156 |
\isadelimmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1157 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1158 |
\endisadelimmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1159 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1160 |
\isadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1161 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1162 |
\endisadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1163 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1164 |
\isatagML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1165 |
\isacommand{ML}\isamarkupfalse% |
40406 | 1166 |
\ {\isaliteral{7B2A}{\isacharverbatimopen}}\isanewline |
1167 |
\ \ val\ s\ {\isaliteral{3D}{\isacharequal}}\isanewline |
|
1168 |
\ \ \ \ Buffer{\isaliteral{2E}{\isachardot}}empty\isanewline |
|
1169 |
\ \ \ \ {\isaliteral{7C}{\isacharbar}}{\isaliteral{3E}{\isachargreater}}\ Buffer{\isaliteral{2E}{\isachardot}}add\ {\isaliteral{22}{\isachardoublequote}}digits{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequote}}\isanewline |
|
1170 |
\ \ \ \ {\isaliteral{7C}{\isacharbar}}{\isaliteral{3E}{\isachargreater}}\ fold\ {\isaliteral{28}{\isacharparenleft}}Buffer{\isaliteral{2E}{\isachardot}}add\ o\ string{\isaliteral{5F}{\isacharunderscore}}of{\isaliteral{5F}{\isacharunderscore}}int{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{28}{\isacharparenleft}}{\isadigit{0}}\ upto\ {\isadigit{9}}{\isaliteral{29}{\isacharparenright}}\isanewline |
|
1171 |
\ \ \ \ {\isaliteral{7C}{\isacharbar}}{\isaliteral{3E}{\isachargreater}}\ Buffer{\isaliteral{2E}{\isachardot}}content{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1172 |
\isanewline |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1173 |
\ \ % |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1174 |
\isaantiq |
40406 | 1175 |
assert{}% |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1176 |
\endisaantiq |
40406 | 1177 |
\ {\isaliteral{28}{\isacharparenleft}}s\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{22}{\isachardoublequote}}digits{\isaliteral{3A}{\isacharcolon}}\ {\isadigit{0}}{\isadigit{1}}{\isadigit{2}}{\isadigit{3}}{\isadigit{4}}{\isadigit{5}}{\isadigit{6}}{\isadigit{7}}{\isadigit{8}}{\isadigit{9}}{\isaliteral{22}{\isachardoublequote}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
1178 |
{\isaliteral{2A7D}{\isacharverbatimclose}}% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1179 |
\endisatagML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1180 |
{\isafoldML}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1181 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1182 |
\isadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1183 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1184 |
\endisadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1185 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1186 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1187 |
Note how \verb|fold (Buffer.add o string_of_int)| above saves |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1188 |
an extra \verb|map| over the given list. This kind of peephole |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1189 |
optimization reduces both the code size and the tree structures in |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1190 |
memory (``deforestation''), but requires some practice to read and |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1191 |
write it fluently. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1192 |
|
40126 | 1193 |
\medskip The next example elaborates the idea of canonical |
1194 |
iteration, demonstrating fast accumulation of tree content using a |
|
1195 |
text buffer.% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1196 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1197 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1198 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1199 |
\isadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1200 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1201 |
\endisadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1202 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1203 |
\isatagML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1204 |
\isacommand{ML}\isamarkupfalse% |
40406 | 1205 |
\ {\isaliteral{7B2A}{\isacharverbatimopen}}\isanewline |
1206 |
\ \ datatype\ tree\ {\isaliteral{3D}{\isacharequal}}\ Text\ of\ string\ {\isaliteral{7C}{\isacharbar}}\ Elem\ of\ string\ {\isaliteral{2A}{\isacharasterisk}}\ tree\ list{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1207 |
\isanewline |
40406 | 1208 |
\ \ fun\ slow{\isaliteral{5F}{\isacharunderscore}}content\ {\isaliteral{28}{\isacharparenleft}}Text\ txt{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ txt\isanewline |
1209 |
\ \ \ \ {\isaliteral{7C}{\isacharbar}}\ slow{\isaliteral{5F}{\isacharunderscore}}content\ {\isaliteral{28}{\isacharparenleft}}Elem\ {\isaliteral{28}{\isacharparenleft}}name{\isaliteral{2C}{\isacharcomma}}\ ts{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\isanewline |
|
1210 |
\ \ \ \ \ \ \ \ {\isaliteral{22}{\isachardoublequote}}{\isaliteral{3C}{\isacharless}}{\isaliteral{22}{\isachardoublequote}}\ {\isaliteral{5E}{\isacharcircum}}\ name\ {\isaliteral{5E}{\isacharcircum}}\ {\isaliteral{22}{\isachardoublequote}}{\isaliteral{3E}{\isachargreater}}{\isaliteral{22}{\isachardoublequote}}\ {\isaliteral{5E}{\isacharcircum}}\isanewline |
|
1211 |
\ \ \ \ \ \ \ \ implode\ {\isaliteral{28}{\isacharparenleft}}map\ slow{\isaliteral{5F}{\isacharunderscore}}content\ ts{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5E}{\isacharcircum}}\isanewline |
|
1212 |
\ \ \ \ \ \ \ \ {\isaliteral{22}{\isachardoublequote}}{\isaliteral{3C}{\isacharless}}{\isaliteral{2F}{\isacharslash}}{\isaliteral{22}{\isachardoublequote}}\ {\isaliteral{5E}{\isacharcircum}}\ name\ {\isaliteral{5E}{\isacharcircum}}\ {\isaliteral{22}{\isachardoublequote}}{\isaliteral{3E}{\isachargreater}}{\isaliteral{22}{\isachardoublequote}}\isanewline |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1213 |
\isanewline |
40406 | 1214 |
\ \ fun\ add{\isaliteral{5F}{\isacharunderscore}}content\ {\isaliteral{28}{\isacharparenleft}}Text\ txt{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ Buffer{\isaliteral{2E}{\isachardot}}add\ txt\isanewline |
1215 |
\ \ \ \ {\isaliteral{7C}{\isacharbar}}\ add{\isaliteral{5F}{\isacharunderscore}}content\ {\isaliteral{28}{\isacharparenleft}}Elem\ {\isaliteral{28}{\isacharparenleft}}name{\isaliteral{2C}{\isacharcomma}}\ ts{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\isanewline |
|
1216 |
\ \ \ \ \ \ \ \ Buffer{\isaliteral{2E}{\isachardot}}add\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{22}{\isachardoublequote}}{\isaliteral{3C}{\isacharless}}{\isaliteral{22}{\isachardoublequote}}\ {\isaliteral{5E}{\isacharcircum}}\ name\ {\isaliteral{5E}{\isacharcircum}}\ {\isaliteral{22}{\isachardoublequote}}{\isaliteral{3E}{\isachargreater}}{\isaliteral{22}{\isachardoublequote}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{23}{\isacharhash}}{\isaliteral{3E}{\isachargreater}}\isanewline |
|
1217 |
\ \ \ \ \ \ \ \ fold\ add{\isaliteral{5F}{\isacharunderscore}}content\ ts\ {\isaliteral{23}{\isacharhash}}{\isaliteral{3E}{\isachargreater}}\isanewline |
|
1218 |
\ \ \ \ \ \ \ \ Buffer{\isaliteral{2E}{\isachardot}}add\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{22}{\isachardoublequote}}{\isaliteral{3C}{\isacharless}}{\isaliteral{2F}{\isacharslash}}{\isaliteral{22}{\isachardoublequote}}\ {\isaliteral{5E}{\isacharcircum}}\ name\ {\isaliteral{5E}{\isacharcircum}}\ {\isaliteral{22}{\isachardoublequote}}{\isaliteral{3E}{\isachargreater}}{\isaliteral{22}{\isachardoublequote}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1219 |
\isanewline |
40406 | 1220 |
\ \ fun\ fast{\isaliteral{5F}{\isacharunderscore}}content\ tree\ {\isaliteral{3D}{\isacharequal}}\isanewline |
1221 |
\ \ \ \ Buffer{\isaliteral{2E}{\isachardot}}empty\ {\isaliteral{7C}{\isacharbar}}{\isaliteral{3E}{\isachargreater}}\ add{\isaliteral{5F}{\isacharunderscore}}content\ tree\ {\isaliteral{7C}{\isacharbar}}{\isaliteral{3E}{\isachargreater}}\ Buffer{\isaliteral{2E}{\isachardot}}content{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
|
1222 |
{\isaliteral{2A7D}{\isacharverbatimclose}}% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1223 |
\endisatagML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1224 |
{\isafoldML}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1225 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1226 |
\isadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1227 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1228 |
\endisadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1229 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1230 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1231 |
The slow part of \verb|slow_content| is the \verb|implode| of |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1232 |
the recursive results, because it copies previously produced strings |
40126 | 1233 |
again. |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1234 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1235 |
The incremental \verb|add_content| avoids this by operating on a |
40126 | 1236 |
buffer that is passed through in a linear fashion. Using \verb|#>| and contraction over the actual buffer argument saves some |
1237 |
additional boiler-plate. Of course, the two \verb|Buffer.add| |
|
1238 |
invocations with concatenated strings could have been split into |
|
1239 |
smaller parts, but this would have obfuscated the source without |
|
1240 |
making a big difference in allocations. Here we have done some |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1241 |
peephole-optimization for the sake of readability. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1242 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1243 |
Another benefit of \verb|add_content| is its ``open'' form as a |
40126 | 1244 |
function on buffers that can be continued in further linear |
1245 |
transformations, folding etc. Thus it is more compositional than |
|
1246 |
the naive \verb|slow_content|. As realistic example, compare the |
|
1247 |
old-style \verb|Term.maxidx_of_term: term -> int| with the newer |
|
1248 |
\verb|Term.maxidx_term: term -> int -> int| in Isabelle/Pure. |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1249 |
|
40126 | 1250 |
Note that \verb|fast_content| above is only defined as example. In |
1251 |
many practical situations, it is customary to provide the |
|
1252 |
incremental \verb|add_content| only and leave the initialization and |
|
1253 |
termination to the concrete application by the user.% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1254 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1255 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1256 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1257 |
\isamarkupsection{Message output channels \label{sec:message-channels}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1258 |
} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1259 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1260 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1261 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1262 |
Isabelle provides output channels for different kinds of |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1263 |
messages: regular output, high-volume tracing information, warnings, |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1264 |
and errors. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1265 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1266 |
Depending on the user interface involved, these messages may appear |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1267 |
in different text styles or colours. The standard output for |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1268 |
terminal sessions prefixes each line of warnings by \verb|###| and errors by \verb|***|, but leaves anything else |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1269 |
unchanged. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1270 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1271 |
Messages are associated with the transaction context of the running |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1272 |
Isar command. This enables the front-end to manage commands and |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1273 |
resulting messages together. For example, after deleting a command |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1274 |
from a given theory document version, the corresponding message |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1275 |
output can be retracted from the display.% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1276 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1277 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1278 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1279 |
\isadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1280 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1281 |
\endisadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1282 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1283 |
\isatagmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1284 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1285 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1286 |
\begin{mldecls} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1287 |
\indexdef{}{ML}{writeln}\verb|writeln: string -> unit| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1288 |
\indexdef{}{ML}{tracing}\verb|tracing: string -> unit| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1289 |
\indexdef{}{ML}{warning}\verb|warning: string -> unit| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1290 |
\indexdef{}{ML}{error}\verb|error: string -> 'a| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1291 |
\end{mldecls} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1292 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1293 |
\begin{description} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1294 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1295 |
\item \verb|writeln|~\isa{text} outputs \isa{text} as regular |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1296 |
message. This is the primary message output operation of Isabelle |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1297 |
and should be used by default. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1298 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1299 |
\item \verb|tracing|~\isa{text} outputs \isa{text} as special |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1300 |
tracing message, indicating potential high-volume output to the |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1301 |
front-end (hundreds or thousands of messages issued by a single |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1302 |
command). The idea is to allow the user-interface to downgrade the |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1303 |
quality of message display to achieve higher throughput. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1304 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1305 |
Note that the user might have to take special actions to see tracing |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1306 |
output, e.g.\ switch to a different output window. So this channel |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1307 |
should not be used for regular output. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1308 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1309 |
\item \verb|warning|~\isa{text} outputs \isa{text} as |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1310 |
warning, which typically means some extra emphasis on the front-end |
40126 | 1311 |
side (color highlighting, icons, etc.). |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1312 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1313 |
\item \verb|error|~\isa{text} raises exception \verb|ERROR|~\isa{text} and thus lets the Isar toplevel print \isa{text} on the |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1314 |
error channel, which typically means some extra emphasis on the |
40126 | 1315 |
front-end side (color highlighting, icons, etc.). |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1316 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1317 |
This assumes that the exception is not handled before the command |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1318 |
terminates. Handling exception \verb|ERROR|~\isa{text} is a |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1319 |
perfectly legal alternative: it means that the error is absorbed |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1320 |
without any message output. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1321 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1322 |
\begin{warn} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1323 |
The actual error channel is accessed via \verb|Output.error_msg|, but |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1324 |
the interaction protocol of Proof~General \emph{crashes} if that |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1325 |
function is used in regular ML code: error output and toplevel |
40126 | 1326 |
command failure always need to coincide. |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1327 |
\end{warn} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1328 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1329 |
\end{description} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1330 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1331 |
\begin{warn} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1332 |
Regular Isabelle/ML code should output messages exclusively by the |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1333 |
official channels. Using raw I/O on \emph{stdout} or \emph{stderr} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1334 |
instead (e.g.\ via \verb|TextIO.output|) is apt to cause problems in |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1335 |
the presence of parallel and asynchronous processing of Isabelle |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1336 |
theories. Such raw output might be displayed by the front-end in |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1337 |
some system console log, with a low chance that the user will ever |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1338 |
see it. Moreover, as a genuine side-effect on global process |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1339 |
channels, there is no proper way to retract output when Isar command |
40126 | 1340 |
transactions are reset by the system. |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1341 |
\end{warn} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1342 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1343 |
\begin{warn} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1344 |
The message channels should be used in a message-oriented manner. |
40126 | 1345 |
This means that multi-line output that logically belongs together is |
1346 |
issued by a \emph{single} invocation of \verb|writeln| etc.\ with the |
|
1347 |
functional concatenation of all message constituents. |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1348 |
\end{warn}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1349 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1350 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1351 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1352 |
\endisatagmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1353 |
{\isafoldmlref}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1354 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1355 |
\isadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1356 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1357 |
\endisadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1358 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1359 |
\isadelimmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1360 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1361 |
\endisadelimmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1362 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1363 |
\isatagmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1364 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1365 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1366 |
The following example demonstrates a multi-line |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1367 |
warning. Note that in some situations the user sees only the first |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1368 |
line, so the most important point should be made first.% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1369 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1370 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1371 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1372 |
\endisatagmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1373 |
{\isafoldmlex}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1374 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1375 |
\isadelimmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1376 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1377 |
\endisadelimmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1378 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1379 |
\isadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1380 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1381 |
\endisadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1382 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1383 |
\isatagML |
40406 | 1384 |
\isacommand{ML{\isaliteral{5F}{\isacharunderscore}}command}\isamarkupfalse% |
1385 |
\ {\isaliteral{7B2A}{\isacharverbatimopen}}\isanewline |
|
1386 |
\ \ warning\ {\isaliteral{28}{\isacharparenleft}}cat{\isaliteral{5F}{\isacharunderscore}}lines\isanewline |
|
1387 |
\ \ \ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{22}{\isachardoublequote}}Beware\ the\ Jabberwock{\isaliteral{2C}{\isacharcomma}}\ my\ son{\isaliteral{21}{\isacharbang}}{\isaliteral{22}{\isachardoublequote}}{\isaliteral{2C}{\isacharcomma}}\isanewline |
|
1388 |
\ \ \ \ {\isaliteral{22}{\isachardoublequote}}The\ jaws\ that\ bite{\isaliteral{2C}{\isacharcomma}}\ the\ claws\ that\ catch{\isaliteral{21}{\isacharbang}}{\isaliteral{22}{\isachardoublequote}}{\isaliteral{2C}{\isacharcomma}}\isanewline |
|
1389 |
\ \ \ \ {\isaliteral{22}{\isachardoublequote}}Beware\ the\ Jubjub\ Bird{\isaliteral{2C}{\isacharcomma}}\ and\ shun{\isaliteral{22}{\isachardoublequote}}{\isaliteral{2C}{\isacharcomma}}\isanewline |
|
1390 |
\ \ \ \ {\isaliteral{22}{\isachardoublequote}}The\ frumious\ Bandersnatch{\isaliteral{21}{\isacharbang}}{\isaliteral{22}{\isachardoublequote}}{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
|
1391 |
{\isaliteral{2A7D}{\isacharverbatimclose}}% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1392 |
\endisatagML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1393 |
{\isafoldML}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1394 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1395 |
\isadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1396 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1397 |
\endisadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1398 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1399 |
\isamarkupsection{Exceptions \label{sec:exceptions}% |
24089 | 1400 |
} |
1401 |
\isamarkuptrue% |
|
1402 |
% |
|
1403 |
\begin{isamarkuptext}% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1404 |
The Standard ML semantics of strict functional evaluation |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1405 |
together with exceptions is rather well defined, but some delicate |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1406 |
points need to be observed to avoid that ML programs go wrong |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1407 |
despite static type-checking. Exceptions in Isabelle/ML are |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1408 |
subsequently categorized as follows. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1409 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1410 |
\paragraph{Regular user errors.} These are meant to provide |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1411 |
informative feedback about malformed input etc. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1412 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1413 |
The \emph{error} function raises the corresponding \emph{ERROR} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1414 |
exception, with a plain text message as argument. \emph{ERROR} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1415 |
exceptions can be handled internally, in order to be ignored, turned |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1416 |
into other exceptions, or cascaded by appending messages. If the |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1417 |
corresponding Isabelle/Isar command terminates with an \emph{ERROR} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1418 |
exception state, the toplevel will print the result on the error |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1419 |
channel (see \secref{sec:message-channels}). |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1420 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1421 |
It is considered bad style to refer to internal function names or |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1422 |
values in ML source notation in user error messages. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1423 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1424 |
Grammatical correctness of error messages can be improved by |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1425 |
\emph{omitting} final punctuation: messages are often concatenated |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1426 |
or put into a larger context (e.g.\ augmented with source position). |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1427 |
By not insisting in the final word at the origin of the error, the |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1428 |
system can perform its administrative tasks more easily and |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1429 |
robustly. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1430 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1431 |
\paragraph{Program failures.} There is a handful of standard |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1432 |
exceptions that indicate general failure situations, or failures of |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1433 |
core operations on logical entities (types, terms, theorems, |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1434 |
theories, see \chref{ch:logic}). |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1435 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1436 |
These exceptions indicate a genuine breakdown of the program, so the |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1437 |
main purpose is to determine quickly what has happened where. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1438 |
Traditionally, the (short) exception message would include the name |
40126 | 1439 |
of an ML function, although this is no longer necessary, because the |
1440 |
ML runtime system prints a detailed source position of the |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1441 |
corresponding \verb|raise| keyword. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1442 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1443 |
\medskip User modules can always introduce their own custom |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1444 |
exceptions locally, e.g.\ to organize internal failures robustly |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1445 |
without overlapping with existing exceptions. Exceptions that are |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1446 |
exposed in module signatures require extra care, though, and should |
40126 | 1447 |
\emph{not} be introduced by default. Surprise by users of a module |
1448 |
can be often minimized by using plain user errors instead. |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1449 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1450 |
\paragraph{Interrupts.} These indicate arbitrary system events: |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1451 |
both the ML runtime system and the Isabelle/ML infrastructure signal |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1452 |
various exceptional situations by raising the special |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1453 |
\emph{Interrupt} exception in user code. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1454 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1455 |
This is the one and only way that physical events can intrude an |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1456 |
Isabelle/ML program. Such an interrupt can mean out-of-memory, |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1457 |
stack overflow, timeout, internal signaling of threads, or the user |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1458 |
producing a console interrupt manually etc. An Isabelle/ML program |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1459 |
that intercepts interrupts becomes dependent on physical effects of |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1460 |
the environment. Even worse, exception handling patterns that are |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1461 |
too general by accident, e.g.\ by mispelled exception constructors, |
40126 | 1462 |
will cover interrupts unintentionally and thus render the program |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1463 |
semantics ill-defined. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1464 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1465 |
Note that the Interrupt exception dates back to the original SML90 |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1466 |
language definition. It was excluded from the SML97 version to |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1467 |
avoid its malign impact on ML program semantics, but without |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1468 |
providing a viable alternative. Isabelle/ML recovers physical |
40229 | 1469 |
interruptibility (which is an indispensable tool to implement |
1470 |
managed evaluation of command transactions), but requires user code |
|
1471 |
to be strictly transparent wrt.\ interrupts. |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1472 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1473 |
\begin{warn} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1474 |
Isabelle/ML user code needs to terminate promptly on interruption, |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1475 |
without guessing at its meaning to the system infrastructure. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1476 |
Temporary handling of interrupts for cleanup of global resources |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1477 |
etc.\ needs to be followed immediately by re-raising of the original |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1478 |
exception. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1479 |
\end{warn}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1480 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1481 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1482 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1483 |
\isadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1484 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1485 |
\endisadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1486 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1487 |
\isatagmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1488 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1489 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1490 |
\begin{mldecls} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1491 |
\indexdef{}{ML}{try}\verb|try: ('a -> 'b) -> 'a -> 'b option| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1492 |
\indexdef{}{ML}{can}\verb|can: ('a -> 'b) -> 'a -> bool| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1493 |
\indexdef{}{ML}{ERROR}\verb|ERROR: string -> exn| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1494 |
\indexdef{}{ML}{Fail}\verb|Fail: string -> exn| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1495 |
\indexdef{}{ML}{Exn.is\_interrupt}\verb|Exn.is_interrupt: exn -> bool| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1496 |
\indexdef{}{ML}{reraise}\verb|reraise: exn -> 'a| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1497 |
\indexdef{}{ML}{exception\_trace}\verb|exception_trace: (unit -> 'a) -> 'a| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1498 |
\end{mldecls} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1499 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1500 |
\begin{description} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1501 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1502 |
\item \verb|try|~\isa{f\ x} makes the partiality of evaluating |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1503 |
\isa{f\ x} explicit via the option datatype. Interrupts are |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1504 |
\emph{not} handled here, i.e.\ this form serves as safe replacement |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1505 |
for the \emph{unsafe} version \verb|(SOME|~\isa{f\ x}~\verb|handle _ => NONE)| that is occasionally seen in |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1506 |
books about SML. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1507 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1508 |
\item \verb|can| is similar to \verb|try| with more abstract result. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1509 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1510 |
\item \verb|ERROR|~\isa{msg} represents user errors; this |
40126 | 1511 |
exception is normally raised indirectly via the \verb|error| function |
1512 |
(see \secref{sec:message-channels}). |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1513 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1514 |
\item \verb|Fail|~\isa{msg} represents general program failures. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1515 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1516 |
\item \verb|Exn.is_interrupt| identifies interrupts robustly, without |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1517 |
mentioning concrete exception constructors in user code. Handled |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1518 |
interrupts need to be re-raised promptly! |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1519 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1520 |
\item \verb|reraise|~\isa{exn} raises exception \isa{exn} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1521 |
while preserving its implicit position information (if possible, |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1522 |
depending on the ML platform). |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1523 |
|
40126 | 1524 |
\item \verb|exception_trace|~\verb|(fn () =>|~\isa{e}\verb|)| evaluates expression \isa{e} while printing |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1525 |
a full trace of its stack of nested exceptions (if possible, |
40126 | 1526 |
depending on the ML platform).\footnote{In versions of Poly/ML the |
1527 |
trace will appear on raw stdout of the Isabelle process.} |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1528 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1529 |
Inserting \verb|exception_trace| into ML code temporarily is useful |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1530 |
for debugging, but not suitable for production code. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1531 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1532 |
\end{description}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1533 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1534 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1535 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1536 |
\endisatagmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1537 |
{\isafoldmlref}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1538 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1539 |
\isadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1540 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1541 |
\endisadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1542 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1543 |
\isadelimmlantiq |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1544 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1545 |
\endisadelimmlantiq |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1546 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1547 |
\isatagmlantiq |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1548 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1549 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1550 |
\begin{matharray}{rcl} |
40406 | 1551 |
\indexdef{}{ML antiquotation}{assert}\hypertarget{ML antiquotation.assert}{\hyperlink{ML antiquotation.assert}{\mbox{\isa{assert}}}} & : & \isa{ML{\isaliteral{5F}{\isacharunderscore}}antiquotation} \\ |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1552 |
\end{matharray} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1553 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1554 |
\begin{description} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1555 |
|
40406 | 1556 |
\item \isa{{\isaliteral{40}{\isacharat}}{\isaliteral{7B}{\isacharbraceleft}}assert{\isaliteral{7D}{\isacharbraceright}}} inlines a function |
40110 | 1557 |
\verb|bool -> unit| that raises \verb|Fail| if the argument is |
1558 |
\verb|false|. Due to inlining the source position of failed |
|
1559 |
assertions is included in the error output. |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1560 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1561 |
\end{description}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1562 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1563 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1564 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1565 |
\endisatagmlantiq |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1566 |
{\isafoldmlantiq}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1567 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1568 |
\isadelimmlantiq |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1569 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1570 |
\endisadelimmlantiq |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1571 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1572 |
\isamarkupsection{Basic data types% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1573 |
} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1574 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1575 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1576 |
\begin{isamarkuptext}% |
40126 | 1577 |
The basis library proposal of SML97 needs to be treated with |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1578 |
caution. Many of its operations simply do not fit with important |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1579 |
Isabelle/ML conventions (like ``canonical argument order'', see |
40126 | 1580 |
\secref{sec:canonical-argument-order}), others cause problems with |
1581 |
the parallel evaluation model of Isabelle/ML (such as \verb|TextIO.print| or \verb|OS.Process.system|). |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1582 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1583 |
Subsequently we give a brief overview of important operations on |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1584 |
basic ML data types.% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1585 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1586 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1587 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1588 |
\isamarkupsubsection{Characters% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1589 |
} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1590 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1591 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1592 |
\isadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1593 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1594 |
\endisadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1595 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1596 |
\isatagmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1597 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1598 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1599 |
\begin{mldecls} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1600 |
\indexdef{}{ML type}{char}\verb|type char| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1601 |
\end{mldecls} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1602 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1603 |
\begin{description} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1604 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1605 |
\item Type \verb|char| is \emph{not} used. The smallest textual |
40126 | 1606 |
unit in Isabelle is represented as a ``symbol'' (see |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1607 |
\secref{sec:symbols}). |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1608 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1609 |
\end{description}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1610 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1611 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1612 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1613 |
\endisatagmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1614 |
{\isafoldmlref}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1615 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1616 |
\isadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1617 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1618 |
\endisadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1619 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1620 |
\isamarkupsubsection{Integers% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1621 |
} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1622 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1623 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1624 |
\isadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1625 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1626 |
\endisadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1627 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1628 |
\isatagmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1629 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1630 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1631 |
\begin{mldecls} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1632 |
\indexdef{}{ML type}{int}\verb|type int| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1633 |
\end{mldecls} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1634 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1635 |
\begin{description} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1636 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1637 |
\item Type \verb|int| represents regular mathematical integers, |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1638 |
which are \emph{unbounded}. Overflow never happens in |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1639 |
practice.\footnote{The size limit for integer bit patterns in memory |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1640 |
is 64\,MB for 32-bit Poly/ML, and much higher for 64-bit systems.} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1641 |
This works uniformly for all supported ML platforms (Poly/ML and |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1642 |
SML/NJ). |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1643 |
|
40126 | 1644 |
Literal integers in ML text are forced to be of this one true |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1645 |
integer type --- overloading of SML97 is disabled. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1646 |
|
40126 | 1647 |
Structure \verb|IntInf| of SML97 is obsolete and superseded by |
40406 | 1648 |
\verb|Int|. Structure \verb|Integer| in \hyperlink{file.~~/src/Pure/General/integer.ML}{\mbox{\isa{\isatt{{\isaliteral{7E}{\isachartilde}}{\isaliteral{7E}{\isachartilde}}{\isaliteral{2F}{\isacharslash}}src{\isaliteral{2F}{\isacharslash}}Pure{\isaliteral{2F}{\isacharslash}}General{\isaliteral{2F}{\isacharslash}}integer{\isaliteral{2E}{\isachardot}}ML}}}} provides some additional |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1649 |
operations. |
24089 | 1650 |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1651 |
\end{description}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1652 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1653 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1654 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1655 |
\endisatagmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1656 |
{\isafoldmlref}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1657 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1658 |
\isadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1659 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1660 |
\endisadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1661 |
% |
40302 | 1662 |
\isamarkupsubsection{Time% |
1663 |
} |
|
1664 |
\isamarkuptrue% |
|
1665 |
% |
|
1666 |
\isadelimmlref |
|
1667 |
% |
|
1668 |
\endisadelimmlref |
|
1669 |
% |
|
1670 |
\isatagmlref |
|
1671 |
% |
|
1672 |
\begin{isamarkuptext}% |
|
1673 |
\begin{mldecls} |
|
1674 |
\indexdef{}{ML type}{Time.time}\verb|type Time.time| \\ |
|
1675 |
\indexdef{}{ML}{seconds}\verb|seconds: real -> Time.time| \\ |
|
1676 |
\end{mldecls} |
|
1677 |
||
1678 |
\begin{description} |
|
1679 |
||
1680 |
\item Type \verb|Time.time| represents time abstractly according |
|
1681 |
to the SML97 basis library definition. This is adequate for |
|
1682 |
internal ML operations, but awkward in concrete time specifications. |
|
1683 |
||
1684 |
\item \verb|seconds|~\isa{s} turns the concrete scalar \isa{s} (measured in seconds) into an abstract time value. Floating |
|
1685 |
point numbers are easy to use as context parameters (e.g.\ via |
|
1686 |
configuration options, see \secref{sec:config-options}) or |
|
1687 |
preferences that are maintained by external tools as well. |
|
1688 |
||
1689 |
\end{description}% |
|
1690 |
\end{isamarkuptext}% |
|
1691 |
\isamarkuptrue% |
|
1692 |
% |
|
1693 |
\endisatagmlref |
|
1694 |
{\isafoldmlref}% |
|
1695 |
% |
|
1696 |
\isadelimmlref |
|
1697 |
% |
|
1698 |
\endisadelimmlref |
|
1699 |
% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1700 |
\isamarkupsubsection{Options% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1701 |
} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1702 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1703 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1704 |
\isadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1705 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1706 |
\endisadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1707 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1708 |
\isatagmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1709 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1710 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1711 |
\begin{mldecls} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1712 |
\indexdef{}{ML}{Option.map}\verb|Option.map: ('a -> 'b) -> 'a option -> 'b option| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1713 |
\indexdef{}{ML}{is\_some}\verb|is_some: 'a option -> bool| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1714 |
\indexdef{}{ML}{is\_none}\verb|is_none: 'a option -> bool| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1715 |
\indexdef{}{ML}{the}\verb|the: 'a option -> 'a| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1716 |
\indexdef{}{ML}{these}\verb|these: 'a list option -> 'a list| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1717 |
\indexdef{}{ML}{the\_list}\verb|the_list: 'a option -> 'a list| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1718 |
\indexdef{}{ML}{the\_default}\verb|the_default: 'a -> 'a option -> 'a| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1719 |
\end{mldecls}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1720 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1721 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1722 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1723 |
\endisatagmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1724 |
{\isafoldmlref}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1725 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1726 |
\isadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1727 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1728 |
\endisadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1729 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1730 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1731 |
Apart from \verb|Option.map| most operations defined in |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1732 |
structure \verb|Option| are alien to Isabelle/ML. The |
40406 | 1733 |
operations shown above are defined in \hyperlink{file.~~/src/Pure/General/basics.ML}{\mbox{\isa{\isatt{{\isaliteral{7E}{\isachartilde}}{\isaliteral{7E}{\isachartilde}}{\isaliteral{2F}{\isacharslash}}src{\isaliteral{2F}{\isacharslash}}Pure{\isaliteral{2F}{\isacharslash}}General{\isaliteral{2F}{\isacharslash}}basics{\isaliteral{2E}{\isachardot}}ML}}}}, among others.% |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1734 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1735 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1736 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1737 |
\isamarkupsubsection{Lists% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1738 |
} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1739 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1740 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1741 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1742 |
Lists are ubiquitous in ML as simple and light-weight |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1743 |
``collections'' for many everyday programming tasks. Isabelle/ML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1744 |
provides important additions and improvements over operations that |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1745 |
are predefined in the SML97 library.% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1746 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1747 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1748 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1749 |
\isadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1750 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1751 |
\endisadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1752 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1753 |
\isatagmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1754 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1755 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1756 |
\begin{mldecls} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1757 |
\indexdef{}{ML}{cons}\verb|cons: 'a -> 'a list -> 'a list| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1758 |
\indexdef{}{ML}{member}\verb|member: ('b * 'a -> bool) -> 'a list -> 'b -> bool| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1759 |
\indexdef{}{ML}{insert}\verb|insert: ('a * 'a -> bool) -> 'a -> 'a list -> 'a list| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1760 |
\indexdef{}{ML}{remove}\verb|remove: ('b * 'a -> bool) -> 'b -> 'a list -> 'a list| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1761 |
\indexdef{}{ML}{update}\verb|update: ('a * 'a -> bool) -> 'a -> 'a list -> 'a list| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1762 |
\end{mldecls} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1763 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1764 |
\begin{description} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1765 |
|
40406 | 1766 |
\item \verb|cons|~\isa{x\ xs} evaluates to \isa{x\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ xs}. |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1767 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1768 |
Tupled infix operators are a historical accident in Standard ML. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1769 |
The curried \verb|cons| amends this, but it should be only used when |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1770 |
partial application is required. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1771 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1772 |
\item \verb|member|, \verb|insert|, \verb|remove|, \verb|update| treat |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1773 |
lists as a set-like container that maintains the order of elements. |
40406 | 1774 |
See \hyperlink{file.~~/src/Pure/library.ML}{\mbox{\isa{\isatt{{\isaliteral{7E}{\isachartilde}}{\isaliteral{7E}{\isachartilde}}{\isaliteral{2F}{\isacharslash}}src{\isaliteral{2F}{\isacharslash}}Pure{\isaliteral{2F}{\isacharslash}}library{\isaliteral{2E}{\isachardot}}ML}}}} for the full specifications |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1775 |
(written in ML). There are some further derived operations like |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1776 |
\verb|union| or \verb|inter|. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1777 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1778 |
Note that \verb|insert| is conservative about elements that are |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1779 |
already a \verb|member| of the list, while \verb|update| ensures that |
40126 | 1780 |
the latest entry is always put in front. The latter discipline is |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1781 |
often more appropriate in declarations of context data |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1782 |
(\secref{sec:context-data}) that are issued by the user in Isar |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1783 |
source: more recent declarations normally take precedence over |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1784 |
earlier ones. |
24089 | 1785 |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1786 |
\end{description}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1787 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1788 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1789 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1790 |
\endisatagmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1791 |
{\isafoldmlref}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1792 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1793 |
\isadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1794 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1795 |
\endisadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1796 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1797 |
\isadelimmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1798 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1799 |
\endisadelimmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1800 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1801 |
\isatagmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1802 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1803 |
\begin{isamarkuptext}% |
40126 | 1804 |
Using canonical \verb|fold| together with \verb|cons|, or |
1805 |
similar standard operations, alternates the orientation of data. |
|
1806 |
The is quite natural and should not be altered forcible by inserting |
|
1807 |
extra applications of \verb|rev|. The alternative \verb|fold_rev| can |
|
1808 |
be used in the few situations, where alternation should be |
|
1809 |
prevented.% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1810 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1811 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1812 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1813 |
\endisatagmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1814 |
{\isafoldmlex}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1815 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1816 |
\isadelimmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1817 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1818 |
\endisadelimmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1819 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1820 |
\isadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1821 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1822 |
\endisadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1823 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1824 |
\isatagML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1825 |
\isacommand{ML}\isamarkupfalse% |
40406 | 1826 |
\ {\isaliteral{7B2A}{\isacharverbatimopen}}\isanewline |
1827 |
\ \ val\ items\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{5B}{\isacharbrackleft}}{\isadigit{1}}{\isaliteral{2C}{\isacharcomma}}\ {\isadigit{2}}{\isaliteral{2C}{\isacharcomma}}\ {\isadigit{3}}{\isaliteral{2C}{\isacharcomma}}\ {\isadigit{4}}{\isaliteral{2C}{\isacharcomma}}\ {\isadigit{5}}{\isaliteral{2C}{\isacharcomma}}\ {\isadigit{6}}{\isaliteral{2C}{\isacharcomma}}\ {\isadigit{7}}{\isaliteral{2C}{\isacharcomma}}\ {\isadigit{8}}{\isaliteral{2C}{\isacharcomma}}\ {\isadigit{9}}{\isaliteral{2C}{\isacharcomma}}\ {\isadigit{1}}{\isadigit{0}}{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1828 |
\isanewline |
40406 | 1829 |
\ \ val\ list{\isadigit{1}}\ {\isaliteral{3D}{\isacharequal}}\ fold\ cons\ items\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1830 |
\ \ % |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1831 |
\isaantiq |
40406 | 1832 |
assert{}% |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1833 |
\endisaantiq |
40406 | 1834 |
\ {\isaliteral{28}{\isacharparenleft}}list{\isadigit{1}}\ {\isaliteral{3D}{\isacharequal}}\ rev\ items{\isaliteral{29}{\isacharparenright}}{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1835 |
\isanewline |
40406 | 1836 |
\ \ val\ list{\isadigit{2}}\ {\isaliteral{3D}{\isacharequal}}\ fold{\isaliteral{5F}{\isacharunderscore}}rev\ cons\ items\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1837 |
\ \ % |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1838 |
\isaantiq |
40406 | 1839 |
assert{}% |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1840 |
\endisaantiq |
40406 | 1841 |
\ {\isaliteral{28}{\isacharparenleft}}list{\isadigit{2}}\ {\isaliteral{3D}{\isacharequal}}\ items{\isaliteral{29}{\isacharparenright}}{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
1842 |
{\isaliteral{2A7D}{\isacharverbatimclose}}% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1843 |
\endisatagML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1844 |
{\isafoldML}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1845 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1846 |
\isadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1847 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1848 |
\endisadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1849 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1850 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1851 |
The subsequent example demonstrates how to \emph{merge} two |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1852 |
lists in a natural way.% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1853 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1854 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1855 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1856 |
\isadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1857 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1858 |
\endisadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1859 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1860 |
\isatagML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1861 |
\isacommand{ML}\isamarkupfalse% |
40406 | 1862 |
\ {\isaliteral{7B2A}{\isacharverbatimopen}}\isanewline |
1863 |
\ \ fun\ merge{\isaliteral{5F}{\isacharunderscore}}lists\ eq\ {\isaliteral{28}{\isacharparenleft}}xs{\isaliteral{2C}{\isacharcomma}}\ ys{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ fold{\isaliteral{5F}{\isacharunderscore}}rev\ {\isaliteral{28}{\isacharparenleft}}insert\ eq{\isaliteral{29}{\isacharparenright}}\ ys\ xs{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
|
1864 |
{\isaliteral{2A7D}{\isacharverbatimclose}}% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1865 |
\endisatagML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1866 |
{\isafoldML}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1867 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1868 |
\isadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1869 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1870 |
\endisadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1871 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1872 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1873 |
Here the first list is treated conservatively: only the new |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1874 |
elements from the second list are inserted. The inside-out order of |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1875 |
insertion via \verb|fold_rev| attempts to preserve the order of |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1876 |
elements in the result. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1877 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1878 |
This way of merging lists is typical for context data |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1879 |
(\secref{sec:context-data}). See also \verb|merge| as defined in |
40406 | 1880 |
\hyperlink{file.~~/src/Pure/library.ML}{\mbox{\isa{\isatt{{\isaliteral{7E}{\isachartilde}}{\isaliteral{7E}{\isachartilde}}{\isaliteral{2F}{\isacharslash}}src{\isaliteral{2F}{\isacharslash}}Pure{\isaliteral{2F}{\isacharslash}}library{\isaliteral{2E}{\isachardot}}ML}}}}.% |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1881 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1882 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1883 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1884 |
\isamarkupsubsection{Association lists% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1885 |
} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1886 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1887 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1888 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1889 |
The operations for association lists interpret a concrete list |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1890 |
of pairs as a finite function from keys to values. Redundant |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1891 |
representations with multiple occurrences of the same key are |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1892 |
implicitly normalized: lookup and update only take the first |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1893 |
occurrence into account.% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1894 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1895 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1896 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1897 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1898 |
\begin{mldecls} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1899 |
\indexdef{}{ML}{AList.lookup}\verb|AList.lookup: ('a * 'b -> bool) -> ('b * 'c) list -> 'a -> 'c option| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1900 |
\indexdef{}{ML}{AList.defined}\verb|AList.defined: ('a * 'b -> bool) -> ('b * 'c) list -> 'a -> bool| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1901 |
\indexdef{}{ML}{AList.update}\verb|AList.update: ('a * 'a -> bool) -> 'a * 'b -> ('a * 'b) list -> ('a * 'b) list| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1902 |
\end{mldecls} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1903 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1904 |
\begin{description} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1905 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1906 |
\item \verb|AList.lookup|, \verb|AList.defined|, \verb|AList.update| |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1907 |
implement the main ``framework operations'' for mappings in |
40126 | 1908 |
Isabelle/ML, following standard conventions for their names and |
1909 |
types. |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1910 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1911 |
Note that a function called \isa{lookup} is obliged to express its |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1912 |
partiality via an explicit option element. There is no choice to |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1913 |
raise an exception, without changing the name to something like |
40406 | 1914 |
\isa{the{\isaliteral{5F}{\isacharunderscore}}element} or \isa{get}. |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1915 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1916 |
The \isa{defined} operation is essentially a contraction of \verb|is_some| and \isa{lookup}, but this is sufficiently frequent to |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1917 |
justify its independent existence. This also gives the |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1918 |
implementation some opportunity for peep-hole optimization. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1919 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1920 |
\end{description} |
24089 | 1921 |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1922 |
Association lists are adequate as simple and light-weight |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1923 |
implementation of finite mappings in many practical situations. A |
40406 | 1924 |
more heavy-duty table structure is defined in \hyperlink{file.~~/src/Pure/General/table.ML}{\mbox{\isa{\isatt{{\isaliteral{7E}{\isachartilde}}{\isaliteral{7E}{\isachartilde}}{\isaliteral{2F}{\isacharslash}}src{\isaliteral{2F}{\isacharslash}}Pure{\isaliteral{2F}{\isacharslash}}General{\isaliteral{2F}{\isacharslash}}table{\isaliteral{2E}{\isachardot}}ML}}}}; that version scales easily to |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1925 |
thousands or millions of elements.% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1926 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1927 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1928 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1929 |
\isamarkupsubsection{Unsynchronized references% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1930 |
} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1931 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1932 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1933 |
\isadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1934 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1935 |
\endisadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1936 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1937 |
\isatagmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1938 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1939 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1940 |
\begin{mldecls} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1941 |
\indexdef{}{ML type}{Unsynchronized.ref}\verb|type 'a Unsynchronized.ref| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1942 |
\indexdef{}{ML}{Unsynchronized.ref}\verb|Unsynchronized.ref: 'a -> 'a Unsynchronized.ref| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1943 |
\indexdef{}{ML}{!}\verb|! : 'a Unsynchronized.ref -> 'a| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1944 |
\indexdef{}{ML}{:=}\verb|op := : 'a Unsynchronized.ref * 'a -> unit| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1945 |
\end{mldecls}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1946 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1947 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1948 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1949 |
\endisatagmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1950 |
{\isafoldmlref}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1951 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1952 |
\isadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1953 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1954 |
\endisadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1955 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1956 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1957 |
Due to ubiquitous parallelism in Isabelle/ML (see also |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1958 |
\secref{sec:multi-threading}), the mutable reference cells of |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1959 |
Standard ML are notorious for causing problems. In a highly |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1960 |
parallel system, both correctness \emph{and} performance are easily |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1961 |
degraded when using mutable data. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1962 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1963 |
The unwieldy name of \verb|Unsynchronized.ref| for the constructor |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1964 |
for references in Isabelle/ML emphasizes the inconveniences caused by |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1965 |
mutability. Existing operations \verb|!| and \verb|op :=| are |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1966 |
unchanged, but should be used with special precautions, say in a |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1967 |
strictly local situation that is guaranteed to be restricted to |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1968 |
sequential evaluation --- now and in the future.% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1969 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1970 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1971 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1972 |
\isamarkupsection{Thread-safe programming \label{sec:multi-threading}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1973 |
} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1974 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1975 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1976 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1977 |
Multi-threaded execution has become an everyday reality in |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1978 |
Isabelle since Poly/ML 5.2.1 and Isabelle2008. Isabelle/ML provides |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1979 |
implicit and explicit parallelism by default, and there is no way |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1980 |
for user-space tools to ``opt out''. ML programs that are purely |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1981 |
functional, output messages only via the official channels |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1982 |
(\secref{sec:message-channels}), and do not intercept interrupts |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1983 |
(\secref{sec:exceptions}) can participate in the multi-threaded |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1984 |
environment immediately without further ado. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1985 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1986 |
More ambitious tools with more fine-grained interaction with the |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1987 |
environment need to observe the principles explained below.% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1988 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1989 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1990 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1991 |
\isamarkupsubsection{Multi-threading with shared memory% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1992 |
} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1993 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1994 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1995 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1996 |
Multiple threads help to organize advanced operations of the |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1997 |
system, such as real-time conditions on command transactions, |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1998 |
sub-components with explicit communication, general asynchronous |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
1999 |
interaction etc. Moreover, parallel evaluation is a prerequisite to |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2000 |
make adequate use of the CPU resources that are available on |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2001 |
multi-core systems.\footnote{Multi-core computing does not mean that |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2002 |
there are ``spare cycles'' to be wasted. It means that the |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2003 |
continued exponential speedup of CPU performance due to ``Moore's |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2004 |
Law'' follows different rules: clock frequency has reached its peak |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2005 |
around 2005, and applications need to be parallelized in order to |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2006 |
avoid a perceived loss of performance. See also |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2007 |
\cite{Sutter:2005}.} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2008 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2009 |
Isabelle/Isar exploits the inherent structure of theories and proofs |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2010 |
to support \emph{implicit parallelism} to a large extent. LCF-style |
40126 | 2011 |
theorem provides almost ideal conditions for that, see also |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2012 |
\cite{Wenzel:2009}. This means, significant parts of theory and |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2013 |
proof checking is parallelized by default. A maximum speedup-factor |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2014 |
of 3.0 on 4 cores and 5.0 on 8 cores can be |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2015 |
expected.\footnote{Further scalability is limited due to garbage |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2016 |
collection, which is still sequential in Poly/ML 5.2/5.3/5.4. It |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2017 |
helps to provide initial heap space generously, using the |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2018 |
\texttt{-H} option. Initial heap size needs to be scaled-up |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2019 |
together with the number of CPU cores: approximately 1--2\,GB per |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2020 |
core..} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2021 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2022 |
\medskip ML threads lack the memory protection of separate |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2023 |
processes, and operate concurrently on shared heap memory. This has |
40126 | 2024 |
the advantage that results of independent computations are directly |
2025 |
available to other threads: abstract values can be passed without |
|
2026 |
copying or awkward serialization that is typically required for |
|
2027 |
separate processes. |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2028 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2029 |
To make shared-memory multi-threading work robustly and efficiently, |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2030 |
some programming guidelines need to be observed. While the ML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2031 |
system is responsible to maintain basic integrity of the |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2032 |
representation of ML values in memory, the application programmer |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2033 |
needs to ensure that multi-threaded execution does not break the |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2034 |
intended semantics. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2035 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2036 |
\begin{warn} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2037 |
To participate in implicit parallelism, tools need to be |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2038 |
thread-safe. A single ill-behaved tool can affect the stability and |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2039 |
performance of the whole system. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2040 |
\end{warn} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2041 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2042 |
Apart from observing the principles of thread-safeness passively, |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2043 |
advanced tools may also exploit parallelism actively, e.g.\ by using |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2044 |
``future values'' (\secref{sec:futures}) or the more basic library |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2045 |
functions for parallel list operations (\secref{sec:parlist}). |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2046 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2047 |
\begin{warn} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2048 |
Parallel computing resources are managed centrally by the |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2049 |
Isabelle/ML infrastructure. User programs must not fork their own |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2050 |
ML threads to perform computations. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2051 |
\end{warn}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2052 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2053 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2054 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2055 |
\isamarkupsubsection{Critical shared resources% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2056 |
} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2057 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2058 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2059 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2060 |
Thread-safeness is mainly concerned about concurrent |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2061 |
read/write access to shared resources, which are outside the purely |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2062 |
functional world of ML. This covers the following in particular. |
24089 | 2063 |
|
2064 |
\begin{itemize} |
|
2065 |
||
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2066 |
\item Global references (or arrays), i.e.\ mutable memory cells that |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2067 |
persist over several invocations of associated |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2068 |
operations.\footnote{This is independent of the visibility of such |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2069 |
mutable values in the toplevel scope.} |
24089 | 2070 |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2071 |
\item Global state of the running Isabelle/ML process, i.e.\ raw I/O |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2072 |
channels, environment variables, current working directory. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2073 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2074 |
\item Writable resources in the file-system that are shared among |
40126 | 2075 |
different threads or external processes. |
24089 | 2076 |
|
2077 |
\end{itemize} |
|
2078 |
||
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2079 |
Isabelle/ML provides various mechanisms to avoid critical shared |
40126 | 2080 |
resources in most situations. As last resort there are some |
2081 |
mechanisms for explicit synchronization. The following guidelines |
|
2082 |
help to make Isabelle/ML programs work smoothly in a concurrent |
|
2083 |
environment. |
|
24089 | 2084 |
|
2085 |
\begin{itemize} |
|
2086 |
||
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2087 |
\item Avoid global references altogether. Isabelle/Isar maintains a |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2088 |
uniform context that incorporates arbitrary data declared by user |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2089 |
programs (\secref{sec:context-data}). This context is passed as |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2090 |
plain value and user tools can get/map their own data in a purely |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2091 |
functional manner. Configuration options within the context |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2092 |
(\secref{sec:config-options}) provide simple drop-in replacements |
40126 | 2093 |
for historic reference variables. |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2094 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2095 |
\item Keep components with local state information re-entrant. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2096 |
Instead of poking initial values into (private) global references, a |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2097 |
new state record can be created on each invocation, and passed |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2098 |
through any auxiliary functions of the component. The state record |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2099 |
may well contain mutable references, without requiring any special |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2100 |
synchronizations, as long as each invocation gets its own copy. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2101 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2102 |
\item Avoid raw output on \isa{stdout} or \isa{stderr}. The |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2103 |
Poly/ML library is thread-safe for each individual output operation, |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2104 |
but the ordering of parallel invocations is arbitrary. This means |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2105 |
raw output will appear on some system console with unpredictable |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2106 |
interleaving of atomic chunks. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2107 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2108 |
Note that this does not affect regular message output channels |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2109 |
(\secref{sec:message-channels}). An official message is associated |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2110 |
with the command transaction from where it originates, independently |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2111 |
of other transactions. This means each running Isar command has |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2112 |
effectively its own set of message channels, and interleaving can |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2113 |
only happen when commands use parallelism internally (and only at |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2114 |
message boundaries). |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2115 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2116 |
\item Treat environment variables and the current working directory |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2117 |
of the running process as strictly read-only. |
24089 | 2118 |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2119 |
\item Restrict writing to the file-system to unique temporary files. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2120 |
Isabelle already provides a temporary directory that is unique for |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2121 |
the running process, and there is a centralized source of unique |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2122 |
serial numbers in Isabelle/ML. Thus temporary files that are passed |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2123 |
to to some external process will be always disjoint, and thus |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2124 |
thread-safe. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2125 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2126 |
\end{itemize}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2127 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2128 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2129 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2130 |
\isadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2131 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2132 |
\endisadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2133 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2134 |
\isatagmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2135 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2136 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2137 |
\begin{mldecls} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2138 |
\indexdef{}{ML}{File.tmp\_path}\verb|File.tmp_path: Path.T -> Path.T| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2139 |
\indexdef{}{ML}{serial\_string}\verb|serial_string: unit -> string| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2140 |
\end{mldecls} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2141 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2142 |
\begin{description} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2143 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2144 |
\item \verb|File.tmp_path|~\isa{path} relocates the base |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2145 |
component of \isa{path} into the unique temporary directory of |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2146 |
the running Isabelle/ML process. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2147 |
|
40406 | 2148 |
\item \verb|serial_string|~\isa{{\isaliteral{28}{\isacharparenleft}}{\isaliteral{29}{\isacharparenright}}} creates a new serial number |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2149 |
that is unique over the runtime of the Isabelle/ML process. |
24089 | 2150 |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2151 |
\end{description}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2152 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2153 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2154 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2155 |
\endisatagmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2156 |
{\isafoldmlref}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2157 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2158 |
\isadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2159 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2160 |
\endisadelimmlref |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2161 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2162 |
\isadelimmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2163 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2164 |
\endisadelimmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2165 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2166 |
\isatagmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2167 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2168 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2169 |
The following example shows how to create unique |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2170 |
temporary file names.% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2171 |
\end{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2172 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2173 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2174 |
\endisatagmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2175 |
{\isafoldmlex}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2176 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2177 |
\isadelimmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2178 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2179 |
\endisadelimmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2180 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2181 |
\isadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2182 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2183 |
\endisadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2184 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2185 |
\isatagML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2186 |
\isacommand{ML}\isamarkupfalse% |
40406 | 2187 |
\ {\isaliteral{7B2A}{\isacharverbatimopen}}\isanewline |
2188 |
\ \ val\ tmp{\isadigit{1}}\ {\isaliteral{3D}{\isacharequal}}\ File{\isaliteral{2E}{\isachardot}}tmp{\isaliteral{5F}{\isacharunderscore}}path\ {\isaliteral{28}{\isacharparenleft}}Path{\isaliteral{2E}{\isachardot}}basic\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{22}{\isachardoublequote}}foo{\isaliteral{22}{\isachardoublequote}}\ {\isaliteral{5E}{\isacharcircum}}\ serial{\isaliteral{5F}{\isacharunderscore}}string\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
|
2189 |
\ \ val\ tmp{\isadigit{2}}\ {\isaliteral{3D}{\isacharequal}}\ File{\isaliteral{2E}{\isachardot}}tmp{\isaliteral{5F}{\isacharunderscore}}path\ {\isaliteral{28}{\isacharparenleft}}Path{\isaliteral{2E}{\isachardot}}basic\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{22}{\isachardoublequote}}foo{\isaliteral{22}{\isachardoublequote}}\ {\isaliteral{5E}{\isacharcircum}}\ serial{\isaliteral{5F}{\isacharunderscore}}string\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2190 |
\ \ % |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2191 |
\isaantiq |
40406 | 2192 |
assert{}% |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2193 |
\endisaantiq |
40406 | 2194 |
\ {\isaliteral{28}{\isacharparenleft}}tmp{\isadigit{1}}\ {\isaliteral{3C}{\isacharless}}{\isaliteral{3E}{\isachargreater}}\ tmp{\isadigit{2}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
2195 |
{\isaliteral{2A7D}{\isacharverbatimclose}}% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2196 |
\endisatagML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2197 |
{\isafoldML}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2198 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2199 |
\isadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2200 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2201 |
\endisadelimML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2202 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2203 |
\isamarkupsubsection{Explicit synchronization% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2204 |
} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2205 |
\isamarkuptrue% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2206 |
% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2207 |
\begin{isamarkuptext}% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2208 |
Isabelle/ML also provides some explicit synchronization |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2209 |
mechanisms, for the rare situations where mutable shared resources |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2210 |
are really required. These are based on the synchronizations |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2211 |
primitives of Poly/ML, which have been adapted to the specific |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2212 |
assumptions of the concurrent Isabelle/ML environment. User code |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2213 |
must not use the Poly/ML primitives directly! |
24089 | 2214 |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2215 |
\medskip The most basic synchronization concept is a single |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2216 |
\emph{critical section} (also called ``monitor'' in the literature). |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2217 |
A thread that enters the critical section prevents all other threads |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2218 |
from doing the same. A thread that is already within the critical |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2219 |
section may re-enter it in an idempotent manner. |
24089 | 2220 |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2221 |
Such centralized locking is convenient, because it prevents |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2222 |
deadlocks by construction. |
24089 | 2223 |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2224 |
\medskip More fine-grained locking works via \emph{synchronized |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2225 |
variables}. An explicit state component is associated with |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2226 |
mechanisms for locking and signaling. There are operations to |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2227 |
await a condition, change the state, and signal the change to all |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2228 |
other waiting threads. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2229 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2230 |
Here the synchronized access to the state variable is \emph{not} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2231 |
re-entrant: direct or indirect nesting within the same thread will |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2232 |
cause a deadlock!% |
24089 | 2233 |
\end{isamarkuptext}% |
2234 |
\isamarkuptrue% |
|
2235 |
% |
|
2236 |
\isadelimmlref |
|
2237 |
% |
|
2238 |
\endisadelimmlref |
|
2239 |
% |
|
2240 |
\isatagmlref |
|
2241 |
% |
|
2242 |
\begin{isamarkuptext}% |
|
2243 |
\begin{mldecls} |
|
30121 | 2244 |
\indexdef{}{ML}{NAMED\_CRITICAL}\verb|NAMED_CRITICAL: string -> (unit -> 'a) -> 'a| \\ |
2245 |
\indexdef{}{ML}{CRITICAL}\verb|CRITICAL: (unit -> 'a) -> 'a| \\ |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2246 |
\end{mldecls} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2247 |
\begin{mldecls} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2248 |
\indexdef{}{ML type}{Synchronized.var}\verb|type 'a Synchronized.var| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2249 |
\indexdef{}{ML}{Synchronized.var}\verb|Synchronized.var: string -> 'a -> 'a Synchronized.var| \\ |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2250 |
\indexdef{}{ML}{Synchronized.guarded\_access}\verb|Synchronized.guarded_access: 'a Synchronized.var ->|\isasep\isanewline% |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2251 |
\verb| ('a -> ('b * 'a) option) -> 'b| \\ |
24089 | 2252 |
\end{mldecls} |
2253 |
||
2254 |
\begin{description} |
|
2255 |
||
40406 | 2256 |
\item \verb|NAMED_CRITICAL|~\isa{name\ e} evaluates \isa{e\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{29}{\isacharparenright}}} |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2257 |
within the central critical section of Isabelle/ML. No other thread |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2258 |
may do so at the same time, but non-critical parallel execution will |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2259 |
continue. The \isa{name} argument is used for tracing and might |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2260 |
help to spot sources of congestion. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2261 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2262 |
Entering the critical section without contention is very fast, and |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2263 |
several basic system operations do so frequently. Each thread |
40126 | 2264 |
should stay within the critical section quickly only very briefly, |
2265 |
otherwise parallel performance may degrade. |
|
24089 | 2266 |
|
2267 |
\item \verb|CRITICAL| is the same as \verb|NAMED_CRITICAL| with empty |
|
2268 |
name argument. |
|
2269 |
||
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2270 |
\item Type \verb|'a Synchronized.var| represents synchronized |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2271 |
variables with state of type \verb|'a|. |
24089 | 2272 |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2273 |
\item \verb|Synchronized.var|~\isa{name\ x} creates a synchronized |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2274 |
variable that is initialized with value \isa{x}. The \isa{name} is used for tracing. |
25151 | 2275 |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2276 |
\item \verb|Synchronized.guarded_access|~\isa{var\ f} lets the |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2277 |
function \isa{f} operate within a critical section on the state |
40126 | 2278 |
\isa{x} as follows: if \isa{f\ x} produces \verb|NONE|, it |
2279 |
continues to wait on the internal condition variable, expecting that |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2280 |
some other thread will eventually change the content in a suitable |
40406 | 2281 |
manner; if \isa{f\ x} produces \verb|SOME|~\isa{{\isaliteral{28}{\isacharparenleft}}y{\isaliteral{2C}{\isacharcomma}}\ x{\isaliteral{27}{\isacharprime}}{\isaliteral{29}{\isacharparenright}}} it is |
2282 |
satisfied and assigns the new state value \isa{x{\isaliteral{27}{\isacharprime}}}, broadcasts a |
|
40126 | 2283 |
signal to all waiting threads on the associated condition variable, |
2284 |
and returns the result \isa{y}. |
|
26459 | 2285 |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2286 |
\end{description} |
26459 | 2287 |
|
40406 | 2288 |
There are some further variants of the \verb|Synchronized.guarded_access| combinator, see \hyperlink{file.~~/src/Pure/Concurrent/synchronized.ML}{\mbox{\isa{\isatt{{\isaliteral{7E}{\isachartilde}}{\isaliteral{7E}{\isachartilde}}{\isaliteral{2F}{\isacharslash}}src{\isaliteral{2F}{\isacharslash}}Pure{\isaliteral{2F}{\isacharslash}}Concurrent{\isaliteral{2F}{\isacharslash}}synchronized{\isaliteral{2E}{\isachardot}}ML}}}} for details.% |
22293 | 2289 |
\end{isamarkuptext}% |
2290 |
\isamarkuptrue% |
|
2291 |
% |
|
22322 | 2292 |
\endisatagmlref |
2293 |
{\isafoldmlref}% |
|
2294 |
% |
|
2295 |
\isadelimmlref |
|
2296 |
% |
|
2297 |
\endisadelimmlref |
|
2298 |
% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2299 |
\isadelimmlex |
22322 | 2300 |
% |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2301 |
\endisadelimmlex |
22322 | 2302 |
% |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2303 |
\isatagmlex |
22322 | 2304 |
% |
2305 |
\begin{isamarkuptext}% |
|
40126 | 2306 |
The following example implements a counter that produces |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2307 |
positive integers that are unique over the runtime of the Isabelle |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2308 |
process:% |
22293 | 2309 |
\end{isamarkuptext}% |
2310 |
\isamarkuptrue% |
|
2311 |
% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2312 |
\endisatagmlex |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2313 |
{\isafoldmlex}% |
22293 | 2314 |
% |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2315 |
\isadelimmlex |
22293 | 2316 |
% |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2317 |
\endisadelimmlex |
22293 | 2318 |
% |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2319 |
\isadelimML |
22293 | 2320 |
% |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2321 |
\endisadelimML |
22293 | 2322 |
% |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2323 |
\isatagML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2324 |
\isacommand{ML}\isamarkupfalse% |
40406 | 2325 |
\ {\isaliteral{7B2A}{\isacharverbatimopen}}\isanewline |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2326 |
\ \ local\isanewline |
40406 | 2327 |
\ \ \ \ val\ counter\ {\isaliteral{3D}{\isacharequal}}\ Synchronized{\isaliteral{2E}{\isachardot}}var\ {\isaliteral{22}{\isachardoublequote}}counter{\isaliteral{22}{\isachardoublequote}}\ {\isadigit{0}}{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2328 |
\ \ in\isanewline |
40406 | 2329 |
\ \ \ \ fun\ next\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\isanewline |
2330 |
\ \ \ \ \ \ Synchronized{\isaliteral{2E}{\isachardot}}guarded{\isaliteral{5F}{\isacharunderscore}}access\ counter\isanewline |
|
2331 |
\ \ \ \ \ \ \ \ {\isaliteral{28}{\isacharparenleft}}fn\ i\ {\isaliteral{3D}{\isacharequal}}{\isaliteral{3E}{\isachargreater}}\isanewline |
|
2332 |
\ \ \ \ \ \ \ \ \ \ let\ val\ j\ {\isaliteral{3D}{\isacharequal}}\ i\ {\isaliteral{2B}{\isacharplus}}\ {\isadigit{1}}\isanewline |
|
2333 |
\ \ \ \ \ \ \ \ \ \ in\ SOME\ {\isaliteral{28}{\isacharparenleft}}j{\isaliteral{2C}{\isacharcomma}}\ j{\isaliteral{29}{\isacharparenright}}\ end{\isaliteral{29}{\isacharparenright}}{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
|
2334 |
\ \ end{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
|
2335 |
{\isaliteral{2A7D}{\isacharverbatimclose}}\isanewline |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2336 |
\isanewline |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2337 |
\isacommand{ML}\isamarkupfalse% |
40406 | 2338 |
\ {\isaliteral{7B2A}{\isacharverbatimopen}}\isanewline |
2339 |
\ \ val\ a\ {\isaliteral{3D}{\isacharequal}}\ next\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
|
2340 |
\ \ val\ b\ {\isaliteral{3D}{\isacharequal}}\ next\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2341 |
\ \ % |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2342 |
\isaantiq |
40406 | 2343 |
assert{}% |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2344 |
\endisaantiq |
40406 | 2345 |
\ {\isaliteral{28}{\isacharparenleft}}a\ {\isaliteral{3C}{\isacharless}}{\isaliteral{3E}{\isachargreater}}\ b{\isaliteral{29}{\isacharparenright}}{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
2346 |
{\isaliteral{2A7D}{\isacharverbatimclose}}% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2347 |
\endisatagML |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2348 |
{\isafoldML}% |
22293 | 2349 |
% |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2350 |
\isadelimML |
22293 | 2351 |
% |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
36164
diff
changeset
|
2352 |
\endisadelimML |
40126 | 2353 |
% |
2354 |
\begin{isamarkuptext}% |
|
40406 | 2355 |
\medskip See \hyperlink{file.~~/src/Pure/Concurrent/mailbox.ML}{\mbox{\isa{\isatt{{\isaliteral{7E}{\isachartilde}}{\isaliteral{7E}{\isachartilde}}{\isaliteral{2F}{\isacharslash}}src{\isaliteral{2F}{\isacharslash}}Pure{\isaliteral{2F}{\isacharslash}}Concurrent{\isaliteral{2F}{\isacharslash}}mailbox{\isaliteral{2E}{\isachardot}}ML}}}} how |
40126 | 2356 |
to implement a mailbox as synchronized variable over a purely |
2357 |
functional queue.% |
|
2358 |
\end{isamarkuptext}% |
|
2359 |
\isamarkuptrue% |
|
18543 | 2360 |
% |
2361 |
\isadelimtheory |
|
2362 |
% |
|
2363 |
\endisadelimtheory |
|
2364 |
% |
|
2365 |
\isatagtheory |
|
2366 |
\isacommand{end}\isamarkupfalse% |
|
18537 | 2367 |
% |
2368 |
\endisatagtheory |
|
2369 |
{\isafoldtheory}% |
|
2370 |
% |
|
2371 |
\isadelimtheory |
|
2372 |
% |
|
2373 |
\endisadelimtheory |
|
2374 |
\end{isabellebody}% |
|
2375 |
%%% Local Variables: |
|
2376 |
%%% mode: latex |
|
2377 |
%%% TeX-master: "root" |
|
2378 |
%%% End: |