doc-src/Intro/advanced.tex
changeset 303 0746399cfd44
parent 296 e1f6cd9f682e
child 307 994dbab40849
equal deleted inserted replaced
302:7e2cffe28eb5 303:0746399cfd44
   350 default sort for type variables.  A constant declaration can specify an
   350 default sort for type variables.  A constant declaration can specify an
   351 associated concrete syntax.  The translations section specifies rewrite
   351 associated concrete syntax.  The translations section specifies rewrite
   352 rules on abstract syntax trees, for defining notations and abbreviations.
   352 rules on abstract syntax trees, for defining notations and abbreviations.
   353 The {\ML} section contains code to perform arbitrary syntactic
   353 The {\ML} section contains code to perform arbitrary syntactic
   354 transformations.  The main declaration forms are discussed below.
   354 transformations.  The main declaration forms are discussed below.
       
   355 The full syntax can be found in \iflabelundefined{app:TheorySyntax}{the
       
   356   appendix of the {\it Reference Manual}}{Appendix~\ref{app:TheorySyntax}}.
   355 
   357 
   356 All the declaration parts can be omitted.  In the simplest case, $T$ is
   358 All the declaration parts can be omitted.  In the simplest case, $T$ is
   357 just the union of $S@1$,~\ldots,~$S@n$.  New theories always extend one
   359 just the union of $S@1$,~\ldots,~$S@n$.  New theories always extend one
   358 or more other theories, inheriting their types, constants, syntax, etc.
   360 or more other theories, inheriting their types, constants, syntax, etc.
   359 The theory \ttindexbold{Pure} contains nothing but Isabelle's meta-logic.
   361 The theory \ttindexbold{Pure} contains nothing but Isabelle's meta-logic.
   430 end
   432 end
   431 \end{ttbox}
   433 \end{ttbox}
   432 
   434 
   433 
   435 
   434 \subsection{Declaring type constructors}
   436 \subsection{Declaring type constructors}
   435 \indexbold{types!declaring}\indexbold{arities!declaring} 
   437 \indexbold{types!declaring}\indexbold{arities!declaring}
   436 %
   438 %
   437 Types are composed of type variables and {\bf type constructors}.  Each
   439 Types are composed of type variables and {\bf type constructors}.  Each
   438 type constructor takes a fixed number of arguments.  They are declared
   440 type constructor takes a fixed number of arguments.  They are declared
   439 with an \ML-like syntax.  If $list$ takes one type argument, $tree$ takes
   441 with an \ML-like syntax.  If $list$ takes one type argument, $tree$ takes
   440 two arguments and $nat$ takes no arguments, then these type constructors
   442 two arguments and $nat$ takes no arguments, then these type constructors
   513 \begin{warn}
   515 \begin{warn}
   514 Arity declarations resemble constant declarations, but there are {\it no\/}
   516 Arity declarations resemble constant declarations, but there are {\it no\/}
   515 quotation marks!  Types and rules must be quoted because the theory
   517 quotation marks!  Types and rules must be quoted because the theory
   516 translator passes them verbatim to the {\ML} output file.
   518 translator passes them verbatim to the {\ML} output file.
   517 \end{warn}
   519 \end{warn}
       
   520 
       
   521 \subsection{Type synonyms}
       
   522 \indexbold{types!synonyms}\index{types!abbreviations|see{synonyms}}
       
   523 
       
   524 Isabelle supports {\bf type synonyms} ({\bf abbreviations}) which are similar
       
   525 to those found in ML. Such synonyms are defined in the type declaration part
       
   526 and are fairly self explanatory:
       
   527 \begin{ttbox}
       
   528 types gate = "[o,o] => o"
       
   529       'a pred = "'a => o"
       
   530       ('a,'b)nuf = "'b => 'a"
       
   531 \end{ttbox}
       
   532 Type declarations and synonyms can be mixed arbitrarily:
       
   533 \begin{ttbox}
       
   534 types nat
       
   535       'a stream = "nat => 'a"
       
   536       signal = "nat stream"
       
   537       'a list
       
   538 \end{ttbox}
       
   539 A synonym is merely an abbreviation for some existing type expression. Hence
       
   540 synonyms may not be recursive! Internally all synonyms are fully expanded. As
       
   541 a consequence Isabelle output never contains synonyms. Their main purpose is
       
   542 to improve the readability of theories. Synonyms can be used just like any
       
   543 other type:
       
   544 \begin{ttbox}
       
   545 consts and,or :: "gate"
       
   546        negate :: "signal => signal"
       
   547 \end{ttbox}
   518 
   548 
   519 \subsection{Infixes and Mixfixes}
   549 \subsection{Infixes and Mixfixes}
   520 \indexbold{infix operators}\index{examples!of theories}
   550 \indexbold{infix operators}\index{examples!of theories}
   521 The constant declaration part of the theory
   551 The constant declaration part of the theory
   522 \begin{ttbox}
   552 \begin{ttbox}