| 17133 |      1 | %
 | 
|  |      2 | \begin{isabellebody}%
 | 
|  |      3 | \def\isabellecontext{Product}%
 | 
|  |      4 | %
 | 
|  |      5 | \isamarkupheader{Syntactic classes%
 | 
|  |      6 | }
 | 
| 17175 |      7 | \isamarkuptrue%
 | 
| 17133 |      8 | %
 | 
|  |      9 | \isadelimtheory
 | 
|  |     10 | %
 | 
|  |     11 | \endisadelimtheory
 | 
|  |     12 | %
 | 
|  |     13 | \isatagtheory
 | 
| 17175 |     14 | \isacommand{theory}\isamarkupfalse%
 | 
|  |     15 | \ Product\ \isakeyword{imports}\ Main\ \isakeyword{begin}%
 | 
| 17133 |     16 | \endisatagtheory
 | 
|  |     17 | {\isafoldtheory}%
 | 
|  |     18 | %
 | 
|  |     19 | \isadelimtheory
 | 
|  |     20 | %
 | 
|  |     21 | \endisadelimtheory
 | 
|  |     22 | %
 | 
|  |     23 | \begin{isamarkuptext}%
 | 
|  |     24 | \medskip\noindent There is still a feature of Isabelle's type system
 | 
|  |     25 |   left that we have not yet discussed.  When declaring polymorphic
 | 
|  |     26 |   constants \isa{c\ {\isasymColon}\ {\isasymsigma}}, the type variables occurring in \isa{{\isasymsigma}}
 | 
|  |     27 |   may be constrained by type classes (or even general sorts) in an
 | 
|  |     28 |   arbitrary way.  Note that by default, in Isabelle/HOL the
 | 
|  |     29 |   declaration \isa{{\isasymodot}\ {\isasymColon}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a} is actually an abbreviation
 | 
|  |     30 |   for \isa{{\isasymodot}\ {\isasymColon}\ {\isacharprime}a{\isasymColon}type\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a} Since class \isa{type} is the
 | 
|  |     31 |   universal class of HOL, this is not really a constraint at all.
 | 
|  |     32 | 
 | 
|  |     33 |  The \isa{product} class below provides a less degenerate example of
 | 
|  |     34 |  syntactic type classes.%
 | 
|  |     35 | \end{isamarkuptext}%
 | 
| 17175 |     36 | \isamarkuptrue%
 | 
|  |     37 | \isacommand{axclass}\isamarkupfalse%
 | 
|  |     38 | \isanewline
 | 
| 17133 |     39 | \ \ product\ {\isasymsubseteq}\ type\isanewline
 | 
| 17175 |     40 | \isacommand{consts}\isamarkupfalse%
 | 
|  |     41 | \isanewline
 | 
|  |     42 | \ \ product\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a{\isasymColon}product\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a{\isachardoublequoteclose}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequoteopen}{\isasymodot}{\isachardoublequoteclose}\ {\isadigit{7}}{\isadigit{0}}{\isacharparenright}%
 | 
| 17133 |     43 | \begin{isamarkuptext}%
 | 
|  |     44 | Here class \isa{product} is defined as subclass of \isa{type}
 | 
|  |     45 |   without any additional axioms.  This effects in logical equivalence
 | 
|  |     46 |   of \isa{product} and \isa{type}, as is reflected by the trivial
 | 
|  |     47 |   introduction rule generated for this definition.
 | 
|  |     48 | 
 | 
|  |     49 |   \medskip So what is the difference of declaring \isa{{\isasymodot}\ {\isasymColon}\ {\isacharprime}a{\isasymColon}product\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a} vs.\ declaring \isa{{\isasymodot}\ {\isasymColon}\ {\isacharprime}a{\isasymColon}type\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a} anyway?  In this particular case where \isa{product\ {\isasymequiv}\ type}, it should be obvious that both declarations are the same
 | 
|  |     50 |   from the logic's point of view.  It even makes the most sense to
 | 
|  |     51 |   remove sort constraints from constant declarations, as far as the
 | 
|  |     52 |   purely logical meaning is concerned \cite{Wenzel:1997:TPHOL}.
 | 
|  |     53 | 
 | 
|  |     54 |   On the other hand there are syntactic differences, of course.
 | 
|  |     55 |   Constants \isa{{\isasymodot}} on some type \isa{{\isasymtau}} are rejected by the
 | 
|  |     56 |   type-checker, unless the arity \isa{{\isasymtau}\ {\isasymColon}\ product} is part of the
 | 
|  |     57 |   type signature.  In our example, this arity may be always added when
 | 
|  |     58 |   required by means of an $\INSTANCE$ with the default proof $\DDOT$.
 | 
|  |     59 | 
 | 
|  |     60 |   \medskip Thus, we may observe the following discipline of using
 | 
|  |     61 |   syntactic classes.  Overloaded polymorphic constants have their type
 | 
|  |     62 |   arguments restricted to an associated (logically trivial) class
 | 
|  |     63 |   \isa{c}.  Only immediately before \emph{specifying} these
 | 
|  |     64 |   constants on a certain type \isa{{\isasymtau}} do we instantiate \isa{{\isasymtau}\ {\isasymColon}\ c}.
 | 
|  |     65 | 
 | 
|  |     66 |   This is done for class \isa{product} and type \isa{bool} as
 | 
|  |     67 |   follows.%
 | 
|  |     68 | \end{isamarkuptext}%
 | 
| 17175 |     69 | \isamarkuptrue%
 | 
|  |     70 | \isacommand{instance}\isamarkupfalse%
 | 
|  |     71 | \ bool\ {\isacharcolon}{\isacharcolon}\ product%
 | 
| 17133 |     72 | \isadelimproof
 | 
|  |     73 | \ %
 | 
|  |     74 | \endisadelimproof
 | 
|  |     75 | %
 | 
|  |     76 | \isatagproof
 | 
| 17175 |     77 | \isacommand{{\isachardot}{\isachardot}}\isamarkupfalse%
 | 
|  |     78 | %
 | 
| 17133 |     79 | \endisatagproof
 | 
|  |     80 | {\isafoldproof}%
 | 
|  |     81 | %
 | 
|  |     82 | \isadelimproof
 | 
|  |     83 | %
 | 
|  |     84 | \endisadelimproof
 | 
|  |     85 | \isanewline
 | 
| 17175 |     86 | \isacommand{defs}\isamarkupfalse%
 | 
|  |     87 | \ {\isacharparenleft}\isakeyword{overloaded}{\isacharparenright}\isanewline
 | 
|  |     88 | \ \ product{\isacharunderscore}bool{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}x\ {\isasymodot}\ y\ {\isasymequiv}\ x\ {\isasymand}\ y{\isachardoublequoteclose}%
 | 
| 17133 |     89 | \begin{isamarkuptext}%
 | 
|  |     90 | The definition \isa{prod{\isacharunderscore}bool{\isacharunderscore}def} becomes syntactically
 | 
|  |     91 |  well-formed only after the arity \isa{bool\ {\isasymColon}\ product} is made
 | 
|  |     92 |  known to the type checker.
 | 
|  |     93 | 
 | 
|  |     94 |  \medskip It is very important to see that above $\DEFS$ are not
 | 
|  |     95 |  directly connected with $\INSTANCE$ at all!  We were just following
 | 
|  |     96 |  our convention to specify \isa{{\isasymodot}} on \isa{bool} after having
 | 
|  |     97 |  instantiated \isa{bool\ {\isasymColon}\ product}.  Isabelle does not require
 | 
|  |     98 |  these definitions, which is in contrast to programming languages like
 | 
|  |     99 |  Haskell \cite{haskell-report}.
 | 
|  |    100 | 
 | 
|  |    101 |  \medskip While Isabelle type classes and those of Haskell are almost
 | 
|  |    102 |  the same as far as type-checking and type inference are concerned,
 | 
|  |    103 |  there are important semantic differences.  Haskell classes require
 | 
|  |    104 |  their instances to \emph{provide operations} of certain \emph{names}.
 | 
|  |    105 |  Therefore, its \texttt{instance} has a \texttt{where} part that tells
 | 
|  |    106 |  the system what these ``member functions'' should be.
 | 
|  |    107 | 
 | 
|  |    108 |  This style of \texttt{instance} would not make much sense in
 | 
|  |    109 |  Isabelle's meta-logic, because there is no internal notion of
 | 
|  |    110 |  ``providing operations'' or even ``names of functions''.%
 | 
|  |    111 | \end{isamarkuptext}%
 | 
| 17175 |    112 | \isamarkuptrue%
 | 
| 17133 |    113 | %
 | 
|  |    114 | \isadelimtheory
 | 
|  |    115 | %
 | 
|  |    116 | \endisadelimtheory
 | 
|  |    117 | %
 | 
|  |    118 | \isatagtheory
 | 
| 17175 |    119 | \isacommand{end}\isamarkupfalse%
 | 
|  |    120 | %
 | 
| 17133 |    121 | \endisatagtheory
 | 
|  |    122 | {\isafoldtheory}%
 | 
|  |    123 | %
 | 
|  |    124 | \isadelimtheory
 | 
|  |    125 | %
 | 
|  |    126 | \endisadelimtheory
 | 
|  |    127 | \isanewline
 | 
|  |    128 | \end{isabellebody}%
 | 
|  |    129 | %%% Local Variables:
 | 
|  |    130 | %%% mode: latex
 | 
|  |    131 | %%% TeX-master: "root"
 | 
|  |    132 | %%% End:
 |