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