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