doc-src/AxClass/generated/Product.tex
author wenzelm
Fri, 01 Sep 2000 00:27:41 +0200
changeset 9767 dc2ee9b2e065
parent 9672 2c208c98f541
child 9921 7acefd99e748
permissions -rw-r--r--
updated;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9767
dc2ee9b2e065 updated;
wenzelm
parents: 9672
diff changeset
     1
%
dc2ee9b2e065 updated;
wenzelm
parents: 9672
diff changeset
     2
\begin{isabellebody}%
8903
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
     3
%
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
     4
\isamarkupheader{Syntactic classes}
9672
2c208c98f541 updated;
wenzelm
parents: 9665
diff changeset
     5
\isacommand{theory}\ Product\ {\isacharequal}\ Main{\isacharcolon}%
8903
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
     6
\begin{isamarkuptext}%
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
     7
\medskip\noindent There is still a feature of Isabelle's type system
8907
wenzelm
parents: 8903
diff changeset
     8
 left that we have not yet discussed.  When declaring polymorphic
wenzelm
parents: 8903
diff changeset
     9
 constants $c :: \sigma$, the type variables occurring in $\sigma$ may
wenzelm
parents: 8903
diff changeset
    10
 be constrained by type classes (or even general sorts) in an
wenzelm
parents: 8903
diff changeset
    11
 arbitrary way.  Note that by default, in Isabelle/HOL the declaration
wenzelm
parents: 8903
diff changeset
    12
 $\TIMES :: \alpha \To \alpha \To \alpha$ is actually an abbreviation
wenzelm
parents: 8903
diff changeset
    13
 for $\TIMES :: (\alpha::term) \To \alpha \To \alpha$.  Since class
wenzelm
parents: 8903
diff changeset
    14
 $term$ is the universal class of HOL, this is not really a constraint
wenzelm
parents: 8903
diff changeset
    15
 at all.
8903
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    16
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    17
 The $product$ class below provides a less degenerate example of
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    18
 syntactic type classes.%
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    19
\end{isamarkuptext}%
8890
9a44d8d98731 snapshot of new Isar'ized version;
wenzelm
parents:
diff changeset
    20
\isacommand{axclass}\isanewline
9665
2a6d7f1409f9 updated;
wenzelm
parents: 9519
diff changeset
    21
\ \ product\ {\isacharless}\ {\isachardoublequote}term{\isachardoublequote}\isanewline
8890
9a44d8d98731 snapshot of new Isar'ized version;
wenzelm
parents:
diff changeset
    22
\isacommand{consts}\isanewline
9672
2c208c98f541 updated;
wenzelm
parents: 9665
diff changeset
    23
\ \ product\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a{\isacharcolon}{\isacharcolon}product\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a{\isachardoublequote}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequote}{\isasymOtimes}{\isachardoublequote}\ \isadigit{7}\isadigit{0}{\isacharparenright}%
8903
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    24
\begin{isamarkuptext}%
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    25
Here class $product$ is defined as subclass of $term$ without any
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    26
 additional axioms.  This effects in logical equivalence of $product$
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    27
 and $term$, as is reflected by the trivial introduction rule
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    28
 generated for this definition.
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    29
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    30
 \medskip So what is the difference of declaring $\TIMES :: (\alpha ::
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    31
 product) \To \alpha \To \alpha$ vs.\ declaring $\TIMES :: (\alpha ::
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    32
 term) \To \alpha \To \alpha$ anyway?  In this particular case where
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    33
 $product \equiv term$, it should be obvious that both declarations
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    34
 are the same from the logic's point of view.  It even makes the most
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    35
 sense to remove sort constraints from constant declarations, as far
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    36
 as the purely logical meaning is concerned \cite{Wenzel:1997:TPHOL}.
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    37
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    38
 On the other hand there are syntactic differences, of course.
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    39
 Constants $\TIMES^\tau$ are rejected by the type-checker, unless the
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    40
 arity $\tau :: product$ is part of the type signature.  In our
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    41
 example, this arity may be always added when required by means of an
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    42
 $\isarkeyword{instance}$ with the trivial proof $\BY{intro_classes}$.
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    43
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    44
 \medskip Thus, we may observe the following discipline of using
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    45
 syntactic classes.  Overloaded polymorphic constants have their type
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    46
 arguments restricted to an associated (logically trivial) class $c$.
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    47
 Only immediately before \emph{specifying} these constants on a
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    48
 certain type $\tau$ do we instantiate $\tau :: c$.
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    49
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    50
 This is done for class $product$ and type $bool$ as follows.%
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    51
\end{isamarkuptext}%
9672
2c208c98f541 updated;
wenzelm
parents: 9665
diff changeset
    52
\isacommand{instance}\ bool\ {\isacharcolon}{\isacharcolon}\ product\isanewline
9665
2a6d7f1409f9 updated;
wenzelm
parents: 9519
diff changeset
    53
\ \ \isacommand{by}\ intro{\isacharunderscore}classes\isanewline
2a6d7f1409f9 updated;
wenzelm
parents: 9519
diff changeset
    54
\isacommand{defs}\ {\isacharparenleft}\isakeyword{overloaded}{\isacharparenright}\isanewline
9672
2c208c98f541 updated;
wenzelm
parents: 9665
diff changeset
    55
\ \ product{\isacharunderscore}bool{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequote}x\ {\isasymOtimes}\ y\ {\isasymequiv}\ x\ {\isasymand}\ y{\isachardoublequote}%
8903
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    56
\begin{isamarkuptext}%
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    57
The definition $prod_bool_def$ becomes syntactically well-formed only
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    58
 after the arity $bool :: product$ is made known to the type checker.
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    59
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    60
 \medskip It is very important to see that above $\DEFS$ are not
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    61
 directly connected with $\isarkeyword{instance}$ at all!  We were
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    62
 just following our convention to specify $\TIMES$ on $bool$ after
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    63
 having instantiated $bool :: product$.  Isabelle does not require
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    64
 these definitions, which is in contrast to programming languages like
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    65
 Haskell \cite{haskell-report}.
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    66
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    67
 \medskip While Isabelle type classes and those of Haskell are almost
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    68
 the same as far as type-checking and type inference are concerned,
8907
wenzelm
parents: 8903
diff changeset
    69
 there are important semantic differences.  Haskell classes require
wenzelm
parents: 8903
diff changeset
    70
 their instances to \emph{provide operations} of certain \emph{names}.
8903
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    71
 Therefore, its \texttt{instance} has a \texttt{where} part that tells
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    72
 the system what these ``member functions'' should be.
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    73
8907
wenzelm
parents: 8903
diff changeset
    74
 This style of \texttt{instance} won't make much sense in Isabelle's
wenzelm
parents: 8903
diff changeset
    75
 meta-logic, because there is no internal notion of ``providing
wenzelm
parents: 8903
diff changeset
    76
 operations'' or even ``names of functions''.%
8903
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    77
\end{isamarkuptext}%
9767
dc2ee9b2e065 updated;
wenzelm
parents: 9672
diff changeset
    78
\isacommand{end}\end{isabellebody}%
9145
9f7b8de5bfaf updated;
wenzelm
parents: 8907
diff changeset
    79
%%% Local Variables:
9f7b8de5bfaf updated;
wenzelm
parents: 8907
diff changeset
    80
%%% mode: latex
9f7b8de5bfaf updated;
wenzelm
parents: 8907
diff changeset
    81
%%% TeX-master: "root"
9f7b8de5bfaf updated;
wenzelm
parents: 8907
diff changeset
    82
%%% End: