doc-src/IsarImplementation/Thy/document/ML.tex
author haftmann
Fri, 30 Mar 2007 16:18:59 +0200
changeset 22550 c5039bee2602
parent 22503 d53664118418
child 23653 560f8f41ade2
permissions -rw-r--r--
updated
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
%
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
    25
\begin{isamarkuptext}%
21501
8dab1e45c11f updated;
wenzelm
parents: 21172
diff changeset
    26
FIXME%
8dab1e45c11f updated;
wenzelm
parents: 21172
diff changeset
    27
\end{isamarkuptext}%
8dab1e45c11f updated;
wenzelm
parents: 21172
diff changeset
    28
\isamarkuptrue%
8dab1e45c11f updated;
wenzelm
parents: 21172
diff changeset
    29
%
8dab1e45c11f updated;
wenzelm
parents: 21172
diff changeset
    30
\begin{isamarkuptext}%
21148
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    31
This style guide is loosely based on
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    32
  \url{http://caml.inria.fr/resources/doc/guides/guidelines.en.html}.
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    33
%  FIMXE \url{http://www.cs.cornell.edu/Courses/cs312/2003sp/handouts/style.htm}
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    34
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    35
  Like any style guide, it should not be interpreted dogmatically.
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    36
  Instead, it forms a collection of recommendations which,
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    37
  if obeyed, result in code that is not considered to be
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    38
  obfuscated.  In certain cases, derivations are encouraged,
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    39
  as far as you know what you are doing.
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    40
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    41
  \begin{description}
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    42
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    43
    \item[fundamental law of programming]
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    44
      Whenever writing code, keep in mind: A program is
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    45
      written once, modified ten times, and read
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    46
      100 times.  So simplify its writing,
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    47
      always keep future modifications in mind,
21172
eea3c9048c7a updated;
wenzelm
parents: 21148
diff changeset
    48
      and never jeopardize readability.  Every second you hesitate
21148
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    49
      to spend on making your code more clear you will
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    50
      have to spend ten times understanding what you have
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    51
      written later on.
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    52
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    53
    \item[white space matters]
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    54
      Treat white space in your code as if it determines
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    55
      the meaning of code.
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    56
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    57
      \begin{itemize}
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    58
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    59
        \item The space bar is the easiest key to find on the keyboard,
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    60
          press it as often as necessary. {\ttfamily 2 + 2} is better
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    61
          than {\ttfamily 2+2}, likewise {\ttfamily f (x, y)}
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    62
          better than {\ttfamily f(x,y)}.
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    63
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    64
        \item Restrict your lines to \emph{at most} 80 characters.
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    65
          This will allow you to keep the beginning of a line
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    66
          in view while watching its end.
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    67
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    68
        \item Ban tabs; they are a context-sensitive formatting
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    69
          feature and likely to confuse anyone not using your
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    70
          favourite editor.
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    71
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    72
        \item Get rid of trailing whitespace.  Instead, do not
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    73
          surpess a trailing newline at the end of your files.
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    74
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    75
        \item Choose a generally accepted style of indentation,
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    76
          then use it systematically throughout the whole
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    77
          application.  An indentation of two spaces is appropriate.
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    78
          Avoid dangling indentation.
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    79
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    80
      \end{itemize}
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    81
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    82
    \item[cut-and-paste succeeds over copy-and-paste]
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    83
      \emph{Never} copy-and-paste code when programming.  If you
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    84
        need the same piece of code twice, introduce a
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    85
        reasonable auxiliary function (if there is no
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    86
        such function, very likely you got something wrong).
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    87
        Any copy-and-paste will turn out to be painful 
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    88
        when something has to be changed or fixed later on.
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    89
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    90
    \item[comments]
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    91
      are a device which requires careful thinking before using
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    92
      it.  The best comment for your code should be the code itself.
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    93
      Prefer efforts to write clear, understandable code
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    94
      over efforts to explain nasty code.
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    95
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    96
    \item[functional programming is based on functions]
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    97
      Avoid ``constructivisms'', e.g. pass a table lookup function,
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    98
      rather than an actual table with lookup in body.  Accustom
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
    99
      your way of codeing to the level of expressiveness
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
   100
      a functional programming language is giving onto you.
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
   101
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
   102
    \item[tuples]
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
   103
      are often in the way.  When there is no striking argument
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
   104
      to tuple function arguments, just write your function curried.
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
   105
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
   106
    \item[telling names]
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
   107
      Any name should tell its purpose as exactly as possible,
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
   108
      while keeping its length to the absolutely neccessary minimum.
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
   109
      Always give the same name to function arguments which
3a64d58a9f49 first version of style guide
haftmann
parents: 20520
diff changeset
   110
      have the same meaning. Separate words by underscores
21501
8dab1e45c11f updated;
wenzelm
parents: 21172
diff changeset
   111
      (``\verb|int_of_string|'', not ``\verb|intOfString|'')
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
  \end{description}%
18543
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   114
\end{isamarkuptext}%
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   115
\isamarkuptrue%
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   116
%
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   117
\isamarkupchapter{Basic library functions%
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   118
}
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   119
\isamarkuptrue%
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   120
%
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   121
\begin{isamarkuptext}%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   122
Beyond the proposal of the SML/NJ basis library, Isabelle comes
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   123
  with its own library, from which selected parts are given here.
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   124
  See further files \emph{Pure/library.ML} and \emph{Pure/General/*.ML}.%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   125
\end{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   126
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   127
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   128
\isamarkupsection{Linear transformations%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   129
}
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   130
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   131
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   132
\isadelimmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   133
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   134
\endisadelimmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   135
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   136
\isatagmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   137
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   138
\begin{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   139
\begin{mldecls}
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   140
  \indexml{(op |$>$)}\verb|(op |\verb,|,\verb|>): 'a * ('a -> 'b) -> 'b| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   141
  \indexml{fold}\verb|fold: ('a -> 'b -> 'b) -> 'a list -> 'b -> 'b| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   142
  \indexml{fold-rev}\verb|fold_rev: ('a -> 'b -> 'b) -> 'a list -> 'b -> 'b| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   143
  \end{mldecls}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   144
\end{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   145
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   146
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   147
\endisatagmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   148
{\isafoldmlref}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   149
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   150
\isadelimmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   151
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   152
\endisadelimmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   153
%
22322
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   154
\isadelimML
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   155
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   156
\endisadelimML
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   157
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   158
\isatagML
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   159
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   160
\endisatagML
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   161
{\isafoldML}%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   162
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   163
\isadelimML
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   164
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   165
\endisadelimML
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   166
%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   167
\begin{isamarkuptext}%
22322
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   168
Many problems in functional programming can be thought of
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   169
  as linear transformations, i.e.~a caluclation starts with a
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   170
  particular value \isa{x\ {\isasymColon}\ foo} which is then transformed
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   171
  by application of a function \isa{f\ {\isasymColon}\ foo\ {\isasymRightarrow}\ foo},
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   172
  continued by an application of a function \isa{g\ {\isasymColon}\ foo\ {\isasymRightarrow}\ bar},
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   173
  and so on.  As a canoncial example, take primitive functions enriching
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   174
  theories by constants and definitions:
22550
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   175
  \verb|Sign.add_consts_i: (string * typ * mixfix) list -> theory|\isasep\isanewline%
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   176
\verb|-> theory|
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   177
  and \verb|Theory.add_defs_i: bool -> bool|\isasep\isanewline%
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   178
\verb|-> (bstring * term) list -> theory -> theory|.
22322
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   179
  Written with naive application, an addition of a constant with
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   180
  a corresponding definition would look like:
22550
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   181
  \verb|Theory.add_defs_i false false [dummy_def]|\isasep\isanewline%
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   182
\verb|  (Sign.add_consts_i [dummy_const] thy)|.
22322
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   183
  With increasing numbers of applications, this code gets quite unreadable.
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   184
  Using composition, at least the nesting of brackets may be reduced:
22550
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   185
  \verb|(Theory.add_defs_i false false [dummy_def] o Sign.add_consts_i|\isasep\isanewline%
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   186
\verb|  [dummy_const]) thy|.
22322
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   187
  What remains unsatisfactory is that things are written down in the opposite order
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   188
  as they actually ``happen''.%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   189
\end{isamarkuptext}%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   190
\isamarkuptrue%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   191
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   192
\isadelimML
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   193
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   194
\endisadelimML
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   195
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   196
\isatagML
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   197
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   198
\endisatagML
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   199
{\isafoldML}%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   200
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   201
\isadelimML
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   202
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   203
\endisadelimML
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   204
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   205
\begin{isamarkuptext}%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   206
At this stage, Isabelle offers some combinators which allow for more convenient
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   207
  notation, most notably reverse application:
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   208
  \isasep\isanewline%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   209
\verb|thy|\isasep\isanewline%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   210
\verb||\verb,|,\verb|> Sign.add_consts_i [dummy_const]|\isasep\isanewline%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   211
\verb||\verb,|,\verb|> Theory.add_defs_i false false [dummy_def]|%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   212
\end{isamarkuptext}%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   213
\isamarkuptrue%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   214
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   215
\begin{isamarkuptext}%
22550
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   216
\noindent When iterating over a list of parameters \isa{{\isacharbrackleft}x\isactrlisub {\isadigit{1}}{\isacharcomma}\ x\isactrlisub {\isadigit{2}}{\isacharcomma}\ {\isasymdots}\ x\isactrlisub n{\isacharbrackright}\ {\isasymColon}\ {\isacharprime}a\ list},
22322
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   217
  the \verb|fold| combinator lifts a single function \isa{f\ {\isasymColon}\ {\isacharprime}a\ {\isacharminus}{\isachargreater}\ {\isacharprime}b\ {\isacharminus}{\isachargreater}\ {\isacharprime}b}:
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   218
  \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}%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   219
\end{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   220
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   221
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   222
\isadelimmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   223
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   224
\endisadelimmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   225
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   226
\isatagmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   227
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   228
\begin{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   229
\begin{mldecls}
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   230
  \indexml{(op |-$>$)}\verb|(op |\verb,|,\verb|->): ('c * 'a) * ('c -> 'a -> 'b) -> 'b| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   231
  \indexml{(op |$>$$>$)}\verb|(op |\verb,|,\verb|>>): ('a * 'c) * ('a -> 'b) -> 'b * 'c| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   232
  \indexml{(op ||$>$)}\verb|(op |\verb,|,\verb||\verb,|,\verb|>): ('c * 'a) * ('a -> 'b) -> 'c * 'b| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   233
  \indexml{(op ||$>$$>$)}\verb|(op |\verb,|,\verb||\verb,|,\verb|>>): ('c * 'a) * ('a -> 'd * 'b) -> ('c * 'd) * 'b| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   234
  \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
   235
  \end{mldecls}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   236
\end{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   237
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   238
%
22322
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   239
\endisatagmlref
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   240
{\isafoldmlref}%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   241
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   242
\isadelimmlref
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   243
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   244
\endisadelimmlref
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   245
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   246
\begin{isamarkuptext}%
22550
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   247
\noindent FIXME transformations involving side results%
22322
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   248
\end{isamarkuptext}%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   249
\isamarkuptrue%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   250
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   251
\isadelimmlref
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   252
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   253
\endisadelimmlref
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   254
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   255
\isatagmlref
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   256
%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   257
\begin{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   258
\begin{mldecls}
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   259
  \indexml{(op \#$>$)}\verb|(op #>): ('a -> 'b) * ('b -> 'c) -> 'a -> 'c| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   260
  \indexml{(op \#-$>$)}\verb|(op #->): ('a -> 'c * 'b) * ('c -> 'b -> 'd) -> 'a -> 'd| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   261
  \indexml{(op \#$>$$>$)}\verb|(op #>>): ('a -> 'c * 'b) * ('c -> 'd) -> 'a -> 'd * 'b| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   262
  \indexml{(op \#\#$>$)}\verb|(op ##>): ('a -> 'c * 'b) * ('b -> 'd) -> 'a -> 'c * 'd| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   263
  \indexml{(op \#\#$>$$>$)}\verb|(op ##>>): ('a -> 'c * 'b) * ('b -> 'e * 'd) -> 'a -> ('c * 'e) * 'd| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   264
  \end{mldecls}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   265
\end{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   266
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   267
%
22322
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   268
\endisatagmlref
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   269
{\isafoldmlref}%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   270
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   271
\isadelimmlref
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   272
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   273
\endisadelimmlref
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   274
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   275
\begin{isamarkuptext}%
22550
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   276
\noindent All those linear combinators also exist in higher-order
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   277
  variants which do not expect a value on the left hand side
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   278
  but a function.%
22322
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   279
\end{isamarkuptext}%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   280
\isamarkuptrue%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   281
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   282
\isadelimmlref
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   283
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   284
\endisadelimmlref
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   285
%
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   286
\isatagmlref
b9924abb8c66 continued
haftmann
parents: 22293
diff changeset
   287
%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   288
\begin{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   289
\begin{mldecls}
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   290
  \indexml{(op `)}\verb|(op `): ('b -> 'a) -> 'b -> 'a * 'b| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   291
  \indexml{tap}\verb|tap: ('b -> 'a) -> 'b -> 'b| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   292
  \end{mldecls}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   293
\end{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   294
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   295
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   296
\endisatagmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   297
{\isafoldmlref}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   298
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   299
\isadelimmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   300
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   301
\endisadelimmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   302
%
22550
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   303
\begin{isamarkuptext}%
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   304
\noindent FIXME%
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   305
\end{isamarkuptext}%
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   306
\isamarkuptrue%
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   307
%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   308
\isamarkupsection{Options and partiality%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   309
}
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   310
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   311
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   312
\isadelimmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   313
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   314
\endisadelimmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   315
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   316
\isatagmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   317
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   318
\begin{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   319
\begin{mldecls}
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   320
  \indexml{is-some}\verb|is_some: 'a option -> bool| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   321
  \indexml{is-none}\verb|is_none: 'a option -> bool| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   322
  \indexml{the}\verb|the: 'a option -> 'a| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   323
  \indexml{these}\verb|these: 'a list option -> 'a list| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   324
  \indexml{the-list}\verb|the_list: 'a option -> 'a list| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   325
  \indexml{the-default}\verb|the_default: 'a -> 'a option -> 'a| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   326
  \indexml{try}\verb|try: ('a -> 'b) -> 'a -> 'b option| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   327
  \indexml{can}\verb|can: ('a -> 'b) -> 'a -> bool| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   328
  \end{mldecls}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   329
\end{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   330
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   331
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   332
\endisatagmlref
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   333
{\isafoldmlref}%
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
\isadelimmlref
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
\endisadelimmlref
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}%
22550
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   340
Standard selector functions on \isa{option}s are provided.
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   341
  The \verb|try| and \verb|can| functions provide a convenient
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   342
  interface for handling exceptions -- both take as arguments
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   343
  a function \isa{f} together with a parameter \isa{x}
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   344
  and catch any exception during the evaluation of the application
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   345
  of \isa{f} to \isa{x}, either return a lifted result
c5039bee2602 updated
haftmann
parents: 22503
diff changeset
   346
  (\verb|NONE| on failure) or a boolean value (\verb|false| on failure).%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   347
\end{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   348
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   349
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   350
\isamarkupsection{Common data structures%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   351
}
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   352
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   353
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   354
\isamarkupsubsection{Lists (as set-like data structures)%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   355
}
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   356
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   357
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   358
\begin{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   359
\begin{mldecls}
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   360
  \indexml{member}\verb|member: ('b * 'a -> bool) -> 'a list -> 'b -> bool| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   361
  \indexml{insert}\verb|insert: ('a * 'a -> bool) -> 'a -> 'a list -> 'a list| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   362
  \indexml{remove}\verb|remove: ('b * 'a -> bool) -> 'b -> 'a list -> 'a list| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   363
  \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
   364
  \end{mldecls}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   365
\end{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   366
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   367
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   368
\begin{isamarkuptext}%
22503
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   369
Lists are often used as set-like data structures -- set-like in
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   370
  then sense that they support notion of \verb|member|-ship,
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   371
  \verb|insert|-ing and \verb|remove|-ing, but are order-sensitive.
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   372
  This is convenient when implementing a history-like mechanism:
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   373
  \verb|insert| adds an element \emph{to the front} of a list,
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   374
  if not yet present; \verb|remove| removes \emph{all} occurences
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   375
  of a particular element.  Correspondingly \verb|merge| implements a 
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   376
  a merge on two lists suitable for merges of context data
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   377
  (\secref{sec:context-theory}).
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   378
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   379
  Functions are parametrized by an explicit equality function
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   380
  to accomplish overloaded equality;  in most cases of monomorphic
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   381
  equality, writing \verb|(op =)| should suffice.%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   382
\end{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   383
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   384
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   385
\isamarkupsubsection{Association lists%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   386
}
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   387
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   388
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   389
\begin{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   390
\begin{mldecls}
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   391
  \indexmlexception{AList.DUP}\verb|exception AList.DUP| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   392
  \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
   393
  \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
   394
  \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
   395
  \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
   396
  \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
   397
  \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
   398
\verb|    -> ('c -> 'c) -> ('b * 'c) list -> ('b * 'c) list| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   399
  \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
   400
\verb|    -> ('a * 'b) list -> ('a * 'b) list| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   401
  \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
   402
\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
   403
  \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
   404
\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
   405
  \end{mldecls}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   406
\end{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   407
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   408
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   409
\begin{isamarkuptext}%
22503
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   410
Association lists can be seens as an extension of set-like lists:
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   411
  on the one hand, they may be used to implement finite mappings,
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   412
  on the other hand, they remain order-sensitive and allow for
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   413
  multiple key-value-pair with the same key: \verb|AList.lookup|
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   414
  returns the \emph{first} value corresponding to a particular
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   415
  key, if present.  \verb|AList.update| updates
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   416
  the \emph{first} occurence of a particular key; if no such
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   417
  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
   418
  \verb|AList.delete| only deletes the \emph{first} occurence of a key.
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   419
  \verb|AList.merge| provides an operation suitable for merges of context data
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   420
  (\secref{sec:context-theory}), where an equality parameter on
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   421
  values determines whether a merge should be considered a conflict.
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   422
  A slightly generalized operation if implementend by the \verb|AList.join|
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   423
  function which allows for explicit conflict resolution.%
22293
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   424
\end{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   425
\isamarkuptrue%
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
\isamarkupsubsection{Tables%
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
\isamarkuptrue%
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}
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   433
  \indexmltype{Symtab.key}\verb|type Symtab.key| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   434
  \indexmltype{'a Symtab.table}\verb|type 'a Symtab.table| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   435
  \indexmlexception{Symtab.DUP}\verb|exception Symtab.DUP of Symtab.key| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   436
  \indexmlexception{Symtab.DUPS}\verb|exception Symtab.DUPS of Symtab.key list| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   437
  \indexmlexception{Symtab.SAME}\verb|exception Symtab.SAME| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   438
  \indexmlexception{Symtab.UNDEF}\verb|exception Symtab.UNDEF of Symtab.key| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   439
  \indexml{Symtab.empty}\verb|Symtab.empty: 'a Symtab.table| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   440
  \indexml{Symtab.dest}\verb|Symtab.dest: 'a Symtab.table -> (Symtab.key * 'a) list| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   441
  \indexml{Symtab.keys}\verb|Symtab.keys: 'a Symtab.table -> Symtab.key list| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   442
  \indexml{Symtab.lookup}\verb|Symtab.lookup: 'a Symtab.table -> Symtab.key -> 'a option| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   443
  \indexml{Symtab.defined}\verb|Symtab.defined: 'a Symtab.table -> Symtab.key -> bool| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   444
  \indexml{Symtab.update}\verb|Symtab.update: (Symtab.key * 'a) -> 'a Symtab.table -> 'a Symtab.table| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   445
  \indexml{Symtab.default}\verb|Symtab.default: Symtab.key * 'a -> 'a Symtab.table -> 'a Symtab.table| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   446
  \indexml{Symtab.delete}\verb|Symtab.delete: Symtab.key|\isasep\isanewline%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   447
\verb|    -> 'a Symtab.table -> 'a Symtab.table (*exception Symtab.UNDEF*)| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   448
  \indexml{Symtab.map-entry}\verb|Symtab.map_entry: Symtab.key -> ('a -> 'a)|\isasep\isanewline%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   449
\verb|    -> 'a Symtab.table -> 'a Symtab.table| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   450
  \indexml{Symtab.map-default}\verb|Symtab.map_default: (Symtab.key * 'a) -> ('a -> 'a)|\isasep\isanewline%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   451
\verb|    -> 'a Symtab.table -> 'a Symtab.table| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   452
  \indexml{Symtab.join}\verb|Symtab.join: (Symtab.key -> 'a * 'a -> 'a) (*exception Symtab.DUP/Symtab.SAME*)|\isasep\isanewline%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   453
\verb|    -> 'a Symtab.table * 'a Symtab.table|\isasep\isanewline%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   454
\verb|    -> 'a Symtab.table (*exception Symtab.DUPS*)| \\
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   455
  \indexml{Symtab.merge}\verb|Symtab.merge: ('a * 'a -> bool)|\isasep\isanewline%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   456
\verb|    -> 'a Symtab.table * 'a Symtab.table|\isasep\isanewline%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   457
\verb|    -> 'a Symtab.table (*exception Symtab.DUPS*)|
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   458
  \end{mldecls}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   459
\end{isamarkuptext}%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   460
\isamarkuptrue%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   461
%
3593a76c9ed3 added outline for Isabelle library description
haftmann
parents: 21501
diff changeset
   462
\begin{isamarkuptext}%
22503
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   463
Tables are an efficient representation of finite mappings without
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   464
  any notion of order;  due to their efficiency they should be used
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   465
  whenever such pure finite mappings are neccessary.
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   466
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   467
  The key type of tables must be given explicitly by instantiating
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   468
  the \verb|TableFun| functor which takes the key type
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   469
  together with its \verb|order|; for convience, we restrict
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   470
  here to the \verb|Symtab| instance with \verb|string|
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   471
  as key type.
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   472
d53664118418 added some sketches about library functions
haftmann
parents: 22322
diff changeset
   473
  Most table functions correspond to those of association lists.%
18543
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   474
\end{isamarkuptext}%
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   475
\isamarkuptrue%
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   476
%
20490
e502690952be updated;
wenzelm
parents: 18554
diff changeset
   477
\isamarkupchapter{Cookbook%
e502690952be updated;
wenzelm
parents: 18554
diff changeset
   478
}
e502690952be updated;
wenzelm
parents: 18554
diff changeset
   479
\isamarkuptrue%
e502690952be updated;
wenzelm
parents: 18554
diff changeset
   480
%
20491
wenzelm
parents: 20490
diff changeset
   481
\isamarkupsection{A method that depends on declarations in the context%
20490
e502690952be updated;
wenzelm
parents: 18554
diff changeset
   482
}
e502690952be updated;
wenzelm
parents: 18554
diff changeset
   483
\isamarkuptrue%
e502690952be updated;
wenzelm
parents: 18554
diff changeset
   484
%
e502690952be updated;
wenzelm
parents: 18554
diff changeset
   485
\begin{isamarkuptext}%
e502690952be updated;
wenzelm
parents: 18554
diff changeset
   486
FIXME%
e502690952be updated;
wenzelm
parents: 18554
diff changeset
   487
\end{isamarkuptext}%
e502690952be updated;
wenzelm
parents: 18554
diff changeset
   488
\isamarkuptrue%
e502690952be updated;
wenzelm
parents: 18554
diff changeset
   489
%
18543
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   490
\isadelimtheory
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   491
%
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   492
\endisadelimtheory
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   493
%
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   494
\isatagtheory
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   495
\isacommand{end}\isamarkupfalse%
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   496
%
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   497
\endisatagtheory
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   498
{\isafoldtheory}%
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   499
%
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   500
\isadelimtheory
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   501
%
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   502
\endisadelimtheory
18543
e903a1d0bed5 updated;
wenzelm
parents: 18537
diff changeset
   503
\isanewline
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   504
\end{isabellebody}%
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   505
%%% Local Variables:
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   506
%%% mode: latex
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   507
%%% TeX-master: "root"
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   508
%%% End: