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