doc-src/AxClass/generated/Product.tex
author wenzelm
Mon, 12 Feb 2001 20:43:12 +0100
changeset 11099 b301d1f72552
parent 11071 4e542a09b582
child 11964 828ea309dc21
permissions -rw-r--r--
\<subseteq>;
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}%
9921
7acefd99e748 updated;
wenzelm
parents: 9767
diff changeset
     3
\def\isabellecontext{Product}%
8903
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
     4
%
10395
7ef380745743 updated;
wenzelm
parents: 10310
diff changeset
     5
\isamarkupheader{Syntactic classes%
7ef380745743 updated;
wenzelm
parents: 10310
diff changeset
     6
}
9672
2c208c98f541 updated;
wenzelm
parents: 9665
diff changeset
     7
\isacommand{theory}\ Product\ {\isacharequal}\ Main{\isacharcolon}%
8903
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
     8
\begin{isamarkuptext}%
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
     9
\medskip\noindent There is still a feature of Isabelle's type system
8907
wenzelm
parents: 8903
diff changeset
    10
 left that we have not yet discussed.  When declaring polymorphic
10140
ba9297b71897 major cleanup -- improved typesetting;
wenzelm
parents: 9921
diff changeset
    11
 constants \isa{c\ {\isasymColon}\ {\isasymsigma}}, the type variables occurring in \isa{{\isasymsigma}}
ba9297b71897 major cleanup -- improved typesetting;
wenzelm
parents: 9921
diff changeset
    12
 may be constrained by type classes (or even general sorts) in an
8907
wenzelm
parents: 8903
diff changeset
    13
 arbitrary way.  Note that by default, in Isabelle/HOL the declaration
11071
wenzelm
parents: 10395
diff changeset
    14
 \isa{{\isasymodot}\ {\isasymColon}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a} is actually an abbreviation for \isa{{\isasymodot}\ {\isasymColon}\ {\isacharprime}a{\isasymColon}term\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a} Since class \isa{term} is the universal
wenzelm
parents: 10395
diff changeset
    15
 class of HOL, this is not really a constraint at all.
8903
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    16
10140
ba9297b71897 major cleanup -- improved typesetting;
wenzelm
parents: 9921
diff changeset
    17
 The \isa{product} class below provides a less degenerate example of
8903
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
11099
b301d1f72552 \<subseteq>;
wenzelm
parents: 11071
diff changeset
    21
\ \ product\ {\isasymsubseteq}\ {\isachardoublequote}term{\isachardoublequote}\isanewline
8890
9a44d8d98731 snapshot of new Isar'ized version;
wenzelm
parents:
diff changeset
    22
\isacommand{consts}\isanewline
10207
c7c64cd26fc9 updated;
wenzelm
parents: 10140
diff changeset
    23
\ \ 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}%
8903
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    24
\begin{isamarkuptext}%
10140
ba9297b71897 major cleanup -- improved typesetting;
wenzelm
parents: 9921
diff changeset
    25
Here class \isa{product} is defined as subclass of \isa{term}
ba9297b71897 major cleanup -- improved typesetting;
wenzelm
parents: 9921
diff changeset
    26
 without any additional axioms.  This effects in logical equivalence
ba9297b71897 major cleanup -- improved typesetting;
wenzelm
parents: 9921
diff changeset
    27
 of \isa{product} and \isa{term}, as is reflected by the trivial
ba9297b71897 major cleanup -- improved typesetting;
wenzelm
parents: 9921
diff changeset
    28
 introduction rule generated for this definition.
8903
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    29
11071
wenzelm
parents: 10395
diff changeset
    30
 \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}term\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a}
wenzelm
parents: 10395
diff changeset
    31
 anyway?  In this particular case where \isa{product\ {\isasymequiv}\ term}, it
wenzelm
parents: 10395
diff changeset
    32
 should be obvious that both declarations are the same from the
wenzelm
parents: 10395
diff changeset
    33
 logic's point of view.  It even makes the most sense to remove sort
wenzelm
parents: 10395
diff changeset
    34
 constraints from constant declarations, as far as the purely logical
wenzelm
parents: 10395
diff changeset
    35
 meaning is concerned \cite{Wenzel:1997:TPHOL}.
8903
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    36
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    37
 On the other hand there are syntactic differences, of course.
10140
ba9297b71897 major cleanup -- improved typesetting;
wenzelm
parents: 9921
diff changeset
    38
 Constants \isa{{\isasymodot}} on some type \isa{{\isasymtau}} are rejected by the
ba9297b71897 major cleanup -- improved typesetting;
wenzelm
parents: 9921
diff changeset
    39
 type-checker, unless the arity \isa{{\isasymtau}\ {\isasymColon}\ product} is part of the
ba9297b71897 major cleanup -- improved typesetting;
wenzelm
parents: 9921
diff changeset
    40
 type signature.  In our example, this arity may be always added when
10310
d78de58fe368 updated;
wenzelm
parents: 10223
diff changeset
    41
 required by means of an $\INSTANCE$ with the default proof $\DDOT$.
8903
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    42
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    43
 \medskip Thus, we may observe the following discipline of using
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    44
 syntactic classes.  Overloaded polymorphic constants have their type
10140
ba9297b71897 major cleanup -- improved typesetting;
wenzelm
parents: 9921
diff changeset
    45
 arguments restricted to an associated (logically trivial) class
ba9297b71897 major cleanup -- improved typesetting;
wenzelm
parents: 9921
diff changeset
    46
 \isa{c}.  Only immediately before \emph{specifying} these constants
ba9297b71897 major cleanup -- improved typesetting;
wenzelm
parents: 9921
diff changeset
    47
 on a certain type \isa{{\isasymtau}} do we instantiate \isa{{\isasymtau}\ {\isasymColon}\ c}.
8903
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    48
10140
ba9297b71897 major cleanup -- improved typesetting;
wenzelm
parents: 9921
diff changeset
    49
 This is done for class \isa{product} and type \isa{bool} as
ba9297b71897 major cleanup -- improved typesetting;
wenzelm
parents: 9921
diff changeset
    50
 follows.%
8903
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    51
\end{isamarkuptext}%
10310
d78de58fe368 updated;
wenzelm
parents: 10223
diff changeset
    52
\isacommand{instance}\ bool\ {\isacharcolon}{\isacharcolon}\ product\ \isacommand{{\isachardot}{\isachardot}}\isanewline
9665
2a6d7f1409f9 updated;
wenzelm
parents: 9519
diff changeset
    53
\isacommand{defs}\ {\isacharparenleft}\isakeyword{overloaded}{\isacharparenright}\isanewline
10140
ba9297b71897 major cleanup -- improved typesetting;
wenzelm
parents: 9921
diff changeset
    54
\ \ product{\isacharunderscore}bool{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequote}x\ {\isasymodot}\ y\ {\isasymequiv}\ x\ {\isasymand}\ y{\isachardoublequote}%
8903
78d6e47469e4 new Isar version;
wenzelm
parents: 8890
diff changeset
    55
\begin{isamarkuptext}%
10140
ba9297b71897 major cleanup -- improved typesetting;
wenzelm
parents: 9921
diff changeset
    56
The definition \isa{prod{\isacharunderscore}bool{\isacharunderscore}def} becomes syntactically
ba9297b71897 major cleanup -- improved typesetting;
wenzelm
parents: 9921
diff changeset
    57
 well-formed only after the arity \isa{bool\ {\isasymColon}\ product} is made
ba9297b71897 major cleanup -- improved typesetting;
wenzelm
parents: 9921
diff changeset
    58
 known to the type checker.
8903
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
10223
wenzelm
parents: 10207
diff changeset
    61
 directly connected with $\INSTANCE$ at all!  We were just following
wenzelm
parents: 10207
diff changeset
    62
 our convention to specify \isa{{\isasymodot}} on \isa{bool} after having
wenzelm
parents: 10207
diff changeset
    63
 instantiated \isa{bool\ {\isasymColon}\ product}.  Isabelle does not require
wenzelm
parents: 10207
diff changeset
    64
 these definitions, which is in contrast to programming languages like
wenzelm
parents: 10207
diff changeset
    65
 Haskell \cite{haskell-report}.
8903
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
10140
ba9297b71897 major cleanup -- improved typesetting;
wenzelm
parents: 9921
diff changeset
    74
 This style of \texttt{instance} would not make much sense in
ba9297b71897 major cleanup -- improved typesetting;
wenzelm
parents: 9921
diff changeset
    75
 Isabelle's meta-logic, because there is no internal notion of
ba9297b71897 major cleanup -- improved typesetting;
wenzelm
parents: 9921
diff changeset
    76
 ``providing 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: