doc-src/Classes/Thy/document/Classes.tex
author wenzelm
Tue, 03 Mar 2009 19:30:43 +0100
changeset 30229 9861257b18e6
parent 30209 doc-src/IsarAdvanced/Classes/Thy/document/Classes.tex@9e245d524997
parent 30227 doc-src/IsarAdvanced/Classes/Thy/document/Classes.tex@853abb4853cc
child 30729 461ee3e49ad3
permissions -rw-r--r--
merged
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
     1
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
     2
\begin{isabellebody}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
     3
\def\isabellecontext{Classes}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
     4
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
     5
\isadelimtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
     6
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
     7
\endisadelimtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
     8
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
     9
\isatagtheory
28565
haftmann
parents: 28540
diff changeset
    10
\isacommand{theory}\isamarkupfalse%
haftmann
parents: 28540
diff changeset
    11
\ Classes\isanewline
haftmann
parents: 28540
diff changeset
    12
\isakeyword{imports}\ Main\ Setup\isanewline
haftmann
parents: 28540
diff changeset
    13
\isakeyword{begin}%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    14
\endisatagtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    15
{\isafoldtheory}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    16
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    17
\isadelimtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    18
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    19
\endisadelimtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    20
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    21
\isamarkupsection{Introduction%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    22
}
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    23
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    24
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    25
\begin{isamarkuptext}%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    26
Type classes were introduces by Wadler and Blott \cite{wadler89how}
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    27
  into the Haskell language, to allow for a reasonable implementation
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    28
  of overloading\footnote{throughout this tutorial, we are referring
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    29
  to classical Haskell 1.0 type classes, not considering
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    30
  later additions in expressiveness}.
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    31
  As a canonical example, a polymorphic equality function
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    32
  \isa{eq\ {\isasymColon}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ bool} which is overloaded on different
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
    33
  types for \isa{{\isasymalpha}}, which is achieved by splitting introduction
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    34
  of the \isa{eq} function from its overloaded definitions by means
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    35
  of \isa{class} and \isa{instance} declarations:
30227
853abb4853cc tuned manuals
haftmann
parents: 30226
diff changeset
    36
  \footnote{syntax here is a kind of isabellized Haskell}
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    37
28565
haftmann
parents: 28540
diff changeset
    38
  \begin{quote}
haftmann
parents: 28540
diff changeset
    39
30227
853abb4853cc tuned manuals
haftmann
parents: 30226
diff changeset
    40
  \noindent\isa{class\ eq\ where} \\
28565
haftmann
parents: 28540
diff changeset
    41
  \hspace*{2ex}\isa{eq\ {\isasymColon}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ bool}
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    42
28565
haftmann
parents: 28540
diff changeset
    43
  \medskip\noindent\isa{instance\ nat\ {\isasymColon}\ eq\ where} \\
haftmann
parents: 28540
diff changeset
    44
  \hspace*{2ex}\isa{eq\ {\isadigit{0}}\ {\isadigit{0}}\ {\isacharequal}\ True} \\
haftmann
parents: 28540
diff changeset
    45
  \hspace*{2ex}\isa{eq\ {\isadigit{0}}\ {\isacharunderscore}\ {\isacharequal}\ False} \\
haftmann
parents: 28540
diff changeset
    46
  \hspace*{2ex}\isa{eq\ {\isacharunderscore}\ {\isadigit{0}}\ {\isacharequal}\ False} \\
haftmann
parents: 28540
diff changeset
    47
  \hspace*{2ex}\isa{eq\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isacharparenleft}Suc\ m{\isacharparenright}\ {\isacharequal}\ eq\ n\ m}
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    48
28948
1860f016886d fixed typo
haftmann
parents: 28947
diff changeset
    49
  \medskip\noindent\isa{instance\ {\isacharparenleft}{\isasymalpha}{\isasymColon}eq{\isacharcomma}\ {\isasymbeta}{\isasymColon}eq{\isacharparenright}\ pair\ {\isasymColon}\ eq\ where} \\
28565
haftmann
parents: 28540
diff changeset
    50
  \hspace*{2ex}\isa{eq\ {\isacharparenleft}x{\isadigit{1}}{\isacharcomma}\ y{\isadigit{1}}{\isacharparenright}\ {\isacharparenleft}x{\isadigit{2}}{\isacharcomma}\ y{\isadigit{2}}{\isacharparenright}\ {\isacharequal}\ eq\ x{\isadigit{1}}\ x{\isadigit{2}}\ {\isasymand}\ eq\ y{\isadigit{1}}\ y{\isadigit{2}}}
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    51
28565
haftmann
parents: 28540
diff changeset
    52
  \medskip\noindent\isa{class\ ord\ extends\ eq\ where} \\
haftmann
parents: 28540
diff changeset
    53
  \hspace*{2ex}\isa{less{\isacharunderscore}eq\ {\isasymColon}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ bool} \\
haftmann
parents: 28540
diff changeset
    54
  \hspace*{2ex}\isa{less\ {\isasymColon}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ bool}
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    55
28565
haftmann
parents: 28540
diff changeset
    56
  \end{quote}
haftmann
parents: 28540
diff changeset
    57
haftmann
parents: 28540
diff changeset
    58
  \noindent Type variables are annotated with (finitely many) classes;
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    59
  these annotations are assertions that a particular polymorphic type
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    60
  provides definitions for overloaded functions.
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    61
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    62
  Indeed, type classes not only allow for simple overloading
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    63
  but form a generic calculus, an instance of order-sorted
23956
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
    64
  algebra \cite{Nipkow-Prehofer:1993,nipkow-sorts93,Wenzel:1997:TPHOL}.
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    65
28540
haftmann
parents: 27507
diff changeset
    66
  From a software engeneering point of view, type classes
haftmann
parents: 27507
diff changeset
    67
  roughly correspond to interfaces in object-oriented languages like Java;
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    68
  so, it is naturally desirable that type classes do not only
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
    69
  provide functions (class parameters) but also state specifications
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    70
  implementations must obey.  For example, the \isa{class\ eq}
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
    71
  above could be given the following specification, demanding that
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
    72
  \isa{class\ eq} is an equivalence relation obeying reflexivity,
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
    73
  symmetry and transitivity:
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    74
28565
haftmann
parents: 28540
diff changeset
    75
  \begin{quote}
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    76
28565
haftmann
parents: 28540
diff changeset
    77
  \noindent\isa{class\ eq\ where} \\
haftmann
parents: 28540
diff changeset
    78
  \hspace*{2ex}\isa{eq\ {\isasymColon}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ bool} \\
haftmann
parents: 28540
diff changeset
    79
  \isa{satisfying} \\
haftmann
parents: 28540
diff changeset
    80
  \hspace*{2ex}\isa{refl{\isacharcolon}\ eq\ x\ x} \\
haftmann
parents: 28540
diff changeset
    81
  \hspace*{2ex}\isa{sym{\isacharcolon}\ eq\ x\ y\ {\isasymlongleftrightarrow}\ eq\ x\ y} \\
haftmann
parents: 28540
diff changeset
    82
  \hspace*{2ex}\isa{trans{\isacharcolon}\ eq\ x\ y\ {\isasymand}\ eq\ y\ z\ {\isasymlongrightarrow}\ eq\ x\ z}
haftmann
parents: 28540
diff changeset
    83
haftmann
parents: 28540
diff changeset
    84
  \end{quote}
haftmann
parents: 28540
diff changeset
    85
haftmann
parents: 28540
diff changeset
    86
  \noindent From a theoretic point of view, type classes are lightweight
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
    87
  modules; Haskell type classes may be emulated by
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    88
  SML functors \cite{classes_modules}. 
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    89
  Isabelle/Isar offers a discipline of type classes which brings
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    90
  all those aspects together:
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    91
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    92
  \begin{enumerate}
25004
c62c5209487b updated
haftmann
parents: 24991
diff changeset
    93
    \item specifying abstract parameters together with
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    94
       corresponding specifications,
28540
haftmann
parents: 27507
diff changeset
    95
    \item instantiating those abstract parameters by a particular
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    96
       type
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    97
    \item in connection with a ``less ad-hoc'' approach to overloading,
23956
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
    98
    \item with a direct link to the Isabelle module system
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
    99
      (aka locales \cite{kammueller-locales}).
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   100
  \end{enumerate}
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   101
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   102
  \noindent Isar type classes also directly support code generation
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   103
  in a Haskell like fashion.
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   104
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   105
  This tutorial demonstrates common elements of structured specifications
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   106
  and abstract reasoning with type classes by the algebraic hierarchy of
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   107
  semigroups, monoids and groups.  Our background theory is that of
23956
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   108
  Isabelle/HOL \cite{isa-tutorial}, for which some
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   109
  familiarity is assumed.
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   110
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   111
  Here we merely present the look-and-feel for end users.
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   112
  Internally, those are mapped to more primitive Isabelle concepts.
23956
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   113
  See \cite{Haftmann-Wenzel:2006:classes} for more detail.%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   114
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   115
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   116
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   117
\isamarkupsection{A simple algebra example \label{sec:example}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   118
}
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   119
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   120
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   121
\isamarkupsubsection{Class definition%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   122
}
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   123
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   124
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   125
\begin{isamarkuptext}%
28565
haftmann
parents: 28540
diff changeset
   126
Depending on an arbitrary type \isa{{\isasymalpha}}, class \isa{semigroup} introduces a binary operator \isa{{\isacharparenleft}{\isasymotimes}{\isacharparenright}} that is
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   127
  assumed to be associative:%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   128
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   129
\isamarkuptrue%
28565
haftmann
parents: 28540
diff changeset
   130
%
haftmann
parents: 28540
diff changeset
   131
\isadelimquote
haftmann
parents: 28540
diff changeset
   132
%
haftmann
parents: 28540
diff changeset
   133
\endisadelimquote
haftmann
parents: 28540
diff changeset
   134
%
haftmann
parents: 28540
diff changeset
   135
\isatagquote
haftmann
parents: 28540
diff changeset
   136
\isacommand{class}\isamarkupfalse%
29705
a1ecdd8cf81c updated class documentation
haftmann
parents: 29513
diff changeset
   137
\ semigroup\ {\isacharequal}\isanewline
28565
haftmann
parents: 28540
diff changeset
   138
\ \ \isakeyword{fixes}\ mult\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequoteopen}{\isasymotimes}{\isachardoublequoteclose}\ {\isadigit{7}}{\isadigit{0}}{\isacharparenright}\isanewline
haftmann
parents: 28540
diff changeset
   139
\ \ \isakeyword{assumes}\ assoc{\isacharcolon}\ {\isachardoublequoteopen}{\isacharparenleft}x\ {\isasymotimes}\ y{\isacharparenright}\ {\isasymotimes}\ z\ {\isacharequal}\ x\ {\isasymotimes}\ {\isacharparenleft}y\ {\isasymotimes}\ z{\isacharparenright}{\isachardoublequoteclose}%
haftmann
parents: 28540
diff changeset
   140
\endisatagquote
haftmann
parents: 28540
diff changeset
   141
{\isafoldquote}%
haftmann
parents: 28540
diff changeset
   142
%
haftmann
parents: 28540
diff changeset
   143
\isadelimquote
haftmann
parents: 28540
diff changeset
   144
%
haftmann
parents: 28540
diff changeset
   145
\endisadelimquote
haftmann
parents: 28540
diff changeset
   146
%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   147
\begin{isamarkuptext}%
28565
haftmann
parents: 28540
diff changeset
   148
\noindent This \hyperlink{command.class}{\mbox{\isa{\isacommand{class}}}} specification consists of two
haftmann
parents: 28540
diff changeset
   149
  parts: the \qn{operational} part names the class parameter
haftmann
parents: 28540
diff changeset
   150
  (\hyperlink{element.fixes}{\mbox{\isa{\isakeyword{fixes}}}}), the \qn{logical} part specifies properties on them
haftmann
parents: 28540
diff changeset
   151
  (\hyperlink{element.assumes}{\mbox{\isa{\isakeyword{assumes}}}}).  The local \hyperlink{element.fixes}{\mbox{\isa{\isakeyword{fixes}}}} and
haftmann
parents: 28540
diff changeset
   152
  \hyperlink{element.assumes}{\mbox{\isa{\isakeyword{assumes}}}} are lifted to the theory toplevel,
haftmann
parents: 28540
diff changeset
   153
  yielding the global
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   154
  parameter \isa{{\isachardoublequote}mult\ {\isasymColon}\ {\isasymalpha}{\isasymColon}semigroup\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequote}} and the
28565
haftmann
parents: 28540
diff changeset
   155
  global theorem \hyperlink{fact.semigroup.assoc:}{\mbox{\isa{semigroup{\isachardot}assoc{\isacharcolon}}}}~\isa{{\isachardoublequote}{\isasymAnd}x\ y\ z\ {\isasymColon}\ {\isasymalpha}{\isasymColon}semigroup{\isachardot}\ {\isacharparenleft}x\ {\isasymotimes}\ y{\isacharparenright}\ {\isasymotimes}\ z\ {\isacharequal}\ x\ {\isasymotimes}\ {\isacharparenleft}y\ {\isasymotimes}\ z{\isacharparenright}{\isachardoublequote}}.%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   156
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   157
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   158
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   159
\isamarkupsubsection{Class instantiation \label{sec:class_inst}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   160
}
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   161
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   162
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   163
\begin{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   164
The concrete type \isa{int} is made a \isa{semigroup}
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   165
  instance by providing a suitable definition for the class parameter
28565
haftmann
parents: 28540
diff changeset
   166
  \isa{{\isacharparenleft}{\isasymotimes}{\isacharparenright}} and a proof for the specification of \hyperlink{fact.assoc}{\mbox{\isa{assoc}}}.
haftmann
parents: 28540
diff changeset
   167
  This is accomplished by the \hyperlink{command.instantiation}{\mbox{\isa{\isacommand{instantiation}}}} target:%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   168
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   169
\isamarkuptrue%
28565
haftmann
parents: 28540
diff changeset
   170
%
haftmann
parents: 28540
diff changeset
   171
\isadelimquote
haftmann
parents: 28540
diff changeset
   172
%
haftmann
parents: 28540
diff changeset
   173
\endisadelimquote
haftmann
parents: 28540
diff changeset
   174
%
haftmann
parents: 28540
diff changeset
   175
\isatagquote
haftmann
parents: 28540
diff changeset
   176
\isacommand{instantiation}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   177
\ int\ {\isacharcolon}{\isacharcolon}\ semigroup\isanewline
28565
haftmann
parents: 28540
diff changeset
   178
\isakeyword{begin}\isanewline
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   179
\isanewline
28565
haftmann
parents: 28540
diff changeset
   180
\isacommand{definition}\isamarkupfalse%
haftmann
parents: 28540
diff changeset
   181
\isanewline
haftmann
parents: 28540
diff changeset
   182
\ \ mult{\isacharunderscore}int{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}i\ {\isasymotimes}\ j\ {\isacharequal}\ i\ {\isacharplus}\ {\isacharparenleft}j{\isasymColon}int{\isacharparenright}{\isachardoublequoteclose}\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   183
\isanewline
28565
haftmann
parents: 28540
diff changeset
   184
\isacommand{instance}\isamarkupfalse%
haftmann
parents: 28540
diff changeset
   185
\ \isacommand{proof}\isamarkupfalse%
haftmann
parents: 28540
diff changeset
   186
\isanewline
haftmann
parents: 28540
diff changeset
   187
\ \ \isacommand{fix}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   188
\ i\ j\ k\ {\isacharcolon}{\isacharcolon}\ int\ \isacommand{have}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   189
\ {\isachardoublequoteopen}{\isacharparenleft}i\ {\isacharplus}\ j{\isacharparenright}\ {\isacharplus}\ k\ {\isacharequal}\ i\ {\isacharplus}\ {\isacharparenleft}j\ {\isacharplus}\ k{\isacharparenright}{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   190
\ simp\isanewline
28565
haftmann
parents: 28540
diff changeset
   191
\ \ \isacommand{then}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   192
\ \isacommand{show}\isamarkupfalse%
25247
haftmann
parents: 25200
diff changeset
   193
\ {\isachardoublequoteopen}{\isacharparenleft}i\ {\isasymotimes}\ j{\isacharparenright}\ {\isasymotimes}\ k\ {\isacharequal}\ i\ {\isasymotimes}\ {\isacharparenleft}j\ {\isasymotimes}\ k{\isacharparenright}{\isachardoublequoteclose}\isanewline
28566
haftmann
parents: 28565
diff changeset
   194
\ \ \ \ \isacommand{unfolding}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   195
\ mult{\isacharunderscore}int{\isacharunderscore}def\ \isacommand{{\isachardot}}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   196
\isanewline
28565
haftmann
parents: 28540
diff changeset
   197
\isacommand{qed}\isamarkupfalse%
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   198
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   199
\isanewline
28565
haftmann
parents: 28540
diff changeset
   200
\isacommand{end}\isamarkupfalse%
haftmann
parents: 28540
diff changeset
   201
%
haftmann
parents: 28540
diff changeset
   202
\endisatagquote
haftmann
parents: 28540
diff changeset
   203
{\isafoldquote}%
haftmann
parents: 28540
diff changeset
   204
%
haftmann
parents: 28540
diff changeset
   205
\isadelimquote
haftmann
parents: 28540
diff changeset
   206
%
haftmann
parents: 28540
diff changeset
   207
\endisadelimquote
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   208
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   209
\begin{isamarkuptext}%
28565
haftmann
parents: 28540
diff changeset
   210
\noindent \hyperlink{command.instantiation}{\mbox{\isa{\isacommand{instantiation}}}} allows to define class parameters
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   211
  at a particular instance using common specification tools (here,
28565
haftmann
parents: 28540
diff changeset
   212
  \hyperlink{command.definition}{\mbox{\isa{\isacommand{definition}}}}).  The concluding \hyperlink{command.instance}{\mbox{\isa{\isacommand{instance}}}}
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   213
  opens a proof that the given parameters actually conform
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   214
  to the class specification.  Note that the first proof step
28565
haftmann
parents: 28540
diff changeset
   215
  is the \hyperlink{method.default}{\mbox{\isa{default}}} method,
haftmann
parents: 28540
diff changeset
   216
  which for such instance proofs maps to the \hyperlink{method.intro-classes}{\mbox{\isa{intro{\isacharunderscore}classes}}} method.
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   217
  This boils down an instance judgement to the relevant primitive
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   218
  proof goals and should conveniently always be the first method applied
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   219
  in an instantiation proof.
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   220
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   221
  From now on, the type-checker will consider \isa{int}
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   222
  as a \isa{semigroup} automatically, i.e.\ any general results
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   223
  are immediately available on concrete instances.
28565
haftmann
parents: 28540
diff changeset
   224
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   225
  \medskip Another instance of \isa{semigroup} are the natural numbers:%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   226
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   227
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   228
%
28565
haftmann
parents: 28540
diff changeset
   229
\isadelimquote
haftmann
parents: 28540
diff changeset
   230
%
haftmann
parents: 28540
diff changeset
   231
\endisadelimquote
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   232
%
28565
haftmann
parents: 28540
diff changeset
   233
\isatagquote
haftmann
parents: 28540
diff changeset
   234
\isacommand{instantiation}\isamarkupfalse%
haftmann
parents: 28540
diff changeset
   235
\ nat\ {\isacharcolon}{\isacharcolon}\ semigroup\isanewline
haftmann
parents: 28540
diff changeset
   236
\isakeyword{begin}\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   237
\isanewline
28565
haftmann
parents: 28540
diff changeset
   238
\isacommand{primrec}\isamarkupfalse%
haftmann
parents: 28540
diff changeset
   239
\ mult{\isacharunderscore}nat\ \isakeyword{where}\isanewline
haftmann
parents: 28540
diff changeset
   240
\ \ {\isachardoublequoteopen}{\isacharparenleft}{\isadigit{0}}{\isasymColon}nat{\isacharparenright}\ {\isasymotimes}\ n\ {\isacharequal}\ n{\isachardoublequoteclose}\isanewline
haftmann
parents: 28540
diff changeset
   241
\ \ {\isacharbar}\ {\isachardoublequoteopen}Suc\ m\ {\isasymotimes}\ n\ {\isacharequal}\ Suc\ {\isacharparenleft}m\ {\isasymotimes}\ n{\isacharparenright}{\isachardoublequoteclose}\isanewline
haftmann
parents: 28540
diff changeset
   242
\isanewline
haftmann
parents: 28540
diff changeset
   243
\isacommand{instance}\isamarkupfalse%
haftmann
parents: 28540
diff changeset
   244
\ \isacommand{proof}\isamarkupfalse%
haftmann
parents: 28540
diff changeset
   245
\isanewline
haftmann
parents: 28540
diff changeset
   246
\ \ \isacommand{fix}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   247
\ m\ n\ q\ {\isacharcolon}{\isacharcolon}\ nat\ \isanewline
28565
haftmann
parents: 28540
diff changeset
   248
\ \ \isacommand{show}\isamarkupfalse%
25247
haftmann
parents: 25200
diff changeset
   249
\ {\isachardoublequoteopen}m\ {\isasymotimes}\ n\ {\isasymotimes}\ q\ {\isacharequal}\ m\ {\isasymotimes}\ {\isacharparenleft}n\ {\isasymotimes}\ q{\isacharparenright}{\isachardoublequoteclose}\isanewline
28565
haftmann
parents: 28540
diff changeset
   250
\ \ \ \ \isacommand{by}\isamarkupfalse%
25871
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   251
\ {\isacharparenleft}induct\ m{\isacharparenright}\ auto\isanewline
28565
haftmann
parents: 28540
diff changeset
   252
\isacommand{qed}\isamarkupfalse%
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   253
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   254
\isanewline
28565
haftmann
parents: 28540
diff changeset
   255
\isacommand{end}\isamarkupfalse%
haftmann
parents: 28540
diff changeset
   256
%
haftmann
parents: 28540
diff changeset
   257
\endisatagquote
haftmann
parents: 28540
diff changeset
   258
{\isafoldquote}%
haftmann
parents: 28540
diff changeset
   259
%
haftmann
parents: 28540
diff changeset
   260
\isadelimquote
haftmann
parents: 28540
diff changeset
   261
%
haftmann
parents: 28540
diff changeset
   262
\endisadelimquote
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   263
%
25871
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   264
\begin{isamarkuptext}%
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   265
\noindent Note the occurence of the name \isa{mult{\isacharunderscore}nat}
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   266
  in the primrec declaration;  by default, the local name of
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   267
  a class operation \isa{f} to instantiate on type constructor
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   268
  \isa{{\isasymkappa}} are mangled as \isa{f{\isacharunderscore}{\isasymkappa}}.  In case of uncertainty,
28565
haftmann
parents: 28540
diff changeset
   269
  these names may be inspected using the \hyperlink{command.print-context}{\mbox{\isa{\isacommand{print{\isacharunderscore}context}}}} command
25871
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   270
  or the corresponding ProofGeneral button.%
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   271
\end{isamarkuptext}%
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   272
\isamarkuptrue%
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   273
%
25247
haftmann
parents: 25200
diff changeset
   274
\isamarkupsubsection{Lifting and parametric types%
haftmann
parents: 25200
diff changeset
   275
}
haftmann
parents: 25200
diff changeset
   276
\isamarkuptrue%
haftmann
parents: 25200
diff changeset
   277
%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   278
\begin{isamarkuptext}%
25247
haftmann
parents: 25200
diff changeset
   279
Overloaded definitions giving on class instantiation
haftmann
parents: 25200
diff changeset
   280
  may include recursion over the syntactic structure of types.
haftmann
parents: 25200
diff changeset
   281
  As a canonical example, we model product semigroups
haftmann
parents: 25200
diff changeset
   282
  using our simple algebra:%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   283
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   284
\isamarkuptrue%
28565
haftmann
parents: 28540
diff changeset
   285
%
haftmann
parents: 28540
diff changeset
   286
\isadelimquote
haftmann
parents: 28540
diff changeset
   287
%
haftmann
parents: 28540
diff changeset
   288
\endisadelimquote
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   289
%
28565
haftmann
parents: 28540
diff changeset
   290
\isatagquote
haftmann
parents: 28540
diff changeset
   291
\isacommand{instantiation}\isamarkupfalse%
haftmann
parents: 28540
diff changeset
   292
\ {\isacharasterisk}\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}semigroup{\isacharcomma}\ semigroup{\isacharparenright}\ semigroup\isanewline
haftmann
parents: 28540
diff changeset
   293
\isakeyword{begin}\isanewline
haftmann
parents: 28540
diff changeset
   294
\isanewline
haftmann
parents: 28540
diff changeset
   295
\isacommand{definition}\isamarkupfalse%
haftmann
parents: 28540
diff changeset
   296
\isanewline
haftmann
parents: 28540
diff changeset
   297
\ \ mult{\isacharunderscore}prod{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}p\isactrlisub {\isadigit{1}}\ {\isasymotimes}\ p\isactrlisub {\isadigit{2}}\ {\isacharequal}\ {\isacharparenleft}fst\ p\isactrlisub {\isadigit{1}}\ {\isasymotimes}\ fst\ p\isactrlisub {\isadigit{2}}{\isacharcomma}\ snd\ p\isactrlisub {\isadigit{1}}\ {\isasymotimes}\ snd\ p\isactrlisub {\isadigit{2}}{\isacharparenright}{\isachardoublequoteclose}\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   298
\isanewline
28565
haftmann
parents: 28540
diff changeset
   299
\isacommand{instance}\isamarkupfalse%
haftmann
parents: 28540
diff changeset
   300
\ \isacommand{proof}\isamarkupfalse%
haftmann
parents: 28540
diff changeset
   301
\isanewline
haftmann
parents: 28540
diff changeset
   302
\ \ \isacommand{fix}\isamarkupfalse%
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   303
\ p\isactrlisub {\isadigit{1}}\ p\isactrlisub {\isadigit{2}}\ p\isactrlisub {\isadigit{3}}\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}{\isasymColon}semigroup\ {\isasymtimes}\ {\isasymbeta}{\isasymColon}semigroup{\isachardoublequoteclose}\isanewline
28565
haftmann
parents: 28540
diff changeset
   304
\ \ \isacommand{show}\isamarkupfalse%
25247
haftmann
parents: 25200
diff changeset
   305
\ {\isachardoublequoteopen}p\isactrlisub {\isadigit{1}}\ {\isasymotimes}\ p\isactrlisub {\isadigit{2}}\ {\isasymotimes}\ p\isactrlisub {\isadigit{3}}\ {\isacharequal}\ p\isactrlisub {\isadigit{1}}\ {\isasymotimes}\ {\isacharparenleft}p\isactrlisub {\isadigit{2}}\ {\isasymotimes}\ p\isactrlisub {\isadigit{3}}{\isacharparenright}{\isachardoublequoteclose}\isanewline
28566
haftmann
parents: 28565
diff changeset
   306
\ \ \ \ \isacommand{unfolding}\isamarkupfalse%
25247
haftmann
parents: 25200
diff changeset
   307
\ mult{\isacharunderscore}prod{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse%
haftmann
parents: 25200
diff changeset
   308
\ {\isacharparenleft}simp\ add{\isacharcolon}\ assoc{\isacharparenright}\isanewline
28565
haftmann
parents: 28540
diff changeset
   309
\isacommand{qed}\isamarkupfalse%
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   310
\ \ \ \ \ \ \isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   311
\isanewline
28565
haftmann
parents: 28540
diff changeset
   312
\isacommand{end}\isamarkupfalse%
haftmann
parents: 28540
diff changeset
   313
%
haftmann
parents: 28540
diff changeset
   314
\endisatagquote
haftmann
parents: 28540
diff changeset
   315
{\isafoldquote}%
haftmann
parents: 28540
diff changeset
   316
%
haftmann
parents: 28540
diff changeset
   317
\isadelimquote
haftmann
parents: 28540
diff changeset
   318
%
haftmann
parents: 28540
diff changeset
   319
\endisadelimquote
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   320
%
25247
haftmann
parents: 25200
diff changeset
   321
\begin{isamarkuptext}%
haftmann
parents: 25200
diff changeset
   322
\noindent Associativity from product semigroups is
haftmann
parents: 25200
diff changeset
   323
  established using
28565
haftmann
parents: 28540
diff changeset
   324
  the definition of \isa{{\isacharparenleft}{\isasymotimes}{\isacharparenright}} on products and the hypothetical
27507
32d18c9b7f21 updated generated file;
wenzelm
parents: 26991
diff changeset
   325
  associativity of the type components;  these hypotheses
25247
haftmann
parents: 25200
diff changeset
   326
  are facts due to the \isa{semigroup} constraints imposed
28565
haftmann
parents: 28540
diff changeset
   327
  on the type components by the \hyperlink{command.instance}{\mbox{\isa{\isacommand{instance}}}} proposition.
25247
haftmann
parents: 25200
diff changeset
   328
  Indeed, this pattern often occurs with parametric types
haftmann
parents: 25200
diff changeset
   329
  and type classes.%
haftmann
parents: 25200
diff changeset
   330
\end{isamarkuptext}%
haftmann
parents: 25200
diff changeset
   331
\isamarkuptrue%
haftmann
parents: 25200
diff changeset
   332
%
haftmann
parents: 25200
diff changeset
   333
\isamarkupsubsection{Subclassing%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   334
}
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   335
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   336
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   337
\begin{isamarkuptext}%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   338
We define a subclass \isa{monoidl} (a semigroup with a left-hand neutral)
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   339
  by extending \isa{semigroup}
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   340
  with one additional parameter \isa{neutral} together
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   341
  with its property:%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   342
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   343
\isamarkuptrue%
28565
haftmann
parents: 28540
diff changeset
   344
%
haftmann
parents: 28540
diff changeset
   345
\isadelimquote
haftmann
parents: 28540
diff changeset
   346
%
haftmann
parents: 28540
diff changeset
   347
\endisadelimquote
haftmann
parents: 28540
diff changeset
   348
%
haftmann
parents: 28540
diff changeset
   349
\isatagquote
haftmann
parents: 28540
diff changeset
   350
\isacommand{class}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   351
\ monoidl\ {\isacharequal}\ semigroup\ {\isacharplus}\isanewline
28565
haftmann
parents: 28540
diff changeset
   352
\ \ \isakeyword{fixes}\ neutral\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}{\isachardoublequoteclose}\ {\isacharparenleft}{\isachardoublequoteopen}{\isasymone}{\isachardoublequoteclose}{\isacharparenright}\isanewline
haftmann
parents: 28540
diff changeset
   353
\ \ \isakeyword{assumes}\ neutl{\isacharcolon}\ {\isachardoublequoteopen}{\isasymone}\ {\isasymotimes}\ x\ {\isacharequal}\ x{\isachardoublequoteclose}%
haftmann
parents: 28540
diff changeset
   354
\endisatagquote
haftmann
parents: 28540
diff changeset
   355
{\isafoldquote}%
haftmann
parents: 28540
diff changeset
   356
%
haftmann
parents: 28540
diff changeset
   357
\isadelimquote
haftmann
parents: 28540
diff changeset
   358
%
haftmann
parents: 28540
diff changeset
   359
\endisadelimquote
haftmann
parents: 28540
diff changeset
   360
%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   361
\begin{isamarkuptext}%
25247
haftmann
parents: 25200
diff changeset
   362
\noindent Again, we prove some instances, by
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   363
  providing suitable parameter definitions and proofs for the
27507
32d18c9b7f21 updated generated file;
wenzelm
parents: 26991
diff changeset
   364
  additional specifications.  Observe that instantiations
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   365
  for types with the same arity may be simultaneous:%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   366
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   367
\isamarkuptrue%
28566
haftmann
parents: 28565
diff changeset
   368
%
haftmann
parents: 28565
diff changeset
   369
\isadelimquote
haftmann
parents: 28565
diff changeset
   370
%
haftmann
parents: 28565
diff changeset
   371
\endisadelimquote
haftmann
parents: 28565
diff changeset
   372
%
haftmann
parents: 28565
diff changeset
   373
\isatagquote
haftmann
parents: 28565
diff changeset
   374
\isacommand{instantiation}\isamarkupfalse%
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   375
\ nat\ \isakeyword{and}\ int\ {\isacharcolon}{\isacharcolon}\ monoidl\isanewline
28566
haftmann
parents: 28565
diff changeset
   376
\isakeyword{begin}\isanewline
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   377
\isanewline
28566
haftmann
parents: 28565
diff changeset
   378
\isacommand{definition}\isamarkupfalse%
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   379
\isanewline
28566
haftmann
parents: 28565
diff changeset
   380
\ \ neutral{\isacharunderscore}nat{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}{\isasymone}\ {\isacharequal}\ {\isacharparenleft}{\isadigit{0}}{\isasymColon}nat{\isacharparenright}{\isachardoublequoteclose}\isanewline
haftmann
parents: 28565
diff changeset
   381
\isanewline
haftmann
parents: 28565
diff changeset
   382
\isacommand{definition}\isamarkupfalse%
haftmann
parents: 28565
diff changeset
   383
\isanewline
haftmann
parents: 28565
diff changeset
   384
\ \ neutral{\isacharunderscore}int{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}{\isasymone}\ {\isacharequal}\ {\isacharparenleft}{\isadigit{0}}{\isasymColon}int{\isacharparenright}{\isachardoublequoteclose}\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   385
\isanewline
28566
haftmann
parents: 28565
diff changeset
   386
\isacommand{instance}\isamarkupfalse%
haftmann
parents: 28565
diff changeset
   387
\ \isacommand{proof}\isamarkupfalse%
haftmann
parents: 28565
diff changeset
   388
\isanewline
haftmann
parents: 28565
diff changeset
   389
\ \ \isacommand{fix}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   390
\ n\ {\isacharcolon}{\isacharcolon}\ nat\isanewline
28566
haftmann
parents: 28565
diff changeset
   391
\ \ \isacommand{show}\isamarkupfalse%
25247
haftmann
parents: 25200
diff changeset
   392
\ {\isachardoublequoteopen}{\isasymone}\ {\isasymotimes}\ n\ {\isacharequal}\ n{\isachardoublequoteclose}\isanewline
28566
haftmann
parents: 28565
diff changeset
   393
\ \ \ \ \isacommand{unfolding}\isamarkupfalse%
26991
2aa686443859 updated generated file;
wenzelm
parents: 25871
diff changeset
   394
\ neutral{\isacharunderscore}nat{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   395
\ simp\isanewline
28566
haftmann
parents: 28565
diff changeset
   396
\isacommand{next}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   397
\isanewline
28566
haftmann
parents: 28565
diff changeset
   398
\ \ \isacommand{fix}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   399
\ k\ {\isacharcolon}{\isacharcolon}\ int\isanewline
28566
haftmann
parents: 28565
diff changeset
   400
\ \ \isacommand{show}\isamarkupfalse%
25247
haftmann
parents: 25200
diff changeset
   401
\ {\isachardoublequoteopen}{\isasymone}\ {\isasymotimes}\ k\ {\isacharequal}\ k{\isachardoublequoteclose}\isanewline
28566
haftmann
parents: 28565
diff changeset
   402
\ \ \ \ \isacommand{unfolding}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   403
\ neutral{\isacharunderscore}int{\isacharunderscore}def\ mult{\isacharunderscore}int{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   404
\ simp\isanewline
28566
haftmann
parents: 28565
diff changeset
   405
\isacommand{qed}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   406
\isanewline
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   407
\isanewline
28566
haftmann
parents: 28565
diff changeset
   408
\isacommand{end}\isamarkupfalse%
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   409
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   410
\isanewline
28566
haftmann
parents: 28565
diff changeset
   411
\isacommand{instantiation}\isamarkupfalse%
25247
haftmann
parents: 25200
diff changeset
   412
\ {\isacharasterisk}\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}monoidl{\isacharcomma}\ monoidl{\isacharparenright}\ monoidl\isanewline
28566
haftmann
parents: 28565
diff changeset
   413
\isakeyword{begin}\isanewline
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   414
\isanewline
28566
haftmann
parents: 28565
diff changeset
   415
\isacommand{definition}\isamarkupfalse%
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   416
\isanewline
28566
haftmann
parents: 28565
diff changeset
   417
\ \ neutral{\isacharunderscore}prod{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}{\isasymone}\ {\isacharequal}\ {\isacharparenleft}{\isasymone}{\isacharcomma}\ {\isasymone}{\isacharparenright}{\isachardoublequoteclose}\isanewline
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   418
\isanewline
28566
haftmann
parents: 28565
diff changeset
   419
\isacommand{instance}\isamarkupfalse%
haftmann
parents: 28565
diff changeset
   420
\ \isacommand{proof}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   421
\isanewline
28566
haftmann
parents: 28565
diff changeset
   422
\ \ \isacommand{fix}\isamarkupfalse%
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   423
\ p\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}{\isasymColon}monoidl\ {\isasymtimes}\ {\isasymbeta}{\isasymColon}monoidl{\isachardoublequoteclose}\isanewline
28566
haftmann
parents: 28565
diff changeset
   424
\ \ \isacommand{show}\isamarkupfalse%
25247
haftmann
parents: 25200
diff changeset
   425
\ {\isachardoublequoteopen}{\isasymone}\ {\isasymotimes}\ p\ {\isacharequal}\ p{\isachardoublequoteclose}\isanewline
28566
haftmann
parents: 28565
diff changeset
   426
\ \ \ \ \isacommand{unfolding}\isamarkupfalse%
25247
haftmann
parents: 25200
diff changeset
   427
\ neutral{\isacharunderscore}prod{\isacharunderscore}def\ mult{\isacharunderscore}prod{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse%
haftmann
parents: 25200
diff changeset
   428
\ {\isacharparenleft}simp\ add{\isacharcolon}\ neutl{\isacharparenright}\isanewline
28566
haftmann
parents: 28565
diff changeset
   429
\isacommand{qed}\isamarkupfalse%
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   430
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   431
\isanewline
28566
haftmann
parents: 28565
diff changeset
   432
\isacommand{end}\isamarkupfalse%
haftmann
parents: 28565
diff changeset
   433
%
haftmann
parents: 28565
diff changeset
   434
\endisatagquote
haftmann
parents: 28565
diff changeset
   435
{\isafoldquote}%
haftmann
parents: 28565
diff changeset
   436
%
haftmann
parents: 28565
diff changeset
   437
\isadelimquote
haftmann
parents: 28565
diff changeset
   438
%
haftmann
parents: 28565
diff changeset
   439
\endisadelimquote
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   440
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   441
\begin{isamarkuptext}%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   442
\noindent Fully-fledged monoids are modelled by another subclass
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   443
  which does not add new parameters but tightens the specification:%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   444
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   445
\isamarkuptrue%
28566
haftmann
parents: 28565
diff changeset
   446
%
haftmann
parents: 28565
diff changeset
   447
\isadelimquote
haftmann
parents: 28565
diff changeset
   448
%
haftmann
parents: 28565
diff changeset
   449
\endisadelimquote
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   450
%
28566
haftmann
parents: 28565
diff changeset
   451
\isatagquote
haftmann
parents: 28565
diff changeset
   452
\isacommand{class}\isamarkupfalse%
haftmann
parents: 28565
diff changeset
   453
\ monoid\ {\isacharequal}\ monoidl\ {\isacharplus}\isanewline
haftmann
parents: 28565
diff changeset
   454
\ \ \isakeyword{assumes}\ neutr{\isacharcolon}\ {\isachardoublequoteopen}x\ {\isasymotimes}\ {\isasymone}\ {\isacharequal}\ x{\isachardoublequoteclose}\isanewline
haftmann
parents: 28565
diff changeset
   455
\isanewline
haftmann
parents: 28565
diff changeset
   456
\isacommand{instantiation}\isamarkupfalse%
haftmann
parents: 28565
diff changeset
   457
\ nat\ \isakeyword{and}\ int\ {\isacharcolon}{\isacharcolon}\ monoid\ \isanewline
haftmann
parents: 28565
diff changeset
   458
\isakeyword{begin}\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   459
\isanewline
28566
haftmann
parents: 28565
diff changeset
   460
\isacommand{instance}\isamarkupfalse%
haftmann
parents: 28565
diff changeset
   461
\ \isacommand{proof}\isamarkupfalse%
haftmann
parents: 28565
diff changeset
   462
\isanewline
haftmann
parents: 28565
diff changeset
   463
\ \ \isacommand{fix}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   464
\ n\ {\isacharcolon}{\isacharcolon}\ nat\isanewline
28566
haftmann
parents: 28565
diff changeset
   465
\ \ \isacommand{show}\isamarkupfalse%
25247
haftmann
parents: 25200
diff changeset
   466
\ {\isachardoublequoteopen}n\ {\isasymotimes}\ {\isasymone}\ {\isacharequal}\ n{\isachardoublequoteclose}\isanewline
28566
haftmann
parents: 28565
diff changeset
   467
\ \ \ \ \isacommand{unfolding}\isamarkupfalse%
25871
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   468
\ neutral{\isacharunderscore}nat{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse%
45753d56d935 some more primrec
haftmann
parents: 25868
diff changeset
   469
\ {\isacharparenleft}induct\ n{\isacharparenright}\ simp{\isacharunderscore}all\isanewline
28566
haftmann
parents: 28565
diff changeset
   470
\isacommand{next}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   471
\isanewline
28566
haftmann
parents: 28565
diff changeset
   472
\ \ \isacommand{fix}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   473
\ k\ {\isacharcolon}{\isacharcolon}\ int\isanewline
28566
haftmann
parents: 28565
diff changeset
   474
\ \ \isacommand{show}\isamarkupfalse%
25247
haftmann
parents: 25200
diff changeset
   475
\ {\isachardoublequoteopen}k\ {\isasymotimes}\ {\isasymone}\ {\isacharequal}\ k{\isachardoublequoteclose}\isanewline
28566
haftmann
parents: 28565
diff changeset
   476
\ \ \ \ \isacommand{unfolding}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   477
\ neutral{\isacharunderscore}int{\isacharunderscore}def\ mult{\isacharunderscore}int{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   478
\ simp\isanewline
28566
haftmann
parents: 28565
diff changeset
   479
\isacommand{qed}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   480
\isanewline
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   481
\isanewline
28566
haftmann
parents: 28565
diff changeset
   482
\isacommand{end}\isamarkupfalse%
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   483
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   484
\isanewline
28566
haftmann
parents: 28565
diff changeset
   485
\isacommand{instantiation}\isamarkupfalse%
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   486
\ {\isacharasterisk}\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}monoid{\isacharcomma}\ monoid{\isacharparenright}\ monoid\isanewline
28566
haftmann
parents: 28565
diff changeset
   487
\isakeyword{begin}\isanewline
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   488
\isanewline
28566
haftmann
parents: 28565
diff changeset
   489
\isacommand{instance}\isamarkupfalse%
haftmann
parents: 28565
diff changeset
   490
\ \isacommand{proof}\isamarkupfalse%
25247
haftmann
parents: 25200
diff changeset
   491
\ \isanewline
28566
haftmann
parents: 28565
diff changeset
   492
\ \ \isacommand{fix}\isamarkupfalse%
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   493
\ p\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}{\isasymColon}monoid\ {\isasymtimes}\ {\isasymbeta}{\isasymColon}monoid{\isachardoublequoteclose}\isanewline
28566
haftmann
parents: 28565
diff changeset
   494
\ \ \isacommand{show}\isamarkupfalse%
25247
haftmann
parents: 25200
diff changeset
   495
\ {\isachardoublequoteopen}p\ {\isasymotimes}\ {\isasymone}\ {\isacharequal}\ p{\isachardoublequoteclose}\isanewline
28566
haftmann
parents: 28565
diff changeset
   496
\ \ \ \ \isacommand{unfolding}\isamarkupfalse%
25247
haftmann
parents: 25200
diff changeset
   497
\ neutral{\isacharunderscore}prod{\isacharunderscore}def\ mult{\isacharunderscore}prod{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse%
haftmann
parents: 25200
diff changeset
   498
\ {\isacharparenleft}simp\ add{\isacharcolon}\ neutr{\isacharparenright}\isanewline
28566
haftmann
parents: 28565
diff changeset
   499
\isacommand{qed}\isamarkupfalse%
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   500
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   501
\isanewline
28566
haftmann
parents: 28565
diff changeset
   502
\isacommand{end}\isamarkupfalse%
haftmann
parents: 28565
diff changeset
   503
%
haftmann
parents: 28565
diff changeset
   504
\endisatagquote
haftmann
parents: 28565
diff changeset
   505
{\isafoldquote}%
haftmann
parents: 28565
diff changeset
   506
%
haftmann
parents: 28565
diff changeset
   507
\isadelimquote
haftmann
parents: 28565
diff changeset
   508
%
haftmann
parents: 28565
diff changeset
   509
\endisadelimquote
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   510
%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   511
\begin{isamarkuptext}%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   512
\noindent To finish our small algebra example, we add a \isa{group} class
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   513
  with a corresponding instance:%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   514
\end{isamarkuptext}%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   515
\isamarkuptrue%
28566
haftmann
parents: 28565
diff changeset
   516
%
haftmann
parents: 28565
diff changeset
   517
\isadelimquote
haftmann
parents: 28565
diff changeset
   518
%
haftmann
parents: 28565
diff changeset
   519
\endisadelimquote
haftmann
parents: 28565
diff changeset
   520
%
haftmann
parents: 28565
diff changeset
   521
\isatagquote
haftmann
parents: 28565
diff changeset
   522
\isacommand{class}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   523
\ group\ {\isacharequal}\ monoidl\ {\isacharplus}\isanewline
28566
haftmann
parents: 28565
diff changeset
   524
\ \ \isakeyword{fixes}\ inverse\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}\ \ \ \ {\isacharparenleft}{\isachardoublequoteopen}{\isacharparenleft}{\isacharunderscore}{\isasymdiv}{\isacharparenright}{\isachardoublequoteclose}\ {\isacharbrackleft}{\isadigit{1}}{\isadigit{0}}{\isadigit{0}}{\isadigit{0}}{\isacharbrackright}\ {\isadigit{9}}{\isadigit{9}}{\isadigit{9}}{\isacharparenright}\isanewline
haftmann
parents: 28565
diff changeset
   525
\ \ \isakeyword{assumes}\ invl{\isacharcolon}\ {\isachardoublequoteopen}x{\isasymdiv}\ {\isasymotimes}\ x\ {\isacharequal}\ {\isasymone}{\isachardoublequoteclose}\isanewline
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   526
\isanewline
28566
haftmann
parents: 28565
diff changeset
   527
\isacommand{instantiation}\isamarkupfalse%
haftmann
parents: 28565
diff changeset
   528
\ int\ {\isacharcolon}{\isacharcolon}\ group\isanewline
haftmann
parents: 28565
diff changeset
   529
\isakeyword{begin}\isanewline
haftmann
parents: 28565
diff changeset
   530
\isanewline
haftmann
parents: 28565
diff changeset
   531
\isacommand{definition}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   532
\isanewline
28566
haftmann
parents: 28565
diff changeset
   533
\ \ inverse{\isacharunderscore}int{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}i{\isasymdiv}\ {\isacharequal}\ {\isacharminus}\ {\isacharparenleft}i{\isasymColon}int{\isacharparenright}{\isachardoublequoteclose}\isanewline
haftmann
parents: 28565
diff changeset
   534
\isanewline
haftmann
parents: 28565
diff changeset
   535
\isacommand{instance}\isamarkupfalse%
haftmann
parents: 28565
diff changeset
   536
\ \isacommand{proof}\isamarkupfalse%
haftmann
parents: 28565
diff changeset
   537
\isanewline
haftmann
parents: 28565
diff changeset
   538
\ \ \isacommand{fix}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   539
\ i\ {\isacharcolon}{\isacharcolon}\ int\isanewline
28566
haftmann
parents: 28565
diff changeset
   540
\ \ \isacommand{have}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   541
\ {\isachardoublequoteopen}{\isacharminus}i\ {\isacharplus}\ i\ {\isacharequal}\ {\isadigit{0}}{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   542
\ simp\isanewline
28566
haftmann
parents: 28565
diff changeset
   543
\ \ \isacommand{then}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   544
\ \isacommand{show}\isamarkupfalse%
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   545
\ {\isachardoublequoteopen}i{\isasymdiv}\ {\isasymotimes}\ i\ {\isacharequal}\ {\isasymone}{\isachardoublequoteclose}\isanewline
28566
haftmann
parents: 28565
diff changeset
   546
\ \ \ \ \isacommand{unfolding}\isamarkupfalse%
25247
haftmann
parents: 25200
diff changeset
   547
\ mult{\isacharunderscore}int{\isacharunderscore}def\ neutral{\isacharunderscore}int{\isacharunderscore}def\ inverse{\isacharunderscore}int{\isacharunderscore}def\ \isacommand{{\isachardot}}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   548
\isanewline
28566
haftmann
parents: 28565
diff changeset
   549
\isacommand{qed}\isamarkupfalse%
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   550
\isanewline
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
   551
\isanewline
28566
haftmann
parents: 28565
diff changeset
   552
\isacommand{end}\isamarkupfalse%
haftmann
parents: 28565
diff changeset
   553
%
haftmann
parents: 28565
diff changeset
   554
\endisatagquote
haftmann
parents: 28565
diff changeset
   555
{\isafoldquote}%
haftmann
parents: 28565
diff changeset
   556
%
haftmann
parents: 28565
diff changeset
   557
\isadelimquote
haftmann
parents: 28565
diff changeset
   558
%
haftmann
parents: 28565
diff changeset
   559
\endisadelimquote
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   560
%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   561
\isamarkupsection{Type classes as locales%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   562
}
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   563
\isamarkuptrue%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   564
%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   565
\isamarkupsubsection{A look behind the scene%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   566
}
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   567
\isamarkuptrue%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   568
%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   569
\begin{isamarkuptext}%
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   570
The example above gives an impression how Isar type classes work
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   571
  in practice.  As stated in the introduction, classes also provide
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   572
  a link to Isar's locale system.  Indeed, the logical core of a class
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   573
  is nothing else than a locale:%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   574
\end{isamarkuptext}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   575
\isamarkuptrue%
28566
haftmann
parents: 28565
diff changeset
   576
%
haftmann
parents: 28565
diff changeset
   577
\isadelimquote
haftmann
parents: 28565
diff changeset
   578
%
haftmann
parents: 28565
diff changeset
   579
\endisadelimquote
haftmann
parents: 28565
diff changeset
   580
%
haftmann
parents: 28565
diff changeset
   581
\isatagquote
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   582
\isacommand{class}\isamarkupfalse%
29705
a1ecdd8cf81c updated class documentation
haftmann
parents: 29513
diff changeset
   583
\ idem\ {\isacharequal}\isanewline
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   584
\ \ \isakeyword{fixes}\ f\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}\isanewline
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   585
\ \ \isakeyword{assumes}\ idem{\isacharcolon}\ {\isachardoublequoteopen}f\ {\isacharparenleft}f\ x{\isacharparenright}\ {\isacharequal}\ f\ x{\isachardoublequoteclose}%
28566
haftmann
parents: 28565
diff changeset
   586
\endisatagquote
haftmann
parents: 28565
diff changeset
   587
{\isafoldquote}%
haftmann
parents: 28565
diff changeset
   588
%
haftmann
parents: 28565
diff changeset
   589
\isadelimquote
haftmann
parents: 28565
diff changeset
   590
%
haftmann
parents: 28565
diff changeset
   591
\endisadelimquote
haftmann
parents: 28565
diff changeset
   592
%
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   593
\begin{isamarkuptext}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   594
\noindent essentially introduces the locale%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   595
\end{isamarkuptext}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   596
\isamarkuptrue%
30227
853abb4853cc tuned manuals
haftmann
parents: 30226
diff changeset
   597
\ %
28565
haftmann
parents: 28540
diff changeset
   598
\isadeliminvisible
30227
853abb4853cc tuned manuals
haftmann
parents: 30226
diff changeset
   599
%
28565
haftmann
parents: 28540
diff changeset
   600
\endisadeliminvisible
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   601
%
28565
haftmann
parents: 28540
diff changeset
   602
\isataginvisible
30227
853abb4853cc tuned manuals
haftmann
parents: 30226
diff changeset
   603
%
28565
haftmann
parents: 28540
diff changeset
   604
\endisataginvisible
haftmann
parents: 28540
diff changeset
   605
{\isafoldinvisible}%
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   606
%
28565
haftmann
parents: 28540
diff changeset
   607
\isadeliminvisible
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   608
%
28565
haftmann
parents: 28540
diff changeset
   609
\endisadeliminvisible
28566
haftmann
parents: 28565
diff changeset
   610
%
haftmann
parents: 28565
diff changeset
   611
\isadelimquote
haftmann
parents: 28565
diff changeset
   612
%
haftmann
parents: 28565
diff changeset
   613
\endisadelimquote
haftmann
parents: 28565
diff changeset
   614
%
haftmann
parents: 28565
diff changeset
   615
\isatagquote
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   616
\isacommand{locale}\isamarkupfalse%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   617
\ idem\ {\isacharequal}\isanewline
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   618
\ \ \isakeyword{fixes}\ f\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}\isanewline
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   619
\ \ \isakeyword{assumes}\ idem{\isacharcolon}\ {\isachardoublequoteopen}f\ {\isacharparenleft}f\ x{\isacharparenright}\ {\isacharequal}\ f\ x{\isachardoublequoteclose}%
28566
haftmann
parents: 28565
diff changeset
   620
\endisatagquote
haftmann
parents: 28565
diff changeset
   621
{\isafoldquote}%
haftmann
parents: 28565
diff changeset
   622
%
haftmann
parents: 28565
diff changeset
   623
\isadelimquote
haftmann
parents: 28565
diff changeset
   624
%
haftmann
parents: 28565
diff changeset
   625
\endisadelimquote
haftmann
parents: 28565
diff changeset
   626
%
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   627
\begin{isamarkuptext}%
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   628
\noindent together with corresponding constant(s):%
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   629
\end{isamarkuptext}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   630
\isamarkuptrue%
28566
haftmann
parents: 28565
diff changeset
   631
%
haftmann
parents: 28565
diff changeset
   632
\isadelimquote
haftmann
parents: 28565
diff changeset
   633
%
haftmann
parents: 28565
diff changeset
   634
\endisadelimquote
haftmann
parents: 28565
diff changeset
   635
%
haftmann
parents: 28565
diff changeset
   636
\isatagquote
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   637
\isacommand{consts}\isamarkupfalse%
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   638
\ f\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}%
28566
haftmann
parents: 28565
diff changeset
   639
\endisatagquote
haftmann
parents: 28565
diff changeset
   640
{\isafoldquote}%
haftmann
parents: 28565
diff changeset
   641
%
haftmann
parents: 28565
diff changeset
   642
\isadelimquote
haftmann
parents: 28565
diff changeset
   643
%
haftmann
parents: 28565
diff changeset
   644
\endisadelimquote
haftmann
parents: 28565
diff changeset
   645
%
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   646
\begin{isamarkuptext}%
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   647
\noindent The connection to the type system is done by means
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   648
  of a primitive axclass%
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   649
\end{isamarkuptext}%
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   650
\isamarkuptrue%
30227
853abb4853cc tuned manuals
haftmann
parents: 30226
diff changeset
   651
\ %
29513
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   652
\isadeliminvisible
30227
853abb4853cc tuned manuals
haftmann
parents: 30226
diff changeset
   653
%
29513
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   654
\endisadeliminvisible
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   655
%
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   656
\isataginvisible
30227
853abb4853cc tuned manuals
haftmann
parents: 30226
diff changeset
   657
%
29513
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   658
\endisataginvisible
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   659
{\isafoldinvisible}%
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   660
%
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   661
\isadeliminvisible
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   662
%
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   663
\endisadeliminvisible
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   664
%
28566
haftmann
parents: 28565
diff changeset
   665
\isadelimquote
haftmann
parents: 28565
diff changeset
   666
%
haftmann
parents: 28565
diff changeset
   667
\endisadelimquote
haftmann
parents: 28565
diff changeset
   668
%
haftmann
parents: 28565
diff changeset
   669
\isatagquote
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   670
\isacommand{axclass}\isamarkupfalse%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   671
\ idem\ {\isacharless}\ type\isanewline
30227
853abb4853cc tuned manuals
haftmann
parents: 30226
diff changeset
   672
\ \ idem{\isacharcolon}\ {\isachardoublequoteopen}f\ {\isacharparenleft}f\ x{\isacharparenright}\ {\isacharequal}\ f\ x{\isachardoublequoteclose}\ %
28566
haftmann
parents: 28565
diff changeset
   673
\endisatagquote
haftmann
parents: 28565
diff changeset
   674
{\isafoldquote}%
haftmann
parents: 28565
diff changeset
   675
%
haftmann
parents: 28565
diff changeset
   676
\isadelimquote
haftmann
parents: 28565
diff changeset
   677
%
haftmann
parents: 28565
diff changeset
   678
\endisadelimquote
haftmann
parents: 28565
diff changeset
   679
%
29513
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   680
\isadeliminvisible
30227
853abb4853cc tuned manuals
haftmann
parents: 30226
diff changeset
   681
%
29513
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   682
\endisadeliminvisible
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   683
%
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   684
\isataginvisible
30227
853abb4853cc tuned manuals
haftmann
parents: 30226
diff changeset
   685
%
29513
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   686
\endisataginvisible
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   687
{\isafoldinvisible}%
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   688
%
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   689
\isadeliminvisible
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   690
%
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   691
\endisadeliminvisible
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   692
%
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   693
\begin{isamarkuptext}%
22649
6cf96b9f7b9e updated;
wenzelm
parents: 22550
diff changeset
   694
\noindent together with a corresponding interpretation:%
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   695
\end{isamarkuptext}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   696
\isamarkuptrue%
28566
haftmann
parents: 28565
diff changeset
   697
%
haftmann
parents: 28565
diff changeset
   698
\isadelimquote
haftmann
parents: 28565
diff changeset
   699
%
haftmann
parents: 28565
diff changeset
   700
\endisadelimquote
haftmann
parents: 28565
diff changeset
   701
%
haftmann
parents: 28565
diff changeset
   702
\isatagquote
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   703
\isacommand{interpretation}\isamarkupfalse%
29513
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   704
\ idem{\isacharunderscore}class{\isacharcolon}\isanewline
29297
62e0f892e525 updated generated files;
wenzelm
parents: 28948
diff changeset
   705
\ \ idem\ {\isachardoublequoteopen}f\ {\isasymColon}\ {\isacharparenleft}{\isasymalpha}{\isasymColon}idem{\isacharparenright}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}\isanewline
28947
ac1a14b5a085 unfold_locales is default method - no need for explicit references
haftmann
parents: 28727
diff changeset
   706
\isacommand{proof}\isamarkupfalse%
ac1a14b5a085 unfold_locales is default method - no need for explicit references
haftmann
parents: 28727
diff changeset
   707
\ \isacommand{qed}\isamarkupfalse%
ac1a14b5a085 unfold_locales is default method - no need for explicit references
haftmann
parents: 28727
diff changeset
   708
\ {\isacharparenleft}rule\ idem{\isacharparenright}%
28566
haftmann
parents: 28565
diff changeset
   709
\endisatagquote
haftmann
parents: 28565
diff changeset
   710
{\isafoldquote}%
haftmann
parents: 28565
diff changeset
   711
%
haftmann
parents: 28565
diff changeset
   712
\isadelimquote
haftmann
parents: 28565
diff changeset
   713
%
haftmann
parents: 28565
diff changeset
   714
\endisadelimquote
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   715
%
28566
haftmann
parents: 28565
diff changeset
   716
\begin{isamarkuptext}%
haftmann
parents: 28565
diff changeset
   717
\noindent This gives you at hand the full power of the Isabelle module system;
haftmann
parents: 28565
diff changeset
   718
  conclusions in locale \isa{idem} are implicitly propagated
haftmann
parents: 28565
diff changeset
   719
  to class \isa{idem}.%
haftmann
parents: 28565
diff changeset
   720
\end{isamarkuptext}%
haftmann
parents: 28565
diff changeset
   721
\isamarkuptrue%
30227
853abb4853cc tuned manuals
haftmann
parents: 30226
diff changeset
   722
\ %
28565
haftmann
parents: 28540
diff changeset
   723
\isadeliminvisible
30227
853abb4853cc tuned manuals
haftmann
parents: 30226
diff changeset
   724
%
28565
haftmann
parents: 28540
diff changeset
   725
\endisadeliminvisible
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   726
%
28565
haftmann
parents: 28540
diff changeset
   727
\isataginvisible
30227
853abb4853cc tuned manuals
haftmann
parents: 30226
diff changeset
   728
%
28565
haftmann
parents: 28540
diff changeset
   729
\endisataginvisible
haftmann
parents: 28540
diff changeset
   730
{\isafoldinvisible}%
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   731
%
28565
haftmann
parents: 28540
diff changeset
   732
\isadeliminvisible
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   733
%
28565
haftmann
parents: 28540
diff changeset
   734
\endisadeliminvisible
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   735
%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   736
\isamarkupsubsection{Abstract reasoning%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   737
}
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   738
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   739
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   740
\begin{isamarkuptext}%
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   741
Isabelle locales enable reasoning at a general level, while results
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   742
  are implicitly transferred to all instances.  For example, we can
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   743
  now establish the \isa{left{\isacharunderscore}cancel} lemma for groups, which
25247
haftmann
parents: 25200
diff changeset
   744
  states that the function \isa{{\isacharparenleft}x\ {\isasymotimes}{\isacharparenright}} is injective:%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   745
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   746
\isamarkuptrue%
28566
haftmann
parents: 28565
diff changeset
   747
%
haftmann
parents: 28565
diff changeset
   748
\isadelimquote
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   749
%
28566
haftmann
parents: 28565
diff changeset
   750
\endisadelimquote
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   751
%
28566
haftmann
parents: 28565
diff changeset
   752
\isatagquote
haftmann
parents: 28565
diff changeset
   753
\isacommand{lemma}\isamarkupfalse%
haftmann
parents: 28565
diff changeset
   754
\ {\isacharparenleft}\isakeyword{in}\ group{\isacharparenright}\ left{\isacharunderscore}cancel{\isacharcolon}\ {\isachardoublequoteopen}x\ {\isasymotimes}\ y\ {\isacharequal}\ x\ {\isasymotimes}\ z\ {\isasymlongleftrightarrow}\ y\ {\isacharequal}\ z{\isachardoublequoteclose}\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   755
\isacommand{proof}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   756
\isanewline
28566
haftmann
parents: 28565
diff changeset
   757
\ \ \isacommand{assume}\isamarkupfalse%
25200
f1d2e106f2fe adjusted
haftmann
parents: 25004
diff changeset
   758
\ {\isachardoublequoteopen}x\ {\isasymotimes}\ y\ {\isacharequal}\ x\ {\isasymotimes}\ z{\isachardoublequoteclose}\isanewline
28566
haftmann
parents: 28565
diff changeset
   759
\ \ \isacommand{then}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   760
\ \isacommand{have}\isamarkupfalse%
25200
f1d2e106f2fe adjusted
haftmann
parents: 25004
diff changeset
   761
\ {\isachardoublequoteopen}x{\isasymdiv}\ {\isasymotimes}\ {\isacharparenleft}x\ {\isasymotimes}\ y{\isacharparenright}\ {\isacharequal}\ x{\isasymdiv}\ {\isasymotimes}\ {\isacharparenleft}x\ {\isasymotimes}\ z{\isacharparenright}{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   762
\ simp\isanewline
28566
haftmann
parents: 28565
diff changeset
   763
\ \ \isacommand{then}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   764
\ \isacommand{have}\isamarkupfalse%
25200
f1d2e106f2fe adjusted
haftmann
parents: 25004
diff changeset
   765
\ {\isachardoublequoteopen}{\isacharparenleft}x{\isasymdiv}\ {\isasymotimes}\ x{\isacharparenright}\ {\isasymotimes}\ y\ {\isacharequal}\ {\isacharparenleft}x{\isasymdiv}\ {\isasymotimes}\ x{\isacharparenright}\ {\isasymotimes}\ z{\isachardoublequoteclose}\ \isacommand{using}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   766
\ assoc\ \isacommand{by}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   767
\ simp\isanewline
28566
haftmann
parents: 28565
diff changeset
   768
\ \ \isacommand{then}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   769
\ \isacommand{show}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   770
\ {\isachardoublequoteopen}y\ {\isacharequal}\ z{\isachardoublequoteclose}\ \isacommand{using}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   771
\ neutl\ \isakeyword{and}\ invl\ \isacommand{by}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   772
\ simp\isanewline
28566
haftmann
parents: 28565
diff changeset
   773
\isacommand{next}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   774
\isanewline
28566
haftmann
parents: 28565
diff changeset
   775
\ \ \isacommand{assume}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   776
\ {\isachardoublequoteopen}y\ {\isacharequal}\ z{\isachardoublequoteclose}\isanewline
28566
haftmann
parents: 28565
diff changeset
   777
\ \ \isacommand{then}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   778
\ \isacommand{show}\isamarkupfalse%
25200
f1d2e106f2fe adjusted
haftmann
parents: 25004
diff changeset
   779
\ {\isachardoublequoteopen}x\ {\isasymotimes}\ y\ {\isacharequal}\ x\ {\isasymotimes}\ z{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   780
\ simp\isanewline
28566
haftmann
parents: 28565
diff changeset
   781
\isacommand{qed}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   782
%
28566
haftmann
parents: 28565
diff changeset
   783
\endisatagquote
haftmann
parents: 28565
diff changeset
   784
{\isafoldquote}%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   785
%
28566
haftmann
parents: 28565
diff changeset
   786
\isadelimquote
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   787
%
28566
haftmann
parents: 28565
diff changeset
   788
\endisadelimquote
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   789
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   790
\begin{isamarkuptext}%
28565
haftmann
parents: 28540
diff changeset
   791
\noindent Here the \qt{\hyperlink{keyword.in}{\mbox{\isa{\isakeyword{in}}}} \isa{group}} target specification
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   792
  indicates that the result is recorded within that context for later
28565
haftmann
parents: 28540
diff changeset
   793
  use.  This local theorem is also lifted to the global one \hyperlink{fact.group.left-cancel:}{\mbox{\isa{group{\isachardot}left{\isacharunderscore}cancel{\isacharcolon}}}} \isa{{\isachardoublequote}{\isasymAnd}x\ y\ z\ {\isasymColon}\ {\isasymalpha}{\isasymColon}group{\isachardot}\ x\ {\isasymotimes}\ y\ {\isacharequal}\ x\ {\isasymotimes}\ z\ {\isasymlongleftrightarrow}\ y\ {\isacharequal}\ z{\isachardoublequote}}.  Since type \isa{int} has been made an instance of
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   794
  \isa{group} before, we may refer to that fact as well: \isa{{\isachardoublequote}{\isasymAnd}x\ y\ z\ {\isasymColon}\ int{\isachardot}\ x\ {\isasymotimes}\ y\ {\isacharequal}\ x\ {\isasymotimes}\ z\ {\isasymlongleftrightarrow}\ y\ {\isacharequal}\ z{\isachardoublequote}}.%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   795
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   796
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   797
%
23956
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   798
\isamarkupsubsection{Derived definitions%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   799
}
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   800
\isamarkuptrue%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   801
%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   802
\begin{isamarkuptext}%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   803
Isabelle locales support a concept of local definitions
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   804
  in locales:%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   805
\end{isamarkuptext}%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   806
\isamarkuptrue%
28566
haftmann
parents: 28565
diff changeset
   807
%
haftmann
parents: 28565
diff changeset
   808
\isadelimquote
haftmann
parents: 28565
diff changeset
   809
%
haftmann
parents: 28565
diff changeset
   810
\endisadelimquote
haftmann
parents: 28565
diff changeset
   811
%
haftmann
parents: 28565
diff changeset
   812
\isatagquote
haftmann
parents: 28565
diff changeset
   813
\isacommand{primrec}\isamarkupfalse%
28540
haftmann
parents: 27507
diff changeset
   814
\ {\isacharparenleft}\isakeyword{in}\ monoid{\isacharparenright}\ pow{\isacharunderscore}nat\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
28566
haftmann
parents: 28565
diff changeset
   815
\ \ {\isachardoublequoteopen}pow{\isacharunderscore}nat\ {\isadigit{0}}\ x\ {\isacharequal}\ {\isasymone}{\isachardoublequoteclose}\isanewline
haftmann
parents: 28565
diff changeset
   816
\ \ {\isacharbar}\ {\isachardoublequoteopen}pow{\isacharunderscore}nat\ {\isacharparenleft}Suc\ n{\isacharparenright}\ x\ {\isacharequal}\ x\ {\isasymotimes}\ pow{\isacharunderscore}nat\ n\ x{\isachardoublequoteclose}%
haftmann
parents: 28565
diff changeset
   817
\endisatagquote
haftmann
parents: 28565
diff changeset
   818
{\isafoldquote}%
haftmann
parents: 28565
diff changeset
   819
%
haftmann
parents: 28565
diff changeset
   820
\isadelimquote
haftmann
parents: 28565
diff changeset
   821
%
haftmann
parents: 28565
diff changeset
   822
\endisadelimquote
haftmann
parents: 28565
diff changeset
   823
%
23956
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   824
\begin{isamarkuptext}%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   825
\noindent If the locale \isa{group} is also a class, this local
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   826
  definition is propagated onto a global definition of
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   827
  \isa{{\isachardoublequote}pow{\isacharunderscore}nat\ {\isasymColon}\ nat\ {\isasymRightarrow}\ {\isasymalpha}{\isasymColon}monoid\ {\isasymRightarrow}\ {\isasymalpha}{\isasymColon}monoid{\isachardoublequote}}
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   828
  with corresponding theorems
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   829
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   830
  \isa{pow{\isacharunderscore}nat\ {\isadigit{0}}\ x\ {\isacharequal}\ {\isasymone}\isasep\isanewline%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   831
pow{\isacharunderscore}nat\ {\isacharparenleft}Suc\ n{\isacharparenright}\ x\ {\isacharequal}\ x\ {\isasymotimes}\ pow{\isacharunderscore}nat\ n\ x}.
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   832
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   833
  \noindent As you can see from this example, for local
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   834
  definitions you may use any specification tool
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   835
  which works together with locales (e.g. \cite{krauss2006}).%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   836
\end{isamarkuptext}%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   837
\isamarkuptrue%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   838
%
25247
haftmann
parents: 25200
diff changeset
   839
\isamarkupsubsection{A functor analogy%
haftmann
parents: 25200
diff changeset
   840
}
haftmann
parents: 25200
diff changeset
   841
\isamarkuptrue%
haftmann
parents: 25200
diff changeset
   842
%
haftmann
parents: 25200
diff changeset
   843
\begin{isamarkuptext}%
haftmann
parents: 25200
diff changeset
   844
We introduced Isar classes by analogy to type classes
haftmann
parents: 25200
diff changeset
   845
  functional programming;  if we reconsider this in the
haftmann
parents: 25200
diff changeset
   846
  context of what has been said about type classes and locales,
haftmann
parents: 25200
diff changeset
   847
  we can drive this analogy further by stating that type
haftmann
parents: 25200
diff changeset
   848
  classes essentially correspond to functors which have
haftmann
parents: 25200
diff changeset
   849
  a canonical interpretation as type classes.
haftmann
parents: 25200
diff changeset
   850
  Anyway, there is also the possibility of other interpretations.
haftmann
parents: 25200
diff changeset
   851
  For example, also \isa{list}s form a monoid with
28565
haftmann
parents: 28540
diff changeset
   852
  \isa{append} and \isa{{\isacharbrackleft}{\isacharbrackright}} as operations, but it
25247
haftmann
parents: 25200
diff changeset
   853
  seems inappropriate to apply to lists
27507
32d18c9b7f21 updated generated file;
wenzelm
parents: 26991
diff changeset
   854
  the same operations as for genuinely algebraic types.
25247
haftmann
parents: 25200
diff changeset
   855
  In such a case, we simply can do a particular interpretation
haftmann
parents: 25200
diff changeset
   856
  of monoids for lists:%
haftmann
parents: 25200
diff changeset
   857
\end{isamarkuptext}%
haftmann
parents: 25200
diff changeset
   858
\isamarkuptrue%
haftmann
parents: 25200
diff changeset
   859
%
28566
haftmann
parents: 28565
diff changeset
   860
\isadelimquote
haftmann
parents: 28565
diff changeset
   861
%
haftmann
parents: 28565
diff changeset
   862
\endisadelimquote
25247
haftmann
parents: 25200
diff changeset
   863
%
28566
haftmann
parents: 28565
diff changeset
   864
\isatagquote
29513
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   865
\isacommand{interpretation}\isamarkupfalse%
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   866
\ list{\isacharunderscore}monoid{\isacharbang}{\isacharcolon}\ monoid\ append\ {\isachardoublequoteopen}{\isacharbrackleft}{\isacharbrackright}{\isachardoublequoteclose}\isanewline
28947
ac1a14b5a085 unfold_locales is default method - no need for explicit references
haftmann
parents: 28727
diff changeset
   867
\ \ \isacommand{proof}\isamarkupfalse%
ac1a14b5a085 unfold_locales is default method - no need for explicit references
haftmann
parents: 28727
diff changeset
   868
\ \isacommand{qed}\isamarkupfalse%
ac1a14b5a085 unfold_locales is default method - no need for explicit references
haftmann
parents: 28727
diff changeset
   869
\ auto%
28566
haftmann
parents: 28565
diff changeset
   870
\endisatagquote
haftmann
parents: 28565
diff changeset
   871
{\isafoldquote}%
25247
haftmann
parents: 25200
diff changeset
   872
%
28566
haftmann
parents: 28565
diff changeset
   873
\isadelimquote
25247
haftmann
parents: 25200
diff changeset
   874
%
28566
haftmann
parents: 28565
diff changeset
   875
\endisadelimquote
25247
haftmann
parents: 25200
diff changeset
   876
%
haftmann
parents: 25200
diff changeset
   877
\begin{isamarkuptext}%
haftmann
parents: 25200
diff changeset
   878
\noindent This enables us to apply facts on monoids
haftmann
parents: 25200
diff changeset
   879
  to lists, e.g. \isa{{\isacharbrackleft}{\isacharbrackright}\ {\isacharat}\ x\ {\isacharequal}\ x}.
haftmann
parents: 25200
diff changeset
   880
haftmann
parents: 25200
diff changeset
   881
  When using this interpretation pattern, it may also
haftmann
parents: 25200
diff changeset
   882
  be appropriate to map derived definitions accordingly:%
haftmann
parents: 25200
diff changeset
   883
\end{isamarkuptext}%
haftmann
parents: 25200
diff changeset
   884
\isamarkuptrue%
28566
haftmann
parents: 28565
diff changeset
   885
%
haftmann
parents: 28565
diff changeset
   886
\isadelimquote
haftmann
parents: 28565
diff changeset
   887
%
haftmann
parents: 28565
diff changeset
   888
\endisadelimquote
haftmann
parents: 28565
diff changeset
   889
%
haftmann
parents: 28565
diff changeset
   890
\isatagquote
haftmann
parents: 28565
diff changeset
   891
\isacommand{primrec}\isamarkupfalse%
28540
haftmann
parents: 27507
diff changeset
   892
\ replicate\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ {\isasymalpha}\ list\ {\isasymRightarrow}\ {\isasymalpha}\ list{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
28566
haftmann
parents: 28565
diff changeset
   893
\ \ {\isachardoublequoteopen}replicate\ {\isadigit{0}}\ {\isacharunderscore}\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}{\isachardoublequoteclose}\isanewline
haftmann
parents: 28565
diff changeset
   894
\ \ {\isacharbar}\ {\isachardoublequoteopen}replicate\ {\isacharparenleft}Suc\ n{\isacharparenright}\ xs\ {\isacharequal}\ xs\ {\isacharat}\ replicate\ n\ xs{\isachardoublequoteclose}\isanewline
25247
haftmann
parents: 25200
diff changeset
   895
\isanewline
29513
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   896
\isacommand{interpretation}\isamarkupfalse%
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   897
\ list{\isacharunderscore}monoid{\isacharbang}{\isacharcolon}\ monoid\ append\ {\isachardoublequoteopen}{\isacharbrackleft}{\isacharbrackright}{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
28566
haftmann
parents: 28565
diff changeset
   898
\ \ {\isachardoublequoteopen}monoid{\isachardot}pow{\isacharunderscore}nat\ append\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharequal}\ replicate{\isachardoublequoteclose}\isanewline
25247
haftmann
parents: 25200
diff changeset
   899
\isacommand{proof}\isamarkupfalse%
28540
haftmann
parents: 27507
diff changeset
   900
\ {\isacharminus}\isanewline
29513
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   901
\ \ \isacommand{interpret}\isamarkupfalse%
363f17dee9ca adapted to changes in class package
haftmann
parents: 29297
diff changeset
   902
\ monoid\ append\ {\isachardoublequoteopen}{\isacharbrackleft}{\isacharbrackright}{\isachardoublequoteclose}\ \isacommand{{\isachardot}{\isachardot}}\isamarkupfalse%
25247
haftmann
parents: 25200
diff changeset
   903
\isanewline
28566
haftmann
parents: 28565
diff changeset
   904
\ \ \isacommand{show}\isamarkupfalse%
28565
haftmann
parents: 28540
diff changeset
   905
\ {\isachardoublequoteopen}monoid{\isachardot}pow{\isacharunderscore}nat\ append\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharequal}\ replicate{\isachardoublequoteclose}\isanewline
28566
haftmann
parents: 28565
diff changeset
   906
\ \ \isacommand{proof}\isamarkupfalse%
28540
haftmann
parents: 27507
diff changeset
   907
\isanewline
28566
haftmann
parents: 28565
diff changeset
   908
\ \ \ \ \isacommand{fix}\isamarkupfalse%
28540
haftmann
parents: 27507
diff changeset
   909
\ n\isanewline
28566
haftmann
parents: 28565
diff changeset
   910
\ \ \ \ \isacommand{show}\isamarkupfalse%
28565
haftmann
parents: 28540
diff changeset
   911
\ {\isachardoublequoteopen}monoid{\isachardot}pow{\isacharunderscore}nat\ append\ {\isacharbrackleft}{\isacharbrackright}\ n\ {\isacharequal}\ replicate\ n{\isachardoublequoteclose}\isanewline
28566
haftmann
parents: 28565
diff changeset
   912
\ \ \ \ \ \ \isacommand{by}\isamarkupfalse%
25247
haftmann
parents: 25200
diff changeset
   913
\ {\isacharparenleft}induct\ n{\isacharparenright}\ auto\isanewline
28566
haftmann
parents: 28565
diff changeset
   914
\ \ \isacommand{qed}\isamarkupfalse%
28540
haftmann
parents: 27507
diff changeset
   915
\isanewline
28566
haftmann
parents: 28565
diff changeset
   916
\isacommand{qed}\isamarkupfalse%
28540
haftmann
parents: 27507
diff changeset
   917
\ intro{\isacharunderscore}locales%
28566
haftmann
parents: 28565
diff changeset
   918
\endisatagquote
haftmann
parents: 28565
diff changeset
   919
{\isafoldquote}%
25247
haftmann
parents: 25200
diff changeset
   920
%
28566
haftmann
parents: 28565
diff changeset
   921
\isadelimquote
25247
haftmann
parents: 25200
diff changeset
   922
%
28566
haftmann
parents: 28565
diff changeset
   923
\endisadelimquote
25247
haftmann
parents: 25200
diff changeset
   924
%
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   925
\isamarkupsubsection{Additional subclass relations%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   926
}
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   927
\isamarkuptrue%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   928
%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   929
\begin{isamarkuptext}%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   930
Any \isa{group} is also a \isa{monoid};  this
25247
haftmann
parents: 25200
diff changeset
   931
  can be made explicit by claiming an additional
haftmann
parents: 25200
diff changeset
   932
  subclass relation,
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   933
  together with a proof of the logical difference:%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   934
\end{isamarkuptext}%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   935
\isamarkuptrue%
28566
haftmann
parents: 28565
diff changeset
   936
%
haftmann
parents: 28565
diff changeset
   937
\isadelimquote
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   938
%
28566
haftmann
parents: 28565
diff changeset
   939
\endisadelimquote
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   940
%
28566
haftmann
parents: 28565
diff changeset
   941
\isatagquote
haftmann
parents: 28565
diff changeset
   942
\isacommand{subclass}\isamarkupfalse%
haftmann
parents: 28565
diff changeset
   943
\ {\isacharparenleft}\isakeyword{in}\ group{\isacharparenright}\ monoid\isanewline
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   944
\isacommand{proof}\isamarkupfalse%
28947
ac1a14b5a085 unfold_locales is default method - no need for explicit references
haftmann
parents: 28727
diff changeset
   945
\isanewline
28566
haftmann
parents: 28565
diff changeset
   946
\ \ \isacommand{fix}\isamarkupfalse%
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   947
\ x\isanewline
28566
haftmann
parents: 28565
diff changeset
   948
\ \ \isacommand{from}\isamarkupfalse%
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   949
\ invl\ \isacommand{have}\isamarkupfalse%
25200
f1d2e106f2fe adjusted
haftmann
parents: 25004
diff changeset
   950
\ {\isachardoublequoteopen}x{\isasymdiv}\ {\isasymotimes}\ x\ {\isacharequal}\ {\isasymone}{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse%
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   951
\ simp\isanewline
28566
haftmann
parents: 28565
diff changeset
   952
\ \ \isacommand{with}\isamarkupfalse%
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   953
\ assoc\ {\isacharbrackleft}symmetric{\isacharbrackright}\ neutl\ invl\ \isacommand{have}\isamarkupfalse%
25200
f1d2e106f2fe adjusted
haftmann
parents: 25004
diff changeset
   954
\ {\isachardoublequoteopen}x{\isasymdiv}\ {\isasymotimes}\ {\isacharparenleft}x\ {\isasymotimes}\ {\isasymone}{\isacharparenright}\ {\isacharequal}\ x{\isasymdiv}\ {\isasymotimes}\ x{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse%
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   955
\ simp\isanewline
28566
haftmann
parents: 28565
diff changeset
   956
\ \ \isacommand{with}\isamarkupfalse%
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   957
\ left{\isacharunderscore}cancel\ \isacommand{show}\isamarkupfalse%
25200
f1d2e106f2fe adjusted
haftmann
parents: 25004
diff changeset
   958
\ {\isachardoublequoteopen}x\ {\isasymotimes}\ {\isasymone}\ {\isacharequal}\ x{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse%
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   959
\ simp\isanewline
28566
haftmann
parents: 28565
diff changeset
   960
\isacommand{qed}\isamarkupfalse%
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   961
%
28566
haftmann
parents: 28565
diff changeset
   962
\endisatagquote
haftmann
parents: 28565
diff changeset
   963
{\isafoldquote}%
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   964
%
28566
haftmann
parents: 28565
diff changeset
   965
\isadelimquote
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   966
%
28566
haftmann
parents: 28565
diff changeset
   967
\endisadelimquote
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   968
%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   969
\begin{isamarkuptext}%
30227
853abb4853cc tuned manuals
haftmann
parents: 30226
diff changeset
   970
The logical proof is carried out on the locale level.
28947
ac1a14b5a085 unfold_locales is default method - no need for explicit references
haftmann
parents: 28727
diff changeset
   971
  Afterwards it is propagated
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
   972
  to the type system, making \isa{group} an instance of
25247
haftmann
parents: 25200
diff changeset
   973
  \isa{monoid} by adding an additional edge
haftmann
parents: 25200
diff changeset
   974
  to the graph of subclass relations
haftmann
parents: 25200
diff changeset
   975
  (cf.\ \figref{fig:subclass}).
haftmann
parents: 25200
diff changeset
   976
haftmann
parents: 25200
diff changeset
   977
  \begin{figure}[htbp]
haftmann
parents: 25200
diff changeset
   978
   \begin{center}
haftmann
parents: 25200
diff changeset
   979
     \small
haftmann
parents: 25200
diff changeset
   980
     \unitlength 0.6mm
haftmann
parents: 25200
diff changeset
   981
     \begin{picture}(40,60)(0,0)
haftmann
parents: 25200
diff changeset
   982
       \put(20,60){\makebox(0,0){\isa{semigroup}}}
haftmann
parents: 25200
diff changeset
   983
       \put(20,40){\makebox(0,0){\isa{monoidl}}}
haftmann
parents: 25200
diff changeset
   984
       \put(00,20){\makebox(0,0){\isa{monoid}}}
haftmann
parents: 25200
diff changeset
   985
       \put(40,00){\makebox(0,0){\isa{group}}}
haftmann
parents: 25200
diff changeset
   986
       \put(20,55){\vector(0,-1){10}}
haftmann
parents: 25200
diff changeset
   987
       \put(15,35){\vector(-1,-1){10}}
haftmann
parents: 25200
diff changeset
   988
       \put(25,35){\vector(1,-3){10}}
haftmann
parents: 25200
diff changeset
   989
     \end{picture}
haftmann
parents: 25200
diff changeset
   990
     \hspace{8em}
haftmann
parents: 25200
diff changeset
   991
     \begin{picture}(40,60)(0,0)
haftmann
parents: 25200
diff changeset
   992
       \put(20,60){\makebox(0,0){\isa{semigroup}}}
haftmann
parents: 25200
diff changeset
   993
       \put(20,40){\makebox(0,0){\isa{monoidl}}}
haftmann
parents: 25200
diff changeset
   994
       \put(00,20){\makebox(0,0){\isa{monoid}}}
haftmann
parents: 25200
diff changeset
   995
       \put(40,00){\makebox(0,0){\isa{group}}}
haftmann
parents: 25200
diff changeset
   996
       \put(20,55){\vector(0,-1){10}}
haftmann
parents: 25200
diff changeset
   997
       \put(15,35){\vector(-1,-1){10}}
haftmann
parents: 25200
diff changeset
   998
       \put(05,15){\vector(3,-1){30}}
haftmann
parents: 25200
diff changeset
   999
     \end{picture}
haftmann
parents: 25200
diff changeset
  1000
     \caption{Subclass relationship of monoids and groups:
haftmann
parents: 25200
diff changeset
  1001
        before and after establishing the relationship
30227
853abb4853cc tuned manuals
haftmann
parents: 30226
diff changeset
  1002
        \isa{group\ {\isasymsubseteq}\ monoid};  transitive edges are left out.}
25247
haftmann
parents: 25200
diff changeset
  1003
     \label{fig:subclass}
haftmann
parents: 25200
diff changeset
  1004
   \end{center}
haftmann
parents: 25200
diff changeset
  1005
  \end{figure}
30227
853abb4853cc tuned manuals
haftmann
parents: 30226
diff changeset
  1006
25247
haftmann
parents: 25200
diff changeset
  1007
  For illustration, a derived definition
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
  1008
  in \isa{group} which uses \isa{pow{\isacharunderscore}nat}:%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
  1009
\end{isamarkuptext}%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
  1010
\isamarkuptrue%
28565
haftmann
parents: 28540
diff changeset
  1011
%
haftmann
parents: 28540
diff changeset
  1012
\isadelimquote
haftmann
parents: 28540
diff changeset
  1013
%
haftmann
parents: 28540
diff changeset
  1014
\endisadelimquote
haftmann
parents: 28540
diff changeset
  1015
%
haftmann
parents: 28540
diff changeset
  1016
\isatagquote
haftmann
parents: 28540
diff changeset
  1017
\isacommand{definition}\isamarkupfalse%
haftmann
parents: 28540
diff changeset
  1018
\ {\isacharparenleft}\isakeyword{in}\ group{\isacharparenright}\ pow{\isacharunderscore}int\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}int\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
haftmann
parents: 28540
diff changeset
  1019
\ \ {\isachardoublequoteopen}pow{\isacharunderscore}int\ k\ x\ {\isacharequal}\ {\isacharparenleft}if\ k\ {\isachargreater}{\isacharequal}\ {\isadigit{0}}\isanewline
haftmann
parents: 28540
diff changeset
  1020
\ \ \ \ then\ pow{\isacharunderscore}nat\ {\isacharparenleft}nat\ k{\isacharparenright}\ x\isanewline
haftmann
parents: 28540
diff changeset
  1021
\ \ \ \ else\ {\isacharparenleft}pow{\isacharunderscore}nat\ {\isacharparenleft}nat\ {\isacharparenleft}{\isacharminus}\ k{\isacharparenright}{\isacharparenright}\ x{\isacharparenright}{\isasymdiv}{\isacharparenright}{\isachardoublequoteclose}%
haftmann
parents: 28540
diff changeset
  1022
\endisatagquote
haftmann
parents: 28540
diff changeset
  1023
{\isafoldquote}%
haftmann
parents: 28540
diff changeset
  1024
%
haftmann
parents: 28540
diff changeset
  1025
\isadelimquote
haftmann
parents: 28540
diff changeset
  1026
%
haftmann
parents: 28540
diff changeset
  1027
\endisadelimquote
haftmann
parents: 28540
diff changeset
  1028
%
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
  1029
\begin{isamarkuptext}%
25247
haftmann
parents: 25200
diff changeset
  1030
\noindent yields the global definition of
24991
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
  1031
  \isa{{\isachardoublequote}pow{\isacharunderscore}int\ {\isasymColon}\ int\ {\isasymRightarrow}\ {\isasymalpha}{\isasymColon}group\ {\isasymRightarrow}\ {\isasymalpha}{\isasymColon}group{\isachardoublequote}}
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
  1032
  with the corresponding theorem \isa{pow{\isacharunderscore}int\ k\ x\ {\isacharequal}\ {\isacharparenleft}if\ {\isadigit{0}}\ {\isasymle}\ k\ then\ pow{\isacharunderscore}nat\ {\isacharparenleft}nat\ k{\isacharparenright}\ x\ else\ {\isacharparenleft}pow{\isacharunderscore}nat\ {\isacharparenleft}nat\ {\isacharparenleft}{\isacharminus}\ k{\isacharparenright}{\isacharparenright}\ x{\isacharparenright}{\isasymdiv}{\isacharparenright}}.%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
  1033
\end{isamarkuptext}%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
  1034
\isamarkuptrue%
c6f5cc939c29 added subclass command
haftmann
parents: 24628
diff changeset
  1035
%
25868
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1036
\isamarkupsubsection{A note on syntax%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1037
}
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1038
\isamarkuptrue%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1039
%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1040
\begin{isamarkuptext}%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1041
As a commodity, class context syntax allows to refer
27507
32d18c9b7f21 updated generated file;
wenzelm
parents: 26991
diff changeset
  1042
  to local class operations and their global counterparts
25868
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1043
  uniformly;  type inference resolves ambiguities.  For example:%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1044
\end{isamarkuptext}%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1045
\isamarkuptrue%
28565
haftmann
parents: 28540
diff changeset
  1046
%
haftmann
parents: 28540
diff changeset
  1047
\isadelimquote
haftmann
parents: 28540
diff changeset
  1048
%
haftmann
parents: 28540
diff changeset
  1049
\endisadelimquote
haftmann
parents: 28540
diff changeset
  1050
%
haftmann
parents: 28540
diff changeset
  1051
\isatagquote
25868
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1052
\isacommand{context}\isamarkupfalse%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1053
\ semigroup\isanewline
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1054
\isakeyword{begin}\isanewline
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1055
\isanewline
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1056
\isacommand{term}\isamarkupfalse%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1057
\ {\isachardoublequoteopen}x\ {\isasymotimes}\ y{\isachardoublequoteclose}\ %
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1058
\isamarkupcmt{example 1%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1059
}
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1060
\isanewline
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1061
\isacommand{term}\isamarkupfalse%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1062
\ {\isachardoublequoteopen}{\isacharparenleft}x{\isasymColon}nat{\isacharparenright}\ {\isasymotimes}\ y{\isachardoublequoteclose}\ %
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1063
\isamarkupcmt{example 2%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1064
}
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1065
\isanewline
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1066
\isanewline
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1067
\isacommand{end}\isamarkupfalse%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1068
\isanewline
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1069
\isanewline
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1070
\isacommand{term}\isamarkupfalse%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1071
\ {\isachardoublequoteopen}x\ {\isasymotimes}\ y{\isachardoublequoteclose}\ %
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1072
\isamarkupcmt{example 3%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1073
}
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1074
%
28565
haftmann
parents: 28540
diff changeset
  1075
\endisatagquote
haftmann
parents: 28540
diff changeset
  1076
{\isafoldquote}%
haftmann
parents: 28540
diff changeset
  1077
%
haftmann
parents: 28540
diff changeset
  1078
\isadelimquote
haftmann
parents: 28540
diff changeset
  1079
%
haftmann
parents: 28540
diff changeset
  1080
\endisadelimquote
haftmann
parents: 28540
diff changeset
  1081
%
25868
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1082
\begin{isamarkuptext}%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1083
\noindent Here in example 1, the term refers to the local class operation
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1084
  \isa{mult\ {\isacharbrackleft}{\isasymalpha}{\isacharbrackright}}, whereas in example 2 the type constraint
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1085
  enforces the global class operation \isa{mult\ {\isacharbrackleft}nat{\isacharbrackright}}.
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1086
  In the global context in example 3, the reference is
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1087
  to the polymorphic global class operation \isa{mult\ {\isacharbrackleft}{\isacharquery}{\isasymalpha}\ {\isasymColon}\ semigroup{\isacharbrackright}}.%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1088
\end{isamarkuptext}%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1089
\isamarkuptrue%
97c6787099bc a note on syntax
haftmann
parents: 25533
diff changeset
  1090
%
29705
a1ecdd8cf81c updated class documentation
haftmann
parents: 29513
diff changeset
  1091
\isamarkupsection{Further issues%
a1ecdd8cf81c updated class documentation
haftmann
parents: 29513
diff changeset
  1092
}
a1ecdd8cf81c updated class documentation
haftmann
parents: 29513
diff changeset
  1093
\isamarkuptrue%
a1ecdd8cf81c updated class documentation
haftmann
parents: 29513
diff changeset
  1094
%
a1ecdd8cf81c updated class documentation
haftmann
parents: 29513
diff changeset
  1095
\isamarkupsubsection{Type classes and code generation%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1096
}
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1097
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1098
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1099
\begin{isamarkuptext}%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
  1100
Turning back to the first motivation for type classes,
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
  1101
  namely overloading, it is obvious that overloading
28565
haftmann
parents: 28540
diff changeset
  1102
  stemming from \hyperlink{command.class}{\mbox{\isa{\isacommand{class}}}} statements and
haftmann
parents: 28540
diff changeset
  1103
  \hyperlink{command.instantiation}{\mbox{\isa{\isacommand{instantiation}}}}
25533
0140cc7b26ad added something about instantiation target
haftmann
parents: 25247
diff changeset
  1104
  targets naturally maps to Haskell type classes.
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
  1105
  The code generator framework \cite{isabelle-codegen} 
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
  1106
  takes this into account.  Concerning target languages
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
  1107
  lacking type classes (e.g.~SML), type classes
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
  1108
  are implemented by explicit dictionary construction.
28565
haftmann
parents: 28540
diff changeset
  1109
  As example, let's go back to the power function:%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1110
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1111
\isamarkuptrue%
28565
haftmann
parents: 28540
diff changeset
  1112
%
haftmann
parents: 28540
diff changeset
  1113
\isadelimquote
haftmann
parents: 28540
diff changeset
  1114
%
haftmann
parents: 28540
diff changeset
  1115
\endisadelimquote
haftmann
parents: 28540
diff changeset
  1116
%
haftmann
parents: 28540
diff changeset
  1117
\isatagquote
haftmann
parents: 28540
diff changeset
  1118
\isacommand{definition}\isamarkupfalse%
haftmann
parents: 28540
diff changeset
  1119
\ example\ {\isacharcolon}{\isacharcolon}\ int\ \isakeyword{where}\isanewline
haftmann
parents: 28540
diff changeset
  1120
\ \ {\isachardoublequoteopen}example\ {\isacharequal}\ pow{\isacharunderscore}int\ {\isadigit{1}}{\isadigit{0}}\ {\isacharparenleft}{\isacharminus}{\isadigit{2}}{\isacharparenright}{\isachardoublequoteclose}%
haftmann
parents: 28540
diff changeset
  1121
\endisatagquote
haftmann
parents: 28540
diff changeset
  1122
{\isafoldquote}%
haftmann
parents: 28540
diff changeset
  1123
%
haftmann
parents: 28540
diff changeset
  1124
\isadelimquote
haftmann
parents: 28540
diff changeset
  1125
%
haftmann
parents: 28540
diff changeset
  1126
\endisadelimquote
haftmann
parents: 28540
diff changeset
  1127
%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1128
\begin{isamarkuptext}%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
  1129
\noindent This maps to Haskell as:%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1130
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1131
\isamarkuptrue%
28540
haftmann
parents: 27507
diff changeset
  1132
%
28565
haftmann
parents: 28540
diff changeset
  1133
\isadelimquote
28540
haftmann
parents: 27507
diff changeset
  1134
%
28565
haftmann
parents: 28540
diff changeset
  1135
\endisadelimquote
28540
haftmann
parents: 27507
diff changeset
  1136
%
28565
haftmann
parents: 28540
diff changeset
  1137
\isatagquote
28540
haftmann
parents: 27507
diff changeset
  1138
%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1139
\begin{isamarkuptext}%
28727
185110a4b97a clarified verbatim vs. typewriter
haftmann
parents: 28714
diff changeset
  1140
\isatypewriter%
28540
haftmann
parents: 27507
diff changeset
  1141
\noindent%
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1142
\hspace*{0pt}module Example where {\char123}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1143
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1144
\hspace*{0pt}\\
30121
5c7bcb296600 updated generated files;
wenzelm
parents: 29705
diff changeset
  1145
\hspace*{0pt}data Nat = Zero{\char95}nat | Suc Nat;\\
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1146
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1147
\hspace*{0pt}nat{\char95}aux ::~Integer -> Nat -> Nat;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1148
\hspace*{0pt}nat{\char95}aux i n = (if i <= 0 then n else nat{\char95}aux (i - 1) (Suc n));\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1149
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1150
\hspace*{0pt}nat ::~Integer -> Nat;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1151
\hspace*{0pt}nat i = nat{\char95}aux i Zero{\char95}nat;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1152
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1153
\hspace*{0pt}class Semigroup a where {\char123}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1154
\hspace*{0pt} ~mult ::~a -> a -> a;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1155
\hspace*{0pt}{\char125};\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1156
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1157
\hspace*{0pt}class (Semigroup a) => Monoidl a where {\char123}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1158
\hspace*{0pt} ~neutral ::~a;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1159
\hspace*{0pt}{\char125};\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1160
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1161
\hspace*{0pt}class (Monoidl a) => Monoid a where {\char123}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1162
\hspace*{0pt}{\char125};\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1163
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1164
\hspace*{0pt}class (Monoid a) => Group a where {\char123}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1165
\hspace*{0pt} ~inverse ::~a -> a;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1166
\hspace*{0pt}{\char125};\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1167
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1168
\hspace*{0pt}inverse{\char95}int ::~Integer -> Integer;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1169
\hspace*{0pt}inverse{\char95}int i = negate i;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1170
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1171
\hspace*{0pt}neutral{\char95}int ::~Integer;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1172
\hspace*{0pt}neutral{\char95}int = 0;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1173
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1174
\hspace*{0pt}mult{\char95}int ::~Integer -> Integer -> Integer;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1175
\hspace*{0pt}mult{\char95}int i j = i + j;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1176
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1177
\hspace*{0pt}instance Semigroup Integer where {\char123}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1178
\hspace*{0pt} ~mult = mult{\char95}int;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1179
\hspace*{0pt}{\char125};\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1180
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1181
\hspace*{0pt}instance Monoidl Integer where {\char123}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1182
\hspace*{0pt} ~neutral = neutral{\char95}int;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1183
\hspace*{0pt}{\char125};\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1184
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1185
\hspace*{0pt}instance Monoid Integer where {\char123}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1186
\hspace*{0pt}{\char125};\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1187
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1188
\hspace*{0pt}instance Group Integer where {\char123}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1189
\hspace*{0pt} ~inverse = inverse{\char95}int;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1190
\hspace*{0pt}{\char125};\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1191
\hspace*{0pt}\\
28947
ac1a14b5a085 unfold_locales is default method - no need for explicit references
haftmann
parents: 28727
diff changeset
  1192
\hspace*{0pt}pow{\char95}nat ::~forall a.~(Monoid a) => Nat -> a -> a;\\
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1193
\hspace*{0pt}pow{\char95}nat Zero{\char95}nat x = neutral;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1194
\hspace*{0pt}pow{\char95}nat (Suc n) x = mult x (pow{\char95}nat n x);\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1195
\hspace*{0pt}\\
28947
ac1a14b5a085 unfold_locales is default method - no need for explicit references
haftmann
parents: 28727
diff changeset
  1196
\hspace*{0pt}pow{\char95}int ::~forall a.~(Group a) => Integer -> a -> a;\\
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1197
\hspace*{0pt}pow{\char95}int k x =\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1198
\hspace*{0pt} ~(if 0 <= k then pow{\char95}nat (nat k) x\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1199
\hspace*{0pt} ~~~else inverse (pow{\char95}nat (nat (negate k)) x));\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1200
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1201
\hspace*{0pt}example ::~Integer;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1202
\hspace*{0pt}example = pow{\char95}int 10 (-2);\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1203
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1204
\hspace*{0pt}{\char125}%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
  1205
\end{isamarkuptext}%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
  1206
\isamarkuptrue%
28540
haftmann
parents: 27507
diff changeset
  1207
%
28565
haftmann
parents: 28540
diff changeset
  1208
\endisatagquote
haftmann
parents: 28540
diff changeset
  1209
{\isafoldquote}%
28540
haftmann
parents: 27507
diff changeset
  1210
%
28565
haftmann
parents: 28540
diff changeset
  1211
\isadelimquote
28540
haftmann
parents: 27507
diff changeset
  1212
%
28565
haftmann
parents: 28540
diff changeset
  1213
\endisadelimquote
28540
haftmann
parents: 27507
diff changeset
  1214
%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
  1215
\begin{isamarkuptext}%
28540
haftmann
parents: 27507
diff changeset
  1216
\noindent The whole code in SML with explicit dictionary passing:%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1217
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1218
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1219
%
28565
haftmann
parents: 28540
diff changeset
  1220
\isadelimquote
28540
haftmann
parents: 27507
diff changeset
  1221
%
28565
haftmann
parents: 28540
diff changeset
  1222
\endisadelimquote
28540
haftmann
parents: 27507
diff changeset
  1223
%
28565
haftmann
parents: 28540
diff changeset
  1224
\isatagquote
28540
haftmann
parents: 27507
diff changeset
  1225
%
haftmann
parents: 27507
diff changeset
  1226
\begin{isamarkuptext}%
28727
185110a4b97a clarified verbatim vs. typewriter
haftmann
parents: 28714
diff changeset
  1227
\isatypewriter%
28540
haftmann
parents: 27507
diff changeset
  1228
\noindent%
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1229
\hspace*{0pt}structure Example = \\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1230
\hspace*{0pt}struct\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1231
\hspace*{0pt}\\
30121
5c7bcb296600 updated generated files;
wenzelm
parents: 29705
diff changeset
  1232
\hspace*{0pt}datatype nat = Zero{\char95}nat | Suc of nat;\\
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1233
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1234
\hspace*{0pt}fun nat{\char95}aux i n =\\
28947
ac1a14b5a085 unfold_locales is default method - no need for explicit references
haftmann
parents: 28727
diff changeset
  1235
\hspace*{0pt} ~(if IntInf.<= (i,~(0 :~IntInf.int)) then n\\
ac1a14b5a085 unfold_locales is default method - no need for explicit references
haftmann
parents: 28727
diff changeset
  1236
\hspace*{0pt} ~~~else nat{\char95}aux (IntInf.- (i,~(1 :~IntInf.int))) (Suc n));\\
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1237
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1238
\hspace*{0pt}fun nat i = nat{\char95}aux i Zero{\char95}nat;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1239
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1240
\hspace*{0pt}type 'a semigroup = {\char123}mult :~'a -> 'a -> 'a{\char125};\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1241
\hspace*{0pt}fun mult (A{\char95}:'a semigroup) = {\char35}mult A{\char95};\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1242
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1243
\hspace*{0pt}type 'a monoidl =\\
28947
ac1a14b5a085 unfold_locales is default method - no need for explicit references
haftmann
parents: 28727
diff changeset
  1244
\hspace*{0pt} ~{\char123}Classes{\char95}{\char95}semigroup{\char95}monoidl :~'a semigroup,~neutral :~'a{\char125};\\
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1245
\hspace*{0pt}fun semigroup{\char95}monoidl (A{\char95}:'a monoidl) = {\char35}Classes{\char95}{\char95}semigroup{\char95}monoidl A{\char95};\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1246
\hspace*{0pt}fun neutral (A{\char95}:'a monoidl) = {\char35}neutral A{\char95};\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1247
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1248
\hspace*{0pt}type 'a monoid = {\char123}Classes{\char95}{\char95}monoidl{\char95}monoid :~'a monoidl{\char125};\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1249
\hspace*{0pt}fun monoidl{\char95}monoid (A{\char95}:'a monoid) = {\char35}Classes{\char95}{\char95}monoidl{\char95}monoid A{\char95};\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1250
\hspace*{0pt}\\
28947
ac1a14b5a085 unfold_locales is default method - no need for explicit references
haftmann
parents: 28727
diff changeset
  1251
\hspace*{0pt}type 'a group = {\char123}Classes{\char95}{\char95}monoid{\char95}group :~'a monoid,~inverse :~'a -> 'a{\char125};\\
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1252
\hspace*{0pt}fun monoid{\char95}group (A{\char95}:'a group) = {\char35}Classes{\char95}{\char95}monoid{\char95}group A{\char95};\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1253
\hspace*{0pt}fun inverse (A{\char95}:'a group) = {\char35}inverse A{\char95};\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1254
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1255
\hspace*{0pt}fun inverse{\char95}int i = IntInf.{\char126}~i;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1256
\hspace*{0pt}\\
29297
62e0f892e525 updated generated files;
wenzelm
parents: 28948
diff changeset
  1257
\hspace*{0pt}val neutral{\char95}int :~IntInf.int = (0 :~IntInf.int)\\
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1258
\hspace*{0pt}\\
28947
ac1a14b5a085 unfold_locales is default method - no need for explicit references
haftmann
parents: 28727
diff changeset
  1259
\hspace*{0pt}fun mult{\char95}int i j = IntInf.+ (i,~j);\\
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1260
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1261
\hspace*{0pt}val semigroup{\char95}int = {\char123}mult = mult{\char95}int{\char125}~:~IntInf.int semigroup;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1262
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1263
\hspace*{0pt}val monoidl{\char95}int =\\
28947
ac1a14b5a085 unfold_locales is default method - no need for explicit references
haftmann
parents: 28727
diff changeset
  1264
\hspace*{0pt} ~{\char123}Classes{\char95}{\char95}semigroup{\char95}monoidl = semigroup{\char95}int,~neutral = neutral{\char95}int{\char125}~:\\
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1265
\hspace*{0pt} ~IntInf.int monoidl;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1266
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1267
\hspace*{0pt}val monoid{\char95}int = {\char123}Classes{\char95}{\char95}monoidl{\char95}monoid = monoidl{\char95}int{\char125}~:\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1268
\hspace*{0pt} ~IntInf.int monoid;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1269
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1270
\hspace*{0pt}val group{\char95}int =\\
28947
ac1a14b5a085 unfold_locales is default method - no need for explicit references
haftmann
parents: 28727
diff changeset
  1271
\hspace*{0pt} ~{\char123}Classes{\char95}{\char95}monoid{\char95}group = monoid{\char95}int,~inverse = inverse{\char95}int{\char125}~:\\
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1272
\hspace*{0pt} ~IntInf.int group;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1273
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1274
\hspace*{0pt}fun pow{\char95}nat A{\char95}~Zero{\char95}nat x = neutral (monoidl{\char95}monoid A{\char95})\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1275
\hspace*{0pt} ~| pow{\char95}nat A{\char95}~(Suc n) x =\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1276
\hspace*{0pt} ~~~mult ((semigroup{\char95}monoidl o monoidl{\char95}monoid) A{\char95}) x (pow{\char95}nat A{\char95}~n x);\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1277
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1278
\hspace*{0pt}fun pow{\char95}int A{\char95}~k x =\\
28947
ac1a14b5a085 unfold_locales is default method - no need for explicit references
haftmann
parents: 28727
diff changeset
  1279
\hspace*{0pt} ~(if IntInf.<= ((0 :~IntInf.int),~k)\\
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1280
\hspace*{0pt} ~~~then pow{\char95}nat (monoid{\char95}group A{\char95}) (nat k) x\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1281
\hspace*{0pt} ~~~else inverse A{\char95}~(pow{\char95}nat (monoid{\char95}group A{\char95}) (nat (IntInf.{\char126}~k)) x));\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1282
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1283
\hspace*{0pt}val example :~IntInf.int =\\
29297
62e0f892e525 updated generated files;
wenzelm
parents: 28948
diff changeset
  1284
\hspace*{0pt} ~pow{\char95}int group{\char95}int (10 :~IntInf.int) ({\char126}2 :~IntInf.int)\\
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28566
diff changeset
  1285
\hspace*{0pt}\\
28947
ac1a14b5a085 unfold_locales is default method - no need for explicit references
haftmann
parents: 28727
diff changeset
  1286
\hspace*{0pt}end;~(*struct Example*)%
28540
haftmann
parents: 27507
diff changeset
  1287
\end{isamarkuptext}%
haftmann
parents: 27507
diff changeset
  1288
\isamarkuptrue%
haftmann
parents: 27507
diff changeset
  1289
%
28565
haftmann
parents: 28540
diff changeset
  1290
\endisatagquote
haftmann
parents: 28540
diff changeset
  1291
{\isafoldquote}%
28540
haftmann
parents: 27507
diff changeset
  1292
%
28565
haftmann
parents: 28540
diff changeset
  1293
\isadelimquote
28540
haftmann
parents: 27507
diff changeset
  1294
%
28565
haftmann
parents: 28540
diff changeset
  1295
\endisadelimquote
28540
haftmann
parents: 27507
diff changeset
  1296
%
29705
a1ecdd8cf81c updated class documentation
haftmann
parents: 29513
diff changeset
  1297
\isamarkupsubsection{Inspecting the type class universe%
a1ecdd8cf81c updated class documentation
haftmann
parents: 29513
diff changeset
  1298
}
a1ecdd8cf81c updated class documentation
haftmann
parents: 29513
diff changeset
  1299
\isamarkuptrue%
a1ecdd8cf81c updated class documentation
haftmann
parents: 29513
diff changeset
  1300
%
a1ecdd8cf81c updated class documentation
haftmann
parents: 29513
diff changeset
  1301
\begin{isamarkuptext}%
a1ecdd8cf81c updated class documentation
haftmann
parents: 29513
diff changeset
  1302
To facilitate orientation in complex subclass structures,
a1ecdd8cf81c updated class documentation
haftmann
parents: 29513
diff changeset
  1303
  two diagnostics commands are provided:
a1ecdd8cf81c updated class documentation
haftmann
parents: 29513
diff changeset
  1304
a1ecdd8cf81c updated class documentation
haftmann
parents: 29513
diff changeset
  1305
  \begin{description}
a1ecdd8cf81c updated class documentation
haftmann
parents: 29513
diff changeset
  1306
a1ecdd8cf81c updated class documentation
haftmann
parents: 29513
diff changeset
  1307
    \item[\hyperlink{command.print-classes}{\mbox{\isa{\isacommand{print{\isacharunderscore}classes}}}}] print a list of all classes
a1ecdd8cf81c updated class documentation
haftmann
parents: 29513
diff changeset
  1308
      together with associated operations etc.
a1ecdd8cf81c updated class documentation
haftmann
parents: 29513
diff changeset
  1309
a1ecdd8cf81c updated class documentation
haftmann
parents: 29513
diff changeset
  1310
    \item[\hyperlink{command.class-deps}{\mbox{\isa{\isacommand{class{\isacharunderscore}deps}}}}] visualizes the subclass relation
a1ecdd8cf81c updated class documentation
haftmann
parents: 29513
diff changeset
  1311
      between all classes as a Hasse diagram.
a1ecdd8cf81c updated class documentation
haftmann
parents: 29513
diff changeset
  1312
a1ecdd8cf81c updated class documentation
haftmann
parents: 29513
diff changeset
  1313
  \end{description}%
a1ecdd8cf81c updated class documentation
haftmann
parents: 29513
diff changeset
  1314
\end{isamarkuptext}%
a1ecdd8cf81c updated class documentation
haftmann
parents: 29513
diff changeset
  1315
\isamarkuptrue%
a1ecdd8cf81c updated class documentation
haftmann
parents: 29513
diff changeset
  1316
%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1317
\isadelimtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1318
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1319
\endisadelimtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1320
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1321
\isatagtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1322
\isacommand{end}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1323
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1324
\endisatagtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1325
{\isafoldtheory}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1326
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1327
\isadelimtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1328
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1329
\endisadelimtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1330
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1331
\end{isabellebody}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1332
%%% Local Variables:
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1333
%%% mode: latex
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1334
%%% TeX-master: "root"
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
  1335
%%% End: