doc-src/IsarImplementation/Thy/document/ML.tex
author wenzelm
Tue, 01 Jun 2010 17:27:38 +0200
changeset 37241 04d2521e79b0
parent 36164 532f4d1cb0fc
child 39885 6a3f7941c3a0
permissions -rw-r--r--
basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
     1
%
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
     2
\begin{isabellebody}%
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
     3
\def\isabellecontext{ML}%
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
     4
%
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
     5
\isadelimtheory
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
     6
%
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
     7
\endisadelimtheory
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
     8
%
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
     9
\isatagtheory
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    10
\isacommand{theory}\isamarkupfalse%
29756
df70c0291579 updated generated files;
wenzelm
parents: 29647
diff changeset
    11
\ {\isachardoublequoteopen}ML{\isachardoublequoteclose}\isanewline
df70c0291579 updated generated files;
wenzelm
parents: 29647
diff changeset
    12
\isakeyword{imports}\ Base\isanewline
df70c0291579 updated generated files;
wenzelm
parents: 29647
diff changeset
    13
\isakeyword{begin}%
18543
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
    14
\endisatagtheory
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
    15
{\isafoldtheory}%
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
    16
%
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
    17
\isadelimtheory
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
    18
%
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
    19
\endisadelimtheory
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
    20
%
26437
5906619c8c6b tuned appendix;
wenzelm
parents: 25608
diff changeset
    21
\isamarkupchapter{Advanced ML programming%
18543
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
    22
}
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
    23
\isamarkuptrue%
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
    24
%
24089
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
    25
\isamarkupsection{Style%
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
    26
}
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
    27
\isamarkuptrue%
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
    28
%
18543
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
    29
\begin{isamarkuptext}%
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
    30
Like any style guide, also this one should not be interpreted dogmatically, but
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
    31
  with care and discernment.  It consists of a collection of
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
    32
  recommendations which have been turned out useful over long years of
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
    33
  Isabelle system development and are supposed to support writing of readable
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
    34
  and managable code.  Special cases encourage derivations,
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
    35
  as far as you know what you are doing.
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
    36
  \footnote{This style guide is loosely based on
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
    37
  \url{http://caml.inria.fr/resources/doc/guides/guidelines.en.html}}
21148
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    38
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    39
  \begin{description}
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    40
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    41
    \item[fundamental law of programming]
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    42
      Whenever writing code, keep in mind: A program is
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    43
      written once, modified ten times, and read
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
    44
      hundred times.  So simplify its writing,
21148
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    45
      always keep future modifications in mind,
21172
eea3c9048c7a updated;
wenzelm
parents: 21148
diff changeset
    46
      and never jeopardize readability.  Every second you hesitate
21148
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    47
      to spend on making your code more clear you will
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    48
      have to spend ten times understanding what you have
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    49
      written later on.
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    50
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    51
    \item[white space matters]
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    52
      Treat white space in your code as if it determines
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    53
      the meaning of code.
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    54
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    55
      \begin{itemize}
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    56
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    57
        \item The space bar is the easiest key to find on the keyboard,
24089
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
    58
          press it as often as necessary. \verb|2 + 2| is better
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
    59
          than \verb|2+2|, likewise \verb|f (x, y)| is
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
    60
          better than \verb|f(x,y)|.
21148
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    61
24089
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
    62
        \item Restrict your lines to 80 characters.  This will allow
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
    63
          you to keep the beginning of a line in view while watching
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
    64
          its end.\footnote{To acknowledge the lax practice of
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
    65
          text editing these days, we tolerate as much as 100
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
    66
          characters per line, but anything beyond 120 is not
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
    67
          considered proper source text.}
21148
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    68
24089
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
    69
        \item Ban tabulators; they are a context-sensitive formatting
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
    70
          feature and likely to confuse anyone not using your favorite
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
    71
          editor.\footnote{Some modern programming language even
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
    72
          forbid tabulators altogether according to the formal syntax
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
    73
          definition.}
21148
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    74
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    75
        \item Get rid of trailing whitespace.  Instead, do not
24089
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
    76
          suppress a trailing newline at the end of your files.
21148
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    77
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    78
        \item Choose a generally accepted style of indentation,
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    79
          then use it systematically throughout the whole
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    80
          application.  An indentation of two spaces is appropriate.
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    81
          Avoid dangling indentation.
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    82
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    83
      \end{itemize}
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    84
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    85
    \item[cut-and-paste succeeds over copy-and-paste]
24089
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
    86
       \emph{Never} copy-and-paste code when programming.  If you
21148
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    87
        need the same piece of code twice, introduce a
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    88
        reasonable auxiliary function (if there is no
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    89
        such function, very likely you got something wrong).
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    90
        Any copy-and-paste will turn out to be painful 
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
    91
        when something has to be changed later on.
21148
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    92
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    93
    \item[comments]
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    94
      are a device which requires careful thinking before using
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    95
      it.  The best comment for your code should be the code itself.
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    96
      Prefer efforts to write clear, understandable code
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    97
      over efforts to explain nasty code.
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    98
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    99
    \item[functional programming is based on functions]
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   100
      Model things as abstract as appropriate.  Avoid unnecessarrily
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   101
      concrete datatype  representations.  For example, consider a function
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   102
      taking some table data structure as argument and performing
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   103
      lookups on it.  Instead of taking a table, it could likewise
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   104
      take just a lookup function.  Accustom
24089
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   105
      your way of coding to the level of expressiveness a functional
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   106
      programming language is giving onto you.
21148
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
   107
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
   108
    \item[tuples]
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
   109
      are often in the way.  When there is no striking argument
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
   110
      to tuple function arguments, just write your function curried.
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
   111
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
   112
    \item[telling names]
24089
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   113
      Any name should tell its purpose as exactly as possible, while
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   114
      keeping its length to the absolutely necessary minimum.  Always
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   115
      give the same name to function arguments which have the same
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   116
      meaning. Separate words by underscores (\verb|int_of_string|, not \verb|intOfString|).\footnote{Some
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   117
      recent tools for Emacs include special precautions to cope with
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   118
      bumpy names in \isa{camelCase}, e.g.\ for improved on-screen
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   119
      readability.  It is easier to abstain from using such names in the
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   120
      first place.}
21148
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
   121
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
   122
  \end{description}%
18543
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   123
\end{isamarkuptext}%
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   124
\isamarkuptrue%
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   125
%
24089
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   126
\isamarkupsection{Thread-safe programming%
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   127
}
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   128
\isamarkuptrue%
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   129
%
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   130
\begin{isamarkuptext}%
29160
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   131
Recent versions of Poly/ML (5.2.1 or later) support robust
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   132
  multithreaded execution, based on native operating system threads of
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   133
  the underlying platform.  Thus threads will actually be executed in
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   134
  parallel on multi-core systems.  A speedup-factor of approximately
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   135
  1.5--3 can be expected on a regular 4-core machine.\footnote{There
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   136
  is some inherent limitation of the speedup factor due to garbage
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   137
  collection, which is still sequential.  It helps to provide initial
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   138
  heap space generously, using the \texttt{-H} option of Poly/ML.}
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   139
  Threads also help to organize advanced operations of the system,
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   140
  with explicit communication between sub-components, real-time
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   141
  conditions, time-outs etc.
24089
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   142
29160
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   143
  Threads lack the memory protection of separate processes, and
24089
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   144
  operate concurrently on shared heap memory.  This has the advantage
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   145
  that results of independent computations are immediately available
29160
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   146
  to other threads, without requiring untyped character streams,
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   147
  awkward serialization etc.
24089
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   148
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   149
  On the other hand, some programming guidelines need to be observed
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   150
  in order to make unprotected parallelism work out smoothly.  While
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   151
  the ML system implementation is responsible to maintain basic
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   152
  integrity of the representation of ML values in memory, the
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   153
  application programmer needs to ensure that multithreaded execution
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   154
  does not break the intended semantics.
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   155
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   156
  \medskip \paragraph{Critical shared resources.} Actually only those
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   157
  parts outside the purely functional world of ML are critical.  In
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   158
  particular, this covers
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   159
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   160
  \begin{itemize}
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   161
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   162
  \item global references (or arrays), i.e.\ those that persist over
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   163
  several invocations of associated operations,\footnote{This is
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   164
  independent of the visibility of such mutable values in the toplevel
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   165
  scope.}
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   166
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   167
  \item direct I/O on shared channels, notably \isa{stdin}, \isa{stdout}, \isa{stderr}.
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   168
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   169
  \end{itemize}
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   170
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   171
  The majority of tools implemented within the Isabelle/Isar framework
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   172
  will not require any of these critical elements: nothing special
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   173
  needs to be observed when staying in the purely functional fragment
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   174
  of ML.  Note that output via the official Isabelle channels does not
29160
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   175
  count as direct I/O, so the operations \verb|writeln|, \verb|warning|, \verb|tracing| etc.\ are safe.
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   176
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   177
  Moreover, ML bindings within the toplevel environment (\verb|type|, \verb|val|, \verb|structure| etc.) due to
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   178
  run-time invocation of the compiler are also safe, because
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   179
  Isabelle/Isar manages this as part of the theory or proof context.
24089
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   180
29160
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   181
  \paragraph{Multithreading in Isabelle/Isar.}  The theory loader
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   182
  automatically exploits the overall parallelism of independent nodes
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   183
  in the development graph, as well as the inherent irrelevance of
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   184
  proofs for goals being fully specified in advance.  This means,
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   185
  checking of individual Isar proofs is parallelized by default.
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   186
  Beyond that, very sophisticated proof tools may use local
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   187
  parallelism internally, via the general programming model of
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   188
  ``future values'' (see also \hyperlink{file.~~/src/Pure/Concurrent/future.ML}{\mbox{\isa{\isatt{{\isachartilde}{\isachartilde}{\isacharslash}src{\isacharslash}Pure{\isacharslash}Concurrent{\isacharslash}future{\isachardot}ML}}}}).
24089
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   189
29160
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   190
  Any ML code that works relatively to the present background theory
24089
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   191
  is already safe.  Contextual data may be easily stored within the
24090
wenzelm
parents: 24089
diff changeset
   192
  theory or proof context, thanks to the generic data concept of
wenzelm
parents: 24089
diff changeset
   193
  Isabelle/Isar (see \secref{sec:context-data}).  This greatly
24089
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   194
  diminishes the demand for global state information in the first
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   195
  place.
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   196
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   197
  \medskip In rare situations where actual mutable content needs to be
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   198
  manipulated, Isabelle provides a single \emph{critical section} that
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   199
  may be entered while preventing any other thread from doing the
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   200
  same.  Entering the critical section without contention is very
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   201
  fast, and several basic system operations do so frequently.  This
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   202
  also means that each thread should leave the critical section
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   203
  quickly, otherwise parallel execution performance may degrade
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   204
  significantly.
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   205
29160
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   206
  Despite this potential bottle-neck, centralized locking is
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   207
  convenient, because it prevents deadlocks without demanding special
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   208
  precautions.  Explicit communication demands other means, though.
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   209
  The high-level abstraction of synchronized variables \hyperlink{file.~~/src/Pure/Concurrent/synchronized.ML}{\mbox{\isa{\isatt{{\isachartilde}{\isachartilde}{\isacharslash}src{\isacharslash}Pure{\isacharslash}Concurrent{\isacharslash}synchronized{\isachardot}ML}}}} enables parallel
86e9f91a0ba4 updated generated file;
wenzelm
parents: 29008
diff changeset
   210
  components to communicate via shared state; see also \hyperlink{file.~~/src/Pure/Concurrent/mailbox.ML}{\mbox{\isa{\isatt{{\isachartilde}{\isachartilde}{\isacharslash}src{\isacharslash}Pure{\isacharslash}Concurrent{\isacharslash}mailbox{\isachardot}ML}}}} as canonical example.
24089
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   211
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   212
  \paragraph{Good conduct of impure programs.} The following
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   213
  guidelines enable non-functional programs to participate in
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   214
  multithreading.
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   215
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   216
  \begin{itemize}
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   217
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   218
  \item Minimize global state information.  Using proper theory and
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   219
  proof context data will actually return to functional update of
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   220
  values, without any special precautions for multithreading.  Apart
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   221
  from the fully general functors for theory and proof data (see
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   222
  \secref{sec:context-data}) there are drop-in replacements that
24090
wenzelm
parents: 24089
diff changeset
   223
  emulate primitive references for common cases of \emph{configuration
24110
4ab3084e311c tuned config options: eliminated separate attribute "option";
wenzelm
parents: 24090
diff changeset
   224
  options} for type \verb|bool|/\verb|int|/\verb|string| (see structure \verb|Config| and \verb|Attrib.config_bool| etc.), and lists of theorems (see functor
36164
532f4d1cb0fc salvaged some ML functors from decay, which is the natural consequence of lack of formal checking;
wenzelm
parents: 36134
diff changeset
   225
  \verb|Named_Thms|).
24089
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   226
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   227
  \item Keep components with local state information
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   228
  \emph{re-entrant}.  Instead of poking initial values into (private)
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   229
  global references, create a new state record on each invocation, and
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   230
  pass that through any auxiliary functions of the component.  The
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   231
  state record may well contain mutable references, without requiring
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   232
  any special synchronizations, as long as each invocation sees its
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   233
  own copy.  Occasionally, one might even return to plain functional
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   234
  updates on non-mutable record values here.
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   235
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   236
  \item Isolate process configuration flags.  The main legitimate
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   237
  application of global references is to configure the whole process
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   238
  in a certain way, essentially affecting all threads.  A typical
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   239
  example is the \verb|show_types| flag, which tells the pretty printer
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   240
  to output explicit type information for terms.  Such flags usually
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   241
  do not affect the functionality of the core system, but only the
24090
wenzelm
parents: 24089
diff changeset
   242
  view being presented to the user.
24089
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   243
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   244
  Occasionally, such global process flags are treated like implicit
33174
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 32836
diff changeset
   245
  arguments to certain operations, by using the \verb|setmp_CRITICAL| combinator
24090
wenzelm
parents: 24089
diff changeset
   246
  for safe temporary assignment.  Its traditional purpose was to
wenzelm
parents: 24089
diff changeset
   247
  ensure proper recovery of the original value when exceptions are
wenzelm
parents: 24089
diff changeset
   248
  raised in the body, now the functionality is extended to enter the
wenzelm
parents: 24089
diff changeset
   249
  \emph{critical section} (with its usual potential of degrading
wenzelm
parents: 24089
diff changeset
   250
  parallelism).
24089
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   251
33174
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 32836
diff changeset
   252
  Note that recovery of plain value passing semantics via \verb|setmp_CRITICAL|~\isa{ref\ value} assumes that this \isa{ref} is
24089
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   253
  exclusively manipulated within the critical section.  In particular,
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   254
  any persistent global assignment of \isa{ref\ {\isacharcolon}{\isacharequal}\ value} needs to
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   255
  be marked critical as well, to prevent intruding another threads
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   256
  local view, and a lost-update in the global scope, too.
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   257
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   258
  \end{itemize}
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   259
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   260
  Recall that in an open ``LCF-style'' system like Isabelle/Isar, the
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   261
  user participates in constructing the overall environment.  This
24090
wenzelm
parents: 24089
diff changeset
   262
  means that state-based facilities offered by one component will
wenzelm
parents: 24089
diff changeset
   263
  require special caution later on.  So minimizing critical elements,
wenzelm
parents: 24089
diff changeset
   264
  by staying within the plain value-oriented view relative to theory
wenzelm
parents: 24089
diff changeset
   265
  or proof contexts most of the time, will also reduce the chance of
24089
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   266
  mishaps occurring to end-users.%
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   267
\end{isamarkuptext}%
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   268
\isamarkuptrue%
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   269
%
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   270
\isadelimmlref
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   271
%
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   272
\endisadelimmlref
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   273
%
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   274
\isatagmlref
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   275
%
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   276
\begin{isamarkuptext}%
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   277
\begin{mldecls}
30121
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   278
  \indexdef{}{ML}{NAMED\_CRITICAL}\verb|NAMED_CRITICAL: string -> (unit -> 'a) -> 'a| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   279
  \indexdef{}{ML}{CRITICAL}\verb|CRITICAL: (unit -> 'a) -> 'a| \\
33174
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 32836
diff changeset
   280
  \indexdef{}{ML}{setmp\_CRITICAL}\verb|setmp_CRITICAL: 'a Unsynchronized.ref -> 'a -> ('b -> 'c) -> 'b -> 'c| \\
24089
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   281
  \end{mldecls}
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   282
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   283
  \begin{description}
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   284
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   285
  \item \verb|NAMED_CRITICAL|~\isa{name\ f} evaluates \isa{f\ {\isacharparenleft}{\isacharparenright}}
24090
wenzelm
parents: 24089
diff changeset
   286
  while staying within the critical section of Isabelle/Isar.  No
wenzelm
parents: 24089
diff changeset
   287
  other thread may do so at the same time, but non-critical parallel
wenzelm
parents: 24089
diff changeset
   288
  execution will continue.  The \isa{name} argument serves for
wenzelm
parents: 24089
diff changeset
   289
  diagnostic purposes and might help to spot sources of congestion.
24089
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   290
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   291
  \item \verb|CRITICAL| is the same as \verb|NAMED_CRITICAL| with empty
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   292
  name argument.
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   293
33174
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 32836
diff changeset
   294
  \item \verb|setmp_CRITICAL|~\isa{ref\ value\ f\ x} evaluates \isa{f\ x}
24089
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   295
  while staying within the critical section and having \isa{ref\ {\isacharcolon}{\isacharequal}\ value} assigned temporarily.  This recovers a value-passing
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   296
  semantics involving global references, regardless of exceptions or
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   297
  concurrency.
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   298
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   299
  \end{description}%
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   300
\end{isamarkuptext}%
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   301
\isamarkuptrue%
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   302
%
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   303
\endisatagmlref
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   304
{\isafoldmlref}%
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   305
%
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   306
\isadelimmlref
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   307
%
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   308
\endisadelimmlref
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   309
%
18543
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   310
\isamarkupchapter{Basic library functions%
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   311
}
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   312
\isamarkuptrue%
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   313
%
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   314
\begin{isamarkuptext}%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   315
Beyond the proposal of the SML/NJ basis library, Isabelle comes
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   316
  with its own library, from which selected parts are given here.
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   317
  These should encourage a study of the Isabelle sources,
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   318
  in particular files \emph{Pure/library.ML} and \emph{Pure/General/*.ML}.%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   319
\end{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   320
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   321
%
29647
12070638fe29 updated generated file;
wenzelm
parents: 29612
diff changeset
   322
\isamarkupsection{Linear transformations \label{sec:ML-linear-trans}%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   323
}
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   324
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   325
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   326
\isadelimmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   327
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   328
\endisadelimmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   329
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   330
\isatagmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   331
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   332
\begin{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   333
\begin{mldecls}
30121
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   334
  \indexdef{}{ML}{op $\mid$$>$ }\verb|op |\verb,|,\verb|> : 'a * ('a -> 'b) -> 'b| \\
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   335
  \end{mldecls}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   336
\end{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   337
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   338
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   339
\endisatagmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   340
{\isafoldmlref}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   341
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   342
\isadelimmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   343
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   344
\endisadelimmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   345
%
22322
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   346
\isadelimML
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   347
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   348
\endisadelimML
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   349
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   350
\isatagML
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   351
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   352
\endisatagML
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   353
{\isafoldML}%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   354
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   355
\isadelimML
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   356
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   357
\endisadelimML
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   358
%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   359
\begin{isamarkuptext}%
26460
21504de31197 some styling
haftmann
parents: 26459
diff changeset
   360
\noindent Many problems in functional programming can be thought of
22322
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   361
  as linear transformations, i.e.~a caluclation starts with a
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   362
  particular value \verb|x : foo| which is then transformed
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   363
  by application of a function \verb|f : foo -> foo|,
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   364
  continued by an application of a function \verb|g : foo -> bar|,
25151
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   365
  and so on.  As a canoncial example, take functions enriching
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   366
  a theory by constant declararion and primitive definitions:
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   367
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   368
  \smallskip\begin{mldecls}
33174
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 32836
diff changeset
   369
  \verb|Sign.declare_const: (binding * typ) * mixfix|\isasep\isanewline%
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   370
\verb|  -> theory -> term * theory| \\
36134
c210a8fda4c5 updated Thm.add_axiom/add_def;
wenzelm
parents: 33174
diff changeset
   371
  \verb|Thm.add_def: bool -> bool -> binding * term -> theory -> (string * thm) * theory|
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   372
  \end{mldecls}
25151
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   373
26460
21504de31197 some styling
haftmann
parents: 26459
diff changeset
   374
  \noindent Written with naive application, an addition of constant
25151
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   375
  \isa{bar} with type \isa{foo\ {\isasymRightarrow}\ foo} and
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   376
  a corresponding definition \isa{bar\ {\isasymequiv}\ {\isasymlambda}x{\isachardot}\ x} would look like:
25151
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   377
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   378
  \smallskip\begin{mldecls}
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   379
  \verb|(fn (t, thy) => Thm.add_def false false|\isasep\isanewline%
29612
4f68e0f8f4fd binding replaces bstring
haftmann
parents: 29581
diff changeset
   380
\verb|  (Binding.name "bar_def", Logic.mk_equals (t, @{term "%x. x"})) thy)|\isasep\isanewline%
33174
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 32836
diff changeset
   381
\verb|    (Sign.declare_const|\isasep\isanewline%
29008
d863c103ded0 adapted to changes in binding module
haftmann
parents: 28283
diff changeset
   382
\verb|      ((Binding.name "bar", @{typ "foo => foo"}), NoSyn) thy)|
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   383
  \end{mldecls}
25151
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   384
26460
21504de31197 some styling
haftmann
parents: 26459
diff changeset
   385
  \noindent With increasing numbers of applications, this code gets quite
25151
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   386
  unreadable.  Further, it is unintuitive that things are
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   387
  written down in the opposite order as they actually ``happen''.%
22322
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   388
\end{isamarkuptext}%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   389
\isamarkuptrue%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   390
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   391
\begin{isamarkuptext}%
25151
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   392
\noindent At this stage, Isabelle offers some combinators which allow
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   393
  for more convenient notation, most notably reverse application:
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   394
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   395
  \smallskip\begin{mldecls}
22322
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   396
\verb|thy|\isasep\isanewline%
33174
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 32836
diff changeset
   397
\verb||\verb,|,\verb|> Sign.declare_const ((Binding.name "bar", @{typ "foo => foo"}), NoSyn)|\isasep\isanewline%
25151
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   398
\verb||\verb,|,\verb|> (fn (t, thy) => thy|\isasep\isanewline%
25608
7793d6423d01 adjusted
haftmann
parents: 25185
diff changeset
   399
\verb||\verb,|,\verb|> Thm.add_def false false|\isasep\isanewline%
29612
4f68e0f8f4fd binding replaces bstring
haftmann
parents: 29581
diff changeset
   400
\verb|     (Binding.name "bar_def", Logic.mk_equals (t, @{term "%x. x"})))|
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   401
  \end{mldecls}%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   402
\end{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   403
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   404
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   405
\isadelimmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   406
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   407
\endisadelimmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   408
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   409
\isatagmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   410
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   411
\begin{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   412
\begin{mldecls}
30121
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   413
  \indexdef{}{ML}{op $\mid$-$>$ }\verb|op |\verb,|,\verb|-> : ('c * 'a) * ('c -> 'a -> 'b) -> 'b| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   414
  \indexdef{}{ML}{op $\mid$$>$$>$ }\verb|op |\verb,|,\verb|>> : ('a * 'c) * ('a -> 'b) -> 'b * 'c| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   415
  \indexdef{}{ML}{op $\mid$$\mid$$>$ }\verb|op |\verb,|,\verb||\verb,|,\verb|> : ('c * 'a) * ('a -> 'b) -> 'c * 'b| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   416
  \indexdef{}{ML}{op $\mid$$\mid$$>$$>$ }\verb|op |\verb,|,\verb||\verb,|,\verb|>> : ('c * 'a) * ('a -> 'd * 'b) -> ('c * 'd) * 'b| \\
25151
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   417
  \end{mldecls}%
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   418
\end{isamarkuptext}%
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   419
\isamarkuptrue%
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   420
%
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   421
\endisatagmlref
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   422
{\isafoldmlref}%
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   423
%
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   424
\isadelimmlref
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   425
%
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   426
\endisadelimmlref
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   427
%
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   428
\begin{isamarkuptext}%
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   429
\noindent Usually, functions involving theory updates also return
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   430
  side results; to use these conveniently, yet another
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   431
  set of combinators is at hand, most notably \verb|op |\verb,|,\verb|->|
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   432
  which allows curried access to side results:
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   433
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   434
  \smallskip\begin{mldecls}
25151
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   435
\verb|thy|\isasep\isanewline%
33174
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 32836
diff changeset
   436
\verb||\verb,|,\verb|> Sign.declare_const ((Binding.name "bar", @{typ "foo => foo"}), NoSyn)|\isasep\isanewline%
25608
7793d6423d01 adjusted
haftmann
parents: 25185
diff changeset
   437
\verb||\verb,|,\verb|-> (fn t => Thm.add_def false false|\isasep\isanewline%
29612
4f68e0f8f4fd binding replaces bstring
haftmann
parents: 29581
diff changeset
   438
\verb|      (Binding.name "bar_def", Logic.mk_equals (t, @{term "%x. x"})))|\isasep\isanewline%
25151
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   439
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   440
  \end{mldecls}
25151
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   441
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   442
  \noindent \verb|op |\verb,|,\verb|>>| allows for processing side results on their own:
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   443
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   444
  \smallskip\begin{mldecls}
25151
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   445
\verb|thy|\isasep\isanewline%
33174
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 32836
diff changeset
   446
\verb||\verb,|,\verb|> Sign.declare_const ((Binding.name "bar", @{typ "foo => foo"}), NoSyn)|\isasep\isanewline%
25151
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   447
\verb||\verb,|,\verb|>> (fn t => Logic.mk_equals (t, @{term "%x. x"}))|\isasep\isanewline%
29612
4f68e0f8f4fd binding replaces bstring
haftmann
parents: 29581
diff changeset
   448
\verb||\verb,|,\verb|-> (fn def => Thm.add_def false false (Binding.name "bar_def", def))|\isasep\isanewline%
25151
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   449
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   450
  \end{mldecls}
25151
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   451
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   452
  \noindent Orthogonally, \verb|op |\verb,|,\verb||\verb,|,\verb|>| applies a transformation
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   453
  in the presence of side results which are left unchanged:
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   454
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   455
  \smallskip\begin{mldecls}
25151
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   456
\verb|thy|\isasep\isanewline%
33174
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 32836
diff changeset
   457
\verb||\verb,|,\verb|> Sign.declare_const ((Binding.name "bar", @{typ "foo => foo"}), NoSyn)|\isasep\isanewline%
25151
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   458
\verb||\verb,|,\verb||\verb,|,\verb|> Sign.add_path "foobar"|\isasep\isanewline%
25608
7793d6423d01 adjusted
haftmann
parents: 25185
diff changeset
   459
\verb||\verb,|,\verb|-> (fn t => Thm.add_def false false|\isasep\isanewline%
29612
4f68e0f8f4fd binding replaces bstring
haftmann
parents: 29581
diff changeset
   460
\verb|      (Binding.name "bar_def", Logic.mk_equals (t, @{term "%x. x"})))|\isasep\isanewline%
25151
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   461
\verb||\verb,|,\verb||\verb,|,\verb|> Sign.restore_naming thy|\isasep\isanewline%
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   462
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   463
  \end{mldecls}
25151
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   464
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   465
  \noindent \verb|op |\verb,|,\verb||\verb,|,\verb|>>| accumulates side results:
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   466
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   467
  \smallskip\begin{mldecls}
25151
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   468
\verb|thy|\isasep\isanewline%
33174
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 32836
diff changeset
   469
\verb||\verb,|,\verb|> Sign.declare_const ((Binding.name "bar", @{typ "foo => foo"}), NoSyn)|\isasep\isanewline%
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 32836
diff changeset
   470
\verb||\verb,|,\verb||\verb,|,\verb|>> Sign.declare_const ((Binding.name "foobar", @{typ "foo => foo"}), NoSyn)|\isasep\isanewline%
25608
7793d6423d01 adjusted
haftmann
parents: 25185
diff changeset
   471
\verb||\verb,|,\verb|-> (fn (t1, t2) => Thm.add_def false false|\isasep\isanewline%
29612
4f68e0f8f4fd binding replaces bstring
haftmann
parents: 29581
diff changeset
   472
\verb|      (Binding.name "bar_def", Logic.mk_equals (t1, t2)))|\isasep\isanewline%
25151
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   473
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   474
  \end{mldecls}%
25151
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   475
\end{isamarkuptext}%
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   476
\isamarkuptrue%
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   477
%
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   478
\isadelimmlref
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   479
%
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   480
\endisadelimmlref
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   481
%
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   482
\isatagmlref
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   483
%
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   484
\begin{isamarkuptext}%
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   485
\begin{mldecls}
30121
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   486
  \indexdef{}{ML}{fold}\verb|fold: ('a -> 'b -> 'b) -> 'a list -> 'b -> 'b| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   487
  \indexdef{}{ML}{fold\_map}\verb|fold_map: ('a -> 'b -> 'c * 'b) -> 'a list -> 'b -> 'c list * 'b| \\
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   488
  \end{mldecls}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   489
\end{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   490
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   491
%
22322
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   492
\endisatagmlref
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   493
{\isafoldmlref}%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   494
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   495
\isadelimmlref
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   496
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   497
\endisadelimmlref
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   498
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   499
\begin{isamarkuptext}%
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   500
\noindent This principles naturally lift to \emph{lists} using
25151
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   501
  the \verb|fold| and \verb|fold_map| combinators.
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   502
  The first lifts a single function
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   503
  \begin{quote}\footnotesize
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   504
    \verb|f : 'a -> 'b -> 'b| to \verb|'a list -> 'b -> 'b|
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   505
  \end{quote}
25151
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   506
  such that
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   507
  \begin{quote}\footnotesize
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   508
    \verb|y |\verb,|,\verb|> fold f [x1, x2, ..., x_n]| \\
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   509
    \hspace*{2ex}\isa{{\isasymleadsto}} \verb|y |\verb,|,\verb|> f x1 |\verb,|,\verb|> f x2 |\verb,|,\verb|> ... |\verb,|,\verb|> f x_n|
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   510
  \end{quote}
26460
21504de31197 some styling
haftmann
parents: 26459
diff changeset
   511
  \noindent The second accumulates side results in a list by lifting
25151
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   512
  a single function
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   513
  \begin{quote}\footnotesize
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   514
    \verb|f : 'a -> 'b -> 'c * 'b| to \verb|'a list -> 'b -> 'c list * 'b|
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   515
  \end{quote}
25151
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   516
  such that
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   517
  \begin{quote}\footnotesize
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   518
    \verb|y |\verb,|,\verb|> fold_map f [x1, x2, ..., x_n]| \\
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   519
    \hspace*{2ex}\isa{{\isasymleadsto}} \verb|y |\verb,|,\verb|> f x1 |\verb,|,\verb||\verb,|,\verb|>> f x2 |\verb,|,\verb||\verb,|,\verb|>> ... |\verb,|,\verb||\verb,|,\verb|>> f x_n| \\
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   520
    \hspace*{6ex}\verb||\verb,|,\verb||\verb,|,\verb|> (fn ((z1, z2), ..., z_n) => [z1, z2, ..., z_n])|
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   521
  \end{quote}
25185
762ed22d15c7 continued
haftmann
parents: 25151
diff changeset
   522
  
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   523
  \noindent Example:
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   524
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   525
  \smallskip\begin{mldecls}
25185
762ed22d15c7 continued
haftmann
parents: 25151
diff changeset
   526
\verb|let|\isasep\isanewline%
762ed22d15c7 continued
haftmann
parents: 25151
diff changeset
   527
\verb|  val consts = ["foo", "bar"];|\isasep\isanewline%
762ed22d15c7 continued
haftmann
parents: 25151
diff changeset
   528
\verb|in|\isasep\isanewline%
762ed22d15c7 continued
haftmann
parents: 25151
diff changeset
   529
\verb|  thy|\isasep\isanewline%
33174
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 32836
diff changeset
   530
\verb|  |\verb,|,\verb|> fold_map (fn const => Sign.declare_const|\isasep\isanewline%
29008
d863c103ded0 adapted to changes in binding module
haftmann
parents: 28283
diff changeset
   531
\verb|       ((Binding.name const, @{typ "foo => foo"}), NoSyn)) consts|\isasep\isanewline%
25185
762ed22d15c7 continued
haftmann
parents: 25151
diff changeset
   532
\verb|  |\verb,|,\verb|>> map (fn t => Logic.mk_equals (t, @{term "%x. x"}))|\isasep\isanewline%
762ed22d15c7 continued
haftmann
parents: 25151
diff changeset
   533
\verb|  |\verb,|,\verb|-> (fn defs => fold_map (fn def =>|\isasep\isanewline%
29612
4f68e0f8f4fd binding replaces bstring
haftmann
parents: 29581
diff changeset
   534
\verb|       Thm.add_def false false (Binding.empty, def)) defs)|\isasep\isanewline%
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   535
\verb|end|
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   536
  \end{mldecls}%
22322
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   537
\end{isamarkuptext}%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   538
\isamarkuptrue%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   539
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   540
\isadelimmlref
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   541
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   542
\endisadelimmlref
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   543
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   544
\isatagmlref
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   545
%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   546
\begin{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   547
\begin{mldecls}
30121
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   548
  \indexdef{}{ML}{op \#$>$ }\verb|op #> : ('a -> 'b) * ('b -> 'c) -> 'a -> 'c| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   549
  \indexdef{}{ML}{op \#-$>$ }\verb|op #-> : ('a -> 'c * 'b) * ('c -> 'b -> 'd) -> 'a -> 'd| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   550
  \indexdef{}{ML}{op \#$>$$>$ }\verb|op #>> : ('a -> 'c * 'b) * ('c -> 'd) -> 'a -> 'd * 'b| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   551
  \indexdef{}{ML}{op \#\#$>$ }\verb|op ##> : ('a -> 'c * 'b) * ('b -> 'd) -> 'a -> 'c * 'd| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   552
  \indexdef{}{ML}{op \#\#$>$$>$ }\verb|op ##>> : ('a -> 'c * 'b) * ('b -> 'e * 'd) -> 'a -> ('c * 'e) * 'd| \\
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   553
  \end{mldecls}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   554
\end{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   555
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   556
%
22322
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   557
\endisatagmlref
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   558
{\isafoldmlref}%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   559
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   560
\isadelimmlref
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   561
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   562
\endisadelimmlref
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   563
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   564
\begin{isamarkuptext}%
22550
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   565
\noindent All those linear combinators also exist in higher-order
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   566
  variants which do not expect a value on the left hand side
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   567
  but a function.%
22322
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   568
\end{isamarkuptext}%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   569
\isamarkuptrue%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   570
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   571
\isadelimmlref
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   572
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   573
\endisadelimmlref
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   574
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   575
\isatagmlref
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   576
%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   577
\begin{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   578
\begin{mldecls}
30121
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   579
  \indexdef{}{ML}{op ` }\verb|op ` : ('b -> 'a) -> 'b -> 'a * 'b| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   580
  \indexdef{}{ML}{tap}\verb|tap: ('b -> 'a) -> 'b -> 'b| \\
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   581
  \end{mldecls}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   582
\end{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   583
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   584
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   585
\endisatagmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   586
{\isafoldmlref}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   587
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   588
\isadelimmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   589
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   590
\endisadelimmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   591
%
22550
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   592
\begin{isamarkuptext}%
25185
762ed22d15c7 continued
haftmann
parents: 25151
diff changeset
   593
\noindent These operators allow to ``query'' a context
762ed22d15c7 continued
haftmann
parents: 25151
diff changeset
   594
  in a series of context transformations:
762ed22d15c7 continued
haftmann
parents: 25151
diff changeset
   595
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   596
  \smallskip\begin{mldecls}
25185
762ed22d15c7 continued
haftmann
parents: 25151
diff changeset
   597
\verb|thy|\isasep\isanewline%
762ed22d15c7 continued
haftmann
parents: 25151
diff changeset
   598
\verb||\verb,|,\verb|> tap (fn _ => writeln "now adding constant")|\isasep\isanewline%
33174
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 32836
diff changeset
   599
\verb||\verb,|,\verb|> Sign.declare_const ((Binding.name "bar", @{typ "foo => foo"}), NoSyn)|\isasep\isanewline%
25185
762ed22d15c7 continued
haftmann
parents: 25151
diff changeset
   600
\verb||\verb,|,\verb||\verb,|,\verb|>> `(fn thy => Sign.declared_const thy|\isasep\isanewline%
29008
d863c103ded0 adapted to changes in binding module
haftmann
parents: 28283
diff changeset
   601
\verb|         (Sign.full_name thy (Binding.name "foobar")))|\isasep\isanewline%
25185
762ed22d15c7 continued
haftmann
parents: 25151
diff changeset
   602
\verb||\verb,|,\verb|-> (fn (t, b) => if b then I|\isasep\isanewline%
33174
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 32836
diff changeset
   603
\verb|       else Sign.declare_const|\isasep\isanewline%
29008
d863c103ded0 adapted to changes in binding module
haftmann
parents: 28283
diff changeset
   604
\verb|         ((Binding.name "foobar", @{typ "foo => foo"}), NoSyn) #> snd)|\isasep\isanewline%
25185
762ed22d15c7 continued
haftmann
parents: 25151
diff changeset
   605
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   606
  \end{mldecls}%
22550
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   607
\end{isamarkuptext}%
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   608
\isamarkuptrue%
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   609
%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   610
\isamarkupsection{Options and partiality%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   611
}
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   612
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   613
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   614
\isadelimmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   615
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   616
\endisadelimmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   617
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   618
\isatagmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   619
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   620
\begin{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   621
\begin{mldecls}
30121
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   622
  \indexdef{}{ML}{is\_some}\verb|is_some: 'a option -> bool| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   623
  \indexdef{}{ML}{is\_none}\verb|is_none: 'a option -> bool| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   624
  \indexdef{}{ML}{the}\verb|the: 'a option -> 'a| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   625
  \indexdef{}{ML}{these}\verb|these: 'a list option -> 'a list| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   626
  \indexdef{}{ML}{the\_list}\verb|the_list: 'a option -> 'a list| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   627
  \indexdef{}{ML}{the\_default}\verb|the_default: 'a -> 'a option -> 'a| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   628
  \indexdef{}{ML}{try}\verb|try: ('a -> 'b) -> 'a -> 'b option| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   629
  \indexdef{}{ML}{can}\verb|can: ('a -> 'b) -> 'a -> bool| \\
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   630
  \end{mldecls}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   631
\end{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   632
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   633
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   634
\endisatagmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   635
{\isafoldmlref}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   636
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   637
\isadelimmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   638
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   639
\endisadelimmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   640
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   641
\begin{isamarkuptext}%
24089
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   642
Standard selector functions on \isa{option}s are provided.  The
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   643
  \verb|try| and \verb|can| functions provide a convenient interface for
26459
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   644
  handling exceptions -- both take as arguments a function \verb|f|
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   645
  together with a parameter \verb|x| and handle any exception during
bb0e729be5a4 some styling
haftmann
parents: 26437
diff changeset
   646
  the evaluation of the application of \verb|f| to \verb|x|, either
24089
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   647
  return a lifted result (\verb|NONE| on failure) or a boolean value
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   648
  (\verb|false| on failure).%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   649
\end{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   650
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   651
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   652
\isamarkupsection{Common data structures%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   653
}
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   654
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   655
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   656
\isamarkupsubsection{Lists (as set-like data structures)%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   657
}
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   658
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   659
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   660
\begin{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   661
\begin{mldecls}
30121
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   662
  \indexdef{}{ML}{member}\verb|member: ('b * 'a -> bool) -> 'a list -> 'b -> bool| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   663
  \indexdef{}{ML}{insert}\verb|insert: ('a * 'a -> bool) -> 'a -> 'a list -> 'a list| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   664
  \indexdef{}{ML}{remove}\verb|remove: ('b * 'a -> bool) -> 'b -> 'a list -> 'a list| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   665
  \indexdef{}{ML}{merge}\verb|merge: ('a * 'a -> bool) -> 'a list * 'a list -> 'a list| \\
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   666
  \end{mldecls}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   667
\end{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   668
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   669
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   670
\begin{isamarkuptext}%
22503
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   671
Lists are often used as set-like data structures -- set-like in
25151
9374a0df240c continued
haftmann
parents: 24110
diff changeset
   672
  the sense that they support a notion of \verb|member|-ship,
22503
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   673
  \verb|insert|-ing and \verb|remove|-ing, but are order-sensitive.
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   674
  This is convenient when implementing a history-like mechanism:
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   675
  \verb|insert| adds an element \emph{to the front} of a list,
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   676
  if not yet present; \verb|remove| removes \emph{all} occurences
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   677
  of a particular element.  Correspondingly \verb|merge| implements a 
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   678
  a merge on two lists suitable for merges of context data
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   679
  (\secref{sec:context-theory}).
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   680
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   681
  Functions are parametrized by an explicit equality function
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   682
  to accomplish overloaded equality;  in most cases of monomorphic
24089
070d539ba403 tuned section "Style";
wenzelm
parents: 23653
diff changeset
   683
  equality, writing \verb|op =| should suffice.%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   684
\end{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   685
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   686
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   687
\isamarkupsubsection{Association lists%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   688
}
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   689
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   690
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   691
\begin{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   692
\begin{mldecls}
30121
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   693
  \indexdef{}{ML exception}{AList.DUP}\verb|exception AList.DUP| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   694
  \indexdef{}{ML}{AList.lookup}\verb|AList.lookup: ('a * 'b -> bool) -> ('b * 'c) list -> 'a -> 'c option| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   695
  \indexdef{}{ML}{AList.defined}\verb|AList.defined: ('a * 'b -> bool) -> ('b * 'c) list -> 'a -> bool| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   696
  \indexdef{}{ML}{AList.update}\verb|AList.update: ('a * 'a -> bool) -> ('a * 'b) -> ('a * 'b) list -> ('a * 'b) list| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   697
  \indexdef{}{ML}{AList.default}\verb|AList.default: ('a * 'a -> bool) -> ('a * 'b) -> ('a * 'b) list -> ('a * 'b) list| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   698
  \indexdef{}{ML}{AList.delete}\verb|AList.delete: ('a * 'b -> bool) -> 'a -> ('b * 'c) list -> ('b * 'c) list| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   699
  \indexdef{}{ML}{AList.map\_entry}\verb|AList.map_entry: ('a * 'b -> bool) -> 'a|\isasep\isanewline%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   700
\verb|    -> ('c -> 'c) -> ('b * 'c) list -> ('b * 'c) list| \\
30121
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   701
  \indexdef{}{ML}{AList.map\_default}\verb|AList.map_default: ('a * 'a -> bool) -> 'a * 'b -> ('b -> 'b)|\isasep\isanewline%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   702
\verb|    -> ('a * 'b) list -> ('a * 'b) list| \\
30121
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   703
  \indexdef{}{ML}{AList.join}\verb|AList.join: ('a * 'a -> bool) -> ('a -> 'b * 'b -> 'b) (*exception DUP*)|\isasep\isanewline%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   704
\verb|    -> ('a * 'b) list * ('a * 'b) list -> ('a * 'b) list (*exception AList.DUP*)| \\
30121
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   705
  \indexdef{}{ML}{AList.merge}\verb|AList.merge: ('a * 'a -> bool) -> ('b * 'b -> bool)|\isasep\isanewline%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   706
\verb|    -> ('a * 'b) list * ('a * 'b) list -> ('a * 'b) list (*exception AList.DUP*)|
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   707
  \end{mldecls}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   708
\end{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   709
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   710
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   711
\begin{isamarkuptext}%
22503
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   712
Association lists can be seens as an extension of set-like lists:
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   713
  on the one hand, they may be used to implement finite mappings,
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   714
  on the other hand, they remain order-sensitive and allow for
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   715
  multiple key-value-pair with the same key: \verb|AList.lookup|
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   716
  returns the \emph{first} value corresponding to a particular
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   717
  key, if present.  \verb|AList.update| updates
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   718
  the \emph{first} occurence of a particular key; if no such
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   719
  key exists yet, the key-value-pair is added \emph{to the front}.
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   720
  \verb|AList.delete| only deletes the \emph{first} occurence of a key.
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   721
  \verb|AList.merge| provides an operation suitable for merges of context data
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   722
  (\secref{sec:context-theory}), where an equality parameter on
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   723
  values determines whether a merge should be considered a conflict.
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   724
  A slightly generalized operation if implementend by the \verb|AList.join|
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   725
  function which allows for explicit conflict resolution.%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   726
\end{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   727
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   728
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   729
\isamarkupsubsection{Tables%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   730
}
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   731
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   732
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   733
\begin{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   734
\begin{mldecls}
30121
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   735
  \indexdef{}{ML type}{'a Symtab.table}\verb|type 'a Symtab.table| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   736
  \indexdef{}{ML exception}{Symtab.DUP}\verb|exception Symtab.DUP of string| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   737
  \indexdef{}{ML exception}{Symtab.SAME}\verb|exception Symtab.SAME| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   738
  \indexdef{}{ML exception}{Symtab.UNDEF}\verb|exception Symtab.UNDEF of string| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   739
  \indexdef{}{ML}{Symtab.empty}\verb|Symtab.empty: 'a Symtab.table| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   740
  \indexdef{}{ML}{Symtab.lookup}\verb|Symtab.lookup: 'a Symtab.table -> string -> 'a option| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   741
  \indexdef{}{ML}{Symtab.defined}\verb|Symtab.defined: 'a Symtab.table -> string -> bool| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   742
  \indexdef{}{ML}{Symtab.update}\verb|Symtab.update: (string * 'a) -> 'a Symtab.table -> 'a Symtab.table| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   743
  \indexdef{}{ML}{Symtab.default}\verb|Symtab.default: string * 'a -> 'a Symtab.table -> 'a Symtab.table| \\
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   744
  \indexdef{}{ML}{Symtab.delete}\verb|Symtab.delete: string|\isasep\isanewline%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   745
\verb|    -> 'a Symtab.table -> 'a Symtab.table (*exception Symtab.UNDEF*)| \\
30121
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   746
  \indexdef{}{ML}{Symtab.map\_entry}\verb|Symtab.map_entry: string -> ('a -> 'a)|\isasep\isanewline%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   747
\verb|    -> 'a Symtab.table -> 'a Symtab.table| \\
30121
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   748
  \indexdef{}{ML}{Symtab.map\_default}\verb|Symtab.map_default: (string * 'a) -> ('a -> 'a)|\isasep\isanewline%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   749
\verb|    -> 'a Symtab.table -> 'a Symtab.table| \\
30121
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   750
  \indexdef{}{ML}{Symtab.join}\verb|Symtab.join: (string -> 'a * 'a -> 'a) (*exception Symtab.DUP/Symtab.SAME*)|\isasep\isanewline%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   751
\verb|    -> 'a Symtab.table * 'a Symtab.table|\isasep\isanewline%
23653
560f8f41ade2 updated;
wenzelm
parents: 22550
diff changeset
   752
\verb|    -> 'a Symtab.table (*exception Symtab.DUP*)| \\
30121
5c7bcb296600 updated generated files;
wenzelm
parents: 29756
diff changeset
   753
  \indexdef{}{ML}{Symtab.merge}\verb|Symtab.merge: ('a * 'a -> bool)|\isasep\isanewline%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   754
\verb|    -> 'a Symtab.table * 'a Symtab.table|\isasep\isanewline%
23653
560f8f41ade2 updated;
wenzelm
parents: 22550
diff changeset
   755
\verb|    -> 'a Symtab.table (*exception Symtab.DUP*)|
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   756
  \end{mldecls}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   757
\end{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   758
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   759
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   760
\begin{isamarkuptext}%
22503
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   761
Tables are an efficient representation of finite mappings without
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   762
  any notion of order;  due to their efficiency they should be used
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   763
  whenever such pure finite mappings are neccessary.
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   764
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   765
  The key type of tables must be given explicitly by instantiating
36164
532f4d1cb0fc salvaged some ML functors from decay, which is the natural consequence of lack of formal checking;
wenzelm
parents: 36134
diff changeset
   766
  the \verb|Table| functor which takes the key type
22503
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   767
  together with its \verb|order|; for convience, we restrict
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   768
  here to the \verb|Symtab| instance with \verb|string|
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   769
  as key type.
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   770
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   771
  Most table functions correspond to those of association lists.%
18543
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   772
\end{isamarkuptext}%
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   773
\isamarkuptrue%
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   774
%
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   775
\isadelimtheory
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   776
%
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   777
\endisadelimtheory
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   778
%
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   779
\isatagtheory
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   780
\isacommand{end}\isamarkupfalse%
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   781
%
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   782
\endisatagtheory
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   783
{\isafoldtheory}%
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   784
%
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   785
\isadelimtheory
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   786
%
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   787
\endisadelimtheory
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   788
\end{isabellebody}%
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   789
%%% Local Variables:
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   790
%%% mode: latex
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   791
%%% TeX-master: "root"
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   792
%%% End: