doc-src/Ref/theories.tex
author lcp
Wed, 10 Nov 1993 05:00:57 +0100
changeset 104 d8205bb279a7
child 138 9ba8bff1addc
permissions -rw-r--r--
Initial revision
lcp@104
     1
%% $Id$
lcp@104
     2
\chapter{Theories, Terms and Types} \label{theories}
lcp@104
     3
\index{theories|(}\index{signatures|bold}
lcp@104
     4
\index{reading!axioms|see{{\tt extend_theory} and {\tt assume_ax}}}
lcp@104
     5
Theories organize the syntax, declarations and axioms of a mathematical
lcp@104
     6
development.  They are built, starting from the Pure theory, by extending
lcp@104
     7
and merging existing theories.  They have the \ML{} type \ttindex{theory}.
lcp@104
     8
Theory operations signal errors by raising exception \ttindex{THEORY},
lcp@104
     9
returning a message and a list of theories.
lcp@104
    10
lcp@104
    11
Signatures, which contain information about sorts, types, constants and
lcp@104
    12
syntax, have the \ML{} type~\ttindexbold{Sign.sg}.  For identification,
lcp@104
    13
each signature carries a unique list of {\bf stamps}, which are~\ML{}
lcp@104
    14
references (to strings).  The strings serve as human-readable names; the
lcp@104
    15
references serve as unique identifiers.  Each primitive signature has a
lcp@104
    16
single stamp.  When two signatures are merged, their lists of stamps are
lcp@104
    17
also merged.  Every theory carries a unique signature.
lcp@104
    18
lcp@104
    19
Terms and types are the underlying representation of logical syntax.  Their
lcp@104
    20
\ML{} definitions are irrelevant to naive Isabelle users.  Programmers who wish
lcp@104
    21
to extend Isabelle may need to know such details, say to code a tactic that
lcp@104
    22
looks for subgoals of a particular form.  Terms and types may be
lcp@104
    23
`certified' to be well-formed with respect to a given signature.
lcp@104
    24
lcp@104
    25
\section{Defining Theories}
lcp@104
    26
\label{DefiningTheories}
lcp@104
    27
lcp@104
    28
Theories can be defined either using concrete syntax or by calling certain
lcp@104
    29
\ML-functions (see \S\ref{BuildingATheory}).  Figure~\ref{TheorySyntax}
lcp@104
    30
presents the concrete syntax for theories.  This grammar employs the
lcp@104
    31
following conventions: 
lcp@104
    32
\begin{itemize}
lcp@104
    33
\item Identifiers such as $theoryDef$ denote nonterminal symbols.
lcp@104
    34
\item Text in {\tt typewriter font} denotes terminal symbols.
lcp@104
    35
\item \ldots{} indicates repetition of a phrase.
lcp@104
    36
\item A vertical bar~($|$) separates alternative phrases.
lcp@104
    37
\item Square [brackets] enclose optional phrases.
lcp@104
    38
\item $id$ stands for an Isabelle identifier.
lcp@104
    39
\item $string$ stands for an ML string, with its quotation marks.
lcp@104
    40
\item $k$ stands for a natural number.
lcp@104
    41
\item $text$ stands for arbitrary ML text.
lcp@104
    42
\end{itemize}
lcp@104
    43
lcp@104
    44
\begin{figure}[hp]
lcp@104
    45
\begin{center}
lcp@104
    46
\begin{tabular}{rclc}
lcp@104
    47
$theoryDef$ &=& $id$ {\tt=} $id@1$ {\tt+} \dots {\tt+} $id@n$
lcp@104
    48
                            [{\tt+} $extension$]\\\\
lcp@104
    49
$extension$ &=& [$classes$] [$default$] [$types$] [$arities$] [$consts$]
lcp@104
    50
                [$rules$] {\tt end} [$ml$]\\\\
lcp@104
    51
$classes$ &=& \ttindex{classes} $class$ \dots $class$ \\\\
lcp@104
    52
$class$ &=& $id$ [{\tt<} $id@1${\tt,} \dots{\tt,} $id@n$] \\\\
lcp@104
    53
$default$ &=& \ttindex{default} $sort$ \\\\
lcp@104
    54
$sort$ &=& $id$ ~~$|$~~ {\tt\{} $id@1${\tt,} \dots{\tt,} $id@n$ {\tt\}} \\\\
lcp@104
    55
$name$ &=& $id$ ~~$|$~~ $string$ \\\\
lcp@104
    56
$types$ &=& \ttindex{types} $typeDecl$ \dots $typeDecl$ \\\\
lcp@104
    57
$typeDecl$ &=& $name${\tt,} \dots{\tt,} $name$ $k$
lcp@104
    58
               [{\tt(} $infix$ {\tt)}] \\\\
lcp@104
    59
$infix$ &=& \ttindex{infixl} $k$ ~~$|$~~ \ttindex{infixr} $k$ \\\\
lcp@104
    60
$arities$ &=& \ttindex{arities} $arityDecl$ \dots $arityDecl$ \\\\
lcp@104
    61
$arityDecl$ &=& $name${\tt,} \dots{\tt,} $name$ {\tt::} $arity$ \\\\
lcp@104
    62
$arity$ &=& [{\tt(} $sort${\tt,} \dots{\tt,} $sort$ {\tt)}] $id$ \\\\
lcp@104
    63
$consts$ &=& \ttindex{consts} $constDecl$ \dots $constDecl$ \\\\
lcp@104
    64
$constDecl$ &=& $name@1${\tt,} \dots{\tt,} $name@n$ {\tt::} $string$
lcp@104
    65
                [{\tt(} $mixfix$ {\tt)}] \\\\
lcp@104
    66
$mixfix$ &=& $string$
lcp@104
    67
             [ [\quad{\tt[} $k@1${\tt,} \dots{\tt,} $k@n$ {\tt]}\quad] $k$]\\
lcp@104
    68
       &$|$& $infix$ \\
lcp@104
    69
       &$|$& \ttindex{binder} $string$ $k$\\\\
lcp@104
    70
$rules$ &=& \ttindex{rules} $rule$ \dots $rule$ \\\\
lcp@104
    71
$rule$ &=& $id$ $string$ \\\\
lcp@104
    72
$ml$ &=& \ttindex{ML} $text$
lcp@104
    73
\end{tabular}
lcp@104
    74
\end{center}
lcp@104
    75
\caption{Theory Syntax}
lcp@104
    76
\label{TheorySyntax}
lcp@104
    77
\end{figure}
lcp@104
    78
lcp@104
    79
The different parts of a theory definition are interpreted as follows:
lcp@104
    80
\begin{description}
lcp@104
    81
\item[$theoryDef$] A theory has a name $id$ and is an extension of the union
lcp@104
    82
  of existing theories $id@1$ \dots $id@n$ with new classes, types,
lcp@104
    83
  constants, syntax and axioms.  The basic theory, which contains only the
lcp@104
    84
  meta-logic, is called {\tt Pure}.
lcp@104
    85
\item[$class$] The new class $id$ is declared as a subclass of existing
lcp@104
    86
  classes $id@1$ \dots $id@n$.  This rules out cyclic class structures.
lcp@104
    87
  Isabelle automatically computes the transitive closure of subclass
lcp@104
    88
  hierarchies.  Hence it is not necessary to declare $c@1 < c@3$ in addition
lcp@104
    89
  to $c@1 < c@2$ and $c@2 < c@3$.
lcp@104
    90
\item[$default$] introduces $sort$ as the new default sort for type
lcp@104
    91
  variables.  Unconstrained type variables in an input string are
lcp@104
    92
  automatically constrained by $sort$; this does not apply to type variables
lcp@104
    93
  created internally during type inference.  If omitted,
lcp@104
    94
  the default sort is the same as in the parent theory.
lcp@104
    95
\item[$sort$] is a finite set $id@1$ \dots $id@n$ of classes; a single class
lcp@104
    96
  $id$ abbreviates the singleton set {\tt\{}$id${\tt\}}.
lcp@104
    97
\item[$name$] is either an alphanumeric identifier or an arbitrary string.
lcp@104
    98
\item[$typeDecl$] Each $name$ is declared as a new type constructor with
lcp@104
    99
  $k$ arguments.  Only binary type constructors can have infix status and
lcp@104
   100
  symbolic names ($string$).
lcp@104
   101
\item[$infix$] declares a type or constant to be an infix operator of
lcp@104
   102
  precedence $k$ associating to the left ({\tt infixl}) or right ({\tt
lcp@104
   103
    infixr}).
lcp@104
   104
\item[$arityDecl$] Each existing type constructor $name@1$ \dots $name@n$
lcp@104
   105
  is given the additional arity $arity$.
lcp@104
   106
\item[$constDecl$] The new constants $name@1$ \dots $name@n$ are declared to
lcp@104
   107
  be of type $string$.  For display purposes they can be annotated with
lcp@104
   108
  $mixfix$ declarations.
lcp@104
   109
\item[$mixfix$] $string$ is a mixfix template of the form {\tt"}\dots{\tt\_}
lcp@104
   110
  \dots{\tt\_} \dots{\tt"} where the $i$-th underscore indicates the position
lcp@104
   111
  where the $i$-th argument should go, $k@i$ is the minimum precedence of
lcp@104
   112
  the $i$-th argument, and $k$ the precedence of the construct.  The list
lcp@104
   113
  \hbox{\tt[$k@1$, \dots, $k@n$]} is optional.
lcp@104
   114
lcp@104
   115
  Binary constants can be given infix status.
lcp@104
   116
lcp@104
   117
  A constant $f$ {\tt::} $(\tau@1\To\tau@2)\To\tau@3$ can be given {\em
lcp@104
   118
    binder} status: {\tt binder} $Q$ $p$ causes $Q\,x.F(x)$ to be treated
lcp@104
   119
  like $f(F)$; $p$ is the precedence of the construct.
lcp@104
   120
\item[$rule$] A rule consists of a name $id$ and a formula $string$.  Rule
lcp@104
   121
  names must be distinct.
lcp@104
   122
\item[$ml$] This final part of a theory consists of ML code, 
lcp@104
   123
  typically for parse and print translations.
lcp@104
   124
\end{description}
lcp@104
   125
The $mixfix$ and $ml$ sections are explained in more detail in the {\it
lcp@104
   126
Defining Logics} chapter of the {\it Logics} manual.
lcp@104
   127
lcp@104
   128
\begin{ttbox} 
lcp@104
   129
use_thy: string -> unit
lcp@104
   130
\end{ttbox}
lcp@104
   131
Each theory definition must reside in a separate file.  Let the file {\it
lcp@104
   132
  tf}{\tt.thy} contain the definition of a theory called $TF$ with rules named
lcp@104
   133
$r@1$ \dots $r@n$.  Calling \ttindexbold{use_thy}~{\tt"}{\it tf\/}{\tt"} reads
lcp@104
   134
file {\it tf}{\tt.thy}, writes an intermediate {\ML}-file {\tt.}{\it
lcp@104
   135
  tf}{\tt.thy.ML}, and reads the latter file.  This declares an {\ML}
lcp@104
   136
structure~$TF$ containing a component {\tt thy} for the new theory
lcp@104
   137
and components $r@1$ \dots $r@n$ for the rules; it also contains the
lcp@104
   138
definitions of the {\tt ML} section if any.  Then {\tt use_thy}
lcp@104
   139
reads the file {\it tf}{\tt.ML}, if it exists; this file normally contains
lcp@104
   140
proofs involving the new theory.
lcp@104
   141
lcp@104
   142
lcp@104
   143
\section{Basic operations on theories}
lcp@104
   144
\subsection{Extracting an axiom from a theory}
lcp@104
   145
\index{theories!extracting axioms|bold}\index{axioms}
lcp@104
   146
\begin{ttbox} 
lcp@104
   147
get_axiom: theory -> string -> thm
lcp@104
   148
assume_ax: theory -> string -> thm
lcp@104
   149
\end{ttbox}
lcp@104
   150
\begin{description}
lcp@104
   151
\item[\ttindexbold{get_axiom} $thy$ $name$] 
lcp@104
   152
returns an axiom with the given $name$ from $thy$, raising exception
lcp@104
   153
\ttindex{THEORY} if none exists.  Merging theories can cause several axioms
lcp@104
   154
to have the same name; {\tt get_axiom} returns an arbitrary one.
lcp@104
   155
lcp@104
   156
\item[\ttindexbold{assume_ax} $thy$ $formula$] 
lcp@104
   157
reads the {\it formula} using the syntax of $thy$, following the same
lcp@104
   158
conventions as axioms in a theory definition.  You can thus pretend that
lcp@104
   159
{\it formula} is an axiom; in fact, {\tt assume_ax} returns an assumption.
lcp@104
   160
You can use the resulting theorem like an axiom.  Note that 
lcp@104
   161
\ttindex{result} complains about additional assumptions, but 
lcp@104
   162
\ttindex{uresult} does not.
lcp@104
   163
lcp@104
   164
For example, if {\it formula} is
lcp@104
   165
\hbox{\tt a=b ==> b=a} then the resulting theorem might have the form
lcp@104
   166
\hbox{\tt\frenchspacing ?a=?b ==> ?b=?a  [!!a b. a=b ==> b=a]}
lcp@104
   167
\end{description}
lcp@104
   168
lcp@104
   169
\subsection{Building a theory}
lcp@104
   170
\label{BuildingATheory}
lcp@104
   171
\index{theories!constructing|bold}
lcp@104
   172
\begin{ttbox} 
lcp@104
   173
pure_thy: theory
lcp@104
   174
merge_theories: theory * theory -> theory
lcp@104
   175
extend_theory: theory -> string
lcp@104
   176
        -> (class * class list) list 
lcp@104
   177
           * sort
lcp@104
   178
           * (string list * int)list
lcp@104
   179
           * (string list * (sort list * class))list
lcp@104
   180
           * (string list * string)list * sext option
lcp@104
   181
        -> (string*string)list -> theory
lcp@104
   182
\end{ttbox}
lcp@104
   183
Type \ttindex{class} is a synonym for {\tt string}; type \ttindex{sort} is
lcp@104
   184
a synonym for \hbox{\tt class list}.
lcp@104
   185
\begin{description}
lcp@104
   186
\item[\ttindexbold{pure_thy}] contains just the types, constants, and syntax
lcp@104
   187
  of the meta-logic.  There are no axioms: meta-level inferences are carried
lcp@104
   188
  out by \ML\ functions.
lcp@104
   189
\item[\ttindexbold{merge_theories} ($thy@1$, $thy@2$)] merges the two
lcp@104
   190
  theories $thy@1$ and $thy@2$.  The resulting theory contains all types,
lcp@104
   191
  constants and axioms of the constituent theories; its default sort is the
lcp@104
   192
  union of the default sorts of the constituent theories.
lcp@104
   193
\item [\ttindexbold{extend_theory} $thy$ {\tt"}$T${\tt"}
lcp@104
   194
      ($classes$, $default$, $types$, $arities$, $consts$, $sextopt$) $rules$]
lcp@104
   195
\hfill\break   %%% include if line is just too short
lcp@104
   196
is the \ML-equivalent of the following theory definition:
lcp@104
   197
\begin{ttbox}
lcp@104
   198
\(T\) = \(thy\) +
lcp@104
   199
classes \(c\) < \(c@1\),\(\dots\),\(c@m\)
lcp@104
   200
        \dots
lcp@104
   201
default {\(d@1,\dots,d@r\)}
lcp@104
   202
types   \(tycon@1\),\dots,\(tycon@i\) \(n\)
lcp@104
   203
        \dots
lcp@104
   204
arities \(tycon@1'\),\dots,\(tycon@j'\) :: (\(s@1\),\dots,\(s@n\))\(c\)
lcp@104
   205
        \dots
lcp@104
   206
consts  \(b@1\),\dots,\(b@k\) :: \(\tau\)
lcp@104
   207
        \dots
lcp@104
   208
rules   \(name\) \(rule\)
lcp@104
   209
        \dots
lcp@104
   210
end
lcp@104
   211
\end{ttbox}
lcp@104
   212
where
lcp@104
   213
\begin{tabular}[t]{l@{~=~}l}
lcp@104
   214
$classes$ & \tt[("$c$",["$c@1$",\dots,"$c@m$"]),\dots] \\
lcp@104
   215
$default$ & \tt["$d@1$",\dots,"$d@r$"]\\
lcp@104
   216
$types$   & \tt[([$tycon@1$,\dots,$tycon@i$], $n$),\dots] \\
lcp@104
   217
$arities$ & \tt[([$tycon'@1$,\dots,$tycon'@j$], ([$s@1$,\dots,$s@n$],$c$)),\dots]
lcp@104
   218
\\
lcp@104
   219
$consts$  & \tt[([$b@1$,\dots,$b@k$],$\tau$),\dots] \\
lcp@104
   220
$rules$   & \tt[("$name$",$rule$),\dots]
lcp@104
   221
\end{tabular}
lcp@104
   222
lcp@104
   223
If theories are defined as in \S\ref{DefiningTheories}, new syntax is added
lcp@104
   224
as mixfix annotations to constants.  Using {\tt extend_theory}, new syntax can
lcp@104
   225
be added via $sextopt$ which is either {\tt None}, or {\tt Some($sext$)}.  The
lcp@104
   226
latter case is not documented.
lcp@104
   227
lcp@104
   228
$T$ identifies the theory internally.  When a theory is redeclared, say to
lcp@104
   229
change an incorrect axiom, bindings to the old axiom may persist.  Isabelle
lcp@104
   230
ensures that the old and new theories are not involved in the same proof.
lcp@104
   231
Attempting to combine different theories having the same name $T$ yields the
lcp@104
   232
fatal error
lcp@104
   233
\begin{center} \tt
lcp@104
   234
Attempt to merge different versions of theory: $T$
lcp@104
   235
\end{center}
lcp@104
   236
\end{description}
lcp@104
   237
lcp@104
   238
lcp@104
   239
\subsection{Inspecting a theory}
lcp@104
   240
\index{theories!inspecting|bold}
lcp@104
   241
\begin{ttbox} 
lcp@104
   242
print_theory  : theory -> unit
lcp@104
   243
axioms_of     : theory -> (string*thm)list
lcp@104
   244
parents_of    : theory -> theory list
lcp@104
   245
sign_of       : theory -> Sign.sg
lcp@104
   246
stamps_of_thy : theory -> string ref list
lcp@104
   247
\end{ttbox}
lcp@104
   248
These provide a simple means of viewing a theory's components.
lcp@104
   249
Unfortunately, there is no direct connection between a theorem and its
lcp@104
   250
theory.
lcp@104
   251
\begin{description}
lcp@104
   252
\item[\ttindexbold{print_theory} {\it thy}]  
lcp@104
   253
prints the theory {\it thy\/} at the terminal as a set of identifiers.
lcp@104
   254
lcp@104
   255
\item[\ttindexbold{axioms_of} $thy$] 
lcp@104
   256
returns the axioms of~$thy$ and its ancestors.
lcp@104
   257
lcp@104
   258
\item[\ttindexbold{parents_of} $thy$] 
lcp@104
   259
returns the parents of~$thy$.  This list contains zero, one or two
lcp@104
   260
elements, depending upon whether $thy$ is {\tt pure_thy}, 
lcp@104
   261
\hbox{\tt extend_theory $thy$} or \hbox{\tt merge_theories ($thy@1$, $thy@2$)}.
lcp@104
   262
lcp@104
   263
\item[\ttindexbold{stamps_of_thy} $thy$]\index{signatures}
lcp@104
   264
returns the stamps of the signature associated with~$thy$.
lcp@104
   265
lcp@104
   266
\item[\ttindexbold{sign_of} $thy$] 
lcp@104
   267
returns the signature associated with~$thy$.  It is useful with functions
lcp@104
   268
like {\tt read_instantiate_sg}, which take a signature as an argument.
lcp@104
   269
\end{description}
lcp@104
   270
lcp@104
   271
lcp@104
   272
\section{Terms}
lcp@104
   273
\index{terms|bold}
lcp@104
   274
Terms belong to the \ML{} type \ttindexbold{term}, which is a concrete datatype
lcp@104
   275
with six constructors: there are six kinds of term.
lcp@104
   276
\begin{ttbox}
lcp@104
   277
type indexname = string * int;
lcp@104
   278
infix 9 $;
lcp@104
   279
datatype term = Const of string * typ
lcp@104
   280
              | Free  of string * typ
lcp@104
   281
              | Var   of indexname * typ
lcp@104
   282
              | Bound of int
lcp@104
   283
              | Abs   of string * typ * term
lcp@104
   284
              | op $  of term * term;
lcp@104
   285
\end{ttbox}
lcp@104
   286
\begin{description}
lcp@104
   287
\item[\ttindexbold{Const}($a$, $T$)] 
lcp@104
   288
is the {\bf constant} with name~$a$ and type~$T$.  Constants include
lcp@104
   289
connectives like $\land$ and $\forall$ (logical constants), as well as
lcp@104
   290
constants like~0 and~$Suc$.  Other constants may be required to define the
lcp@104
   291
concrete syntax of a logic.
lcp@104
   292
lcp@104
   293
\item[\ttindexbold{Free}($a$, $T$)] 
lcp@104
   294
is the {\bf free variable} with name~$a$ and type~$T$.
lcp@104
   295
lcp@104
   296
\item[\ttindexbold{Var}($v$, $T$)] 
lcp@104
   297
is the {\bf scheme variable} with indexname~$v$ and type~$T$.  An
lcp@104
   298
\ttindexbold{indexname} is a string paired with a non-negative index, or
lcp@104
   299
subscript; a term's scheme variables can be systematically renamed by
lcp@104
   300
incrementing their subscripts.  Scheme variables are essentially free
lcp@104
   301
variables, but may be instantiated during unification.
lcp@104
   302
lcp@104
   303
\item[\ttindexbold{Bound} $i$] 
lcp@104
   304
is the {\bf bound variable} with de Bruijn index~$i$, which counts the
lcp@104
   305
number of lambdas, starting from zero, between a variable's occurrence and
lcp@104
   306
its binding.  The representation prevents capture of variables.  For more
lcp@104
   307
information see de Bruijn \cite{debruijn72} or
lcp@104
   308
Paulson~\cite[page~336]{paulson91}.
lcp@104
   309
lcp@104
   310
\item[\ttindexbold{Abs}($a$, $T$, $u$)] 
lcp@104
   311
is the {\bf abstraction} with body~$u$, and whose bound variable has
lcp@104
   312
name~$a$ and type~$T$.  The name is used only for parsing and printing; it
lcp@104
   313
has no logical significance.
lcp@104
   314
lcp@104
   315
\item[\tt $t$ \$ $u$] \index{$@{\tt\$}|bold}
lcp@104
   316
is the {\bf application} of~$t$ to~$u$.  
lcp@104
   317
\end{description}
lcp@104
   318
Application is written as an infix operator in order to aid readability.
lcp@104
   319
For example, here is an \ML{} pattern to recognize first-order formula of
lcp@104
   320
the form~$A\imp B$, binding the subformulae to~$A$ and~$B$:
lcp@104
   321
\begin{ttbox} 
lcp@104
   322
Const("Trueprop",_) $ (Const("op -->",_) $ A $ B)
lcp@104
   323
\end{ttbox}
lcp@104
   324
lcp@104
   325
lcp@104
   326
\section{Certified terms}
lcp@104
   327
\index{terms!certified|bold}\index{signatures}
lcp@104
   328
A term $t$ can be {\bf certified} under a signature to ensure that every
lcp@104
   329
type in~$t$ is declared in the signature and every constant in~$t$ is
lcp@104
   330
declared as a constant of the same type in the signature.  It must be
lcp@104
   331
well-typed and must not have any `loose' bound variable
lcp@104
   332
references.\footnote{This concerns the internal representation of variable
lcp@104
   333
binding using de Bruijn indexes.} Meta-rules such as {\tt forall_elim} take
lcp@104
   334
certified terms as arguments.
lcp@104
   335
lcp@104
   336
Certified terms belong to the abstract type \ttindexbold{Sign.cterm}.
lcp@104
   337
Elements of the type can only be created through the certification process.
lcp@104
   338
In case of error, Isabelle raises exception~\ttindex{TERM}\@.
lcp@104
   339
lcp@104
   340
\subsection{Printing terms}
lcp@104
   341
\index{printing!terms|bold}
lcp@104
   342
\begin{ttbox} 
lcp@104
   343
Sign.string_of_cterm :      Sign.cterm -> string
lcp@104
   344
Sign.string_of_term  : Sign.sg -> term -> string
lcp@104
   345
\end{ttbox}
lcp@104
   346
\begin{description}
lcp@104
   347
\item[\ttindexbold{Sign.string_of_cterm} $ct$] 
lcp@104
   348
displays $ct$ as a string.
lcp@104
   349
lcp@104
   350
\item[\ttindexbold{Sign.string_of_term} $sign$ $t$] 
lcp@104
   351
displays $t$ as a string, using the syntax of~$sign$.
lcp@104
   352
\end{description}
lcp@104
   353
lcp@104
   354
\subsection{Making and inspecting certified terms}
lcp@104
   355
\begin{ttbox} 
lcp@104
   356
Sign.cterm_of   : Sign.sg -> term -> Sign.cterm
lcp@104
   357
Sign.read_cterm : Sign.sg -> string * typ -> Sign.cterm
lcp@104
   358
Sign.rep_cterm  : Sign.cterm -> \{T:typ, t:term, 
lcp@104
   359
                                 sign: Sign.sg, maxidx:int\}
lcp@104
   360
\end{ttbox}
lcp@104
   361
\begin{description}
lcp@104
   362
\item[\ttindexbold{Sign.cterm_of} $sign$ $t$] \index{signatures}
lcp@104
   363
certifies $t$ with respect to signature~$sign$.
lcp@104
   364
lcp@104
   365
\item[\ttindexbold{Sign.read_cterm} $sign$ ($s$, $T$)] 
lcp@104
   366
reads the string~$s$ using the syntax of~$sign$, creating a certified term.
lcp@104
   367
The term is checked to have type~$T$; this type also tells the parser what
lcp@104
   368
kind of phrase to parse.
lcp@104
   369
lcp@104
   370
\item[\ttindexbold{Sign.rep_cterm} $ct$] 
lcp@104
   371
decomposes $ct$ as a record containing its type, the term itself, its
lcp@104
   372
signature, and the maximum subscript of its unknowns.  The type and maximum
lcp@104
   373
subscript are computed during certification.
lcp@104
   374
\end{description}
lcp@104
   375
lcp@104
   376
lcp@104
   377
\section{Types}
lcp@104
   378
\index{types|bold}
lcp@104
   379
Types belong to the \ML{} type \ttindexbold{typ}, which is a concrete
lcp@104
   380
datatype with three constructors.  Types are classified by sorts, which are
lcp@104
   381
lists of classes.  A class is represented by a string.
lcp@104
   382
\begin{ttbox}
lcp@104
   383
type class = string;
lcp@104
   384
type sort  = class list;
lcp@104
   385
lcp@104
   386
datatype typ = Type  of string * typ list
lcp@104
   387
             | TFree of string * sort
lcp@104
   388
             | TVar  of indexname * sort;
lcp@104
   389
lcp@104
   390
infixr 5 -->;
lcp@104
   391
fun S --> T = Type("fun",[S,T]);
lcp@104
   392
\end{ttbox}
lcp@104
   393
\begin{description}
lcp@104
   394
\item[\ttindexbold{Type}($a$, $Ts$)] 
lcp@104
   395
applies the {\bf type constructor} named~$a$ to the type operands~$Ts$.
lcp@104
   396
Type constructors include~\ttindexbold{fun}, the binary function space
lcp@104
   397
constructor, as well as nullary type constructors such
lcp@104
   398
as~\ttindexbold{prop}.  Other type constructors may be introduced.  In
lcp@104
   399
expressions, but not in patterns, \hbox{\tt$S$-->$T$} is a convenient
lcp@104
   400
shorthand for function types.
lcp@104
   401
lcp@104
   402
\item[\ttindexbold{TFree}($a$, $s$)] 
lcp@104
   403
is the {\bf free type variable} with name~$a$ and sort~$s$.
lcp@104
   404
lcp@104
   405
\item[\ttindexbold{TVar}($v$, $s$)] 
lcp@104
   406
is the {\bf scheme type variable} with indexname~$v$ and sort~$s$.  Scheme
lcp@104
   407
type variables are essentially free type variables, but may be instantiated
lcp@104
   408
during unification.
lcp@104
   409
\end{description}
lcp@104
   410
lcp@104
   411
lcp@104
   412
\section{Certified types}
lcp@104
   413
\index{types!certified|bold}
lcp@104
   414
Certified types, which are analogous to certified terms, have type 
lcp@104
   415
\ttindexbold{Sign.ctyp}.
lcp@104
   416
lcp@104
   417
\subsection{Printing types}
lcp@104
   418
\index{printing!types|bold}
lcp@104
   419
\begin{ttbox} 
lcp@104
   420
Sign.string_of_ctyp :      Sign.ctyp -> string
lcp@104
   421
Sign.string_of_typ  : Sign.sg -> typ -> string
lcp@104
   422
\end{ttbox}
lcp@104
   423
\begin{description}
lcp@104
   424
\item[\ttindexbold{Sign.string_of_ctyp} $cT$] 
lcp@104
   425
displays $cT$ as a string.
lcp@104
   426
lcp@104
   427
\item[\ttindexbold{Sign.string_of_typ} $sign$ $T$] 
lcp@104
   428
displays $T$ as a string, using the syntax of~$sign$.
lcp@104
   429
\end{description}
lcp@104
   430
lcp@104
   431
lcp@104
   432
\subsection{Making and inspecting certified types}
lcp@104
   433
\begin{ttbox} 
lcp@104
   434
Sign.ctyp_of  : Sign.sg -> typ -> Sign.ctyp
lcp@104
   435
Sign.rep_ctyp : Sign.ctyp -> \{T: typ, sign: Sign.sg\}
lcp@104
   436
\end{ttbox}
lcp@104
   437
\begin{description}
lcp@104
   438
\item[\ttindexbold{Sign.ctyp_of} $sign$ $T$] \index{signatures}
lcp@104
   439
certifies $T$ with respect to signature~$sign$.
lcp@104
   440
lcp@104
   441
\item[\ttindexbold{Sign.rep_ctyp} $cT$] 
lcp@104
   442
decomposes $cT$ as a record containing the type itself and its signature.
lcp@104
   443
\end{description}
lcp@104
   444
lcp@104
   445
\index{theories|)}