doc-src/IsarAdvanced/Classes/Thy/document/Classes.tex
author wenzelm
Sun, 29 Jul 2007 22:42:00 +0200
changeset 24067 69b51bc5ce06
parent 23956 48494ccfabaf
child 24628 33137422d7fd
permissions -rw-r--r--
adapted ThyLoad.deps_thy;
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
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
     7
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
     8
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
     9
\endisadelimtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    10
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    11
\isatagtheory
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
    12
%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    13
\endisatagtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    14
{\isafoldtheory}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    15
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    16
\isadelimtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    17
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    18
\endisadelimtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    19
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    20
\isadelimML
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    21
%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    22
\endisadelimML
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    23
%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    24
\isatagML
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    25
%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    26
\endisatagML
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    27
{\isafoldML}%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    28
%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    29
\isadelimML
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    30
%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    31
\endisadelimML
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    32
%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    33
\isadelimML
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    34
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    35
\endisadelimML
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    36
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    37
\isatagML
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    38
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    39
\endisatagML
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    40
{\isafoldML}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    41
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    42
\isadelimML
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    43
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    44
\endisadelimML
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    45
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    46
\isamarkupchapter{Haskell-style classes with Isabelle/Isar%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    47
}
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    48
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    49
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    50
\isamarkupsection{Introduction%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    51
}
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    52
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    53
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    54
\begin{isamarkuptext}%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    55
Type classes were introduces by Wadler and Blott \cite{wadler89how}
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    56
  into the Haskell language, to allow for a reasonable implementation
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    57
  of overloading\footnote{throughout this tutorial, we are referring
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    58
  to classical Haskell 1.0 type classes, not considering
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    59
  later additions in expressiveness}.
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    60
  As a canonical example, a polymorphic equality function
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    61
  \isa{eq\ {\isasymColon}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ bool} which is overloaded on different
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
    62
  types for \isa{{\isasymalpha}}, which is achieved by splitting introduction
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    63
  of the \isa{eq} function from its overloaded definitions by means
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    64
  of \isa{class} and \isa{instance} declarations:
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    65
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    66
  \medskip\noindent\hspace*{2ex}\isa{class\ eq\ where}\footnote{syntax here is a kind of isabellized Haskell} \\
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    67
  \hspace*{4ex}\isa{eq\ {\isasymColon}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ bool}
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    68
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    69
  \medskip\noindent\hspace*{2ex}\isa{instance\ nat\ {\isasymColon}\ eq\ where} \\
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    70
  \hspace*{4ex}\isa{eq\ {\isadigit{0}}\ {\isadigit{0}}\ {\isacharequal}\ True} \\
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    71
  \hspace*{4ex}\isa{eq\ {\isadigit{0}}\ {\isacharunderscore}\ {\isacharequal}\ False} \\
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    72
  \hspace*{4ex}\isa{eq\ {\isacharunderscore}\ {\isadigit{0}}\ {\isacharequal}\ False} \\
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    73
  \hspace*{4ex}\isa{eq\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isacharparenleft}Suc\ m{\isacharparenright}\ {\isacharequal}\ eq\ n\ m}
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    74
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    75
  \medskip\noindent\hspace*{2ex}\isa{instance\ {\isacharparenleft}{\isasymalpha}{\isasymColon}eq{\isacharcomma}\ {\isasymbeta}{\isasymColon}eq{\isacharparenright}\ pair\ {\isasymColon}\ eq\ where} \\
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
    76
  \hspace*{4ex}\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
    77
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    78
  \medskip\noindent\hspace*{2ex}\isa{class\ ord\ extends\ eq\ where} \\
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    79
  \hspace*{4ex}\isa{less{\isacharunderscore}eq\ {\isasymColon}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ bool} \\
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    80
  \hspace*{4ex}\isa{less\ {\isasymColon}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ bool}
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    81
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
    82
  \medskip\noindent Type variables are annotated with (finitly many) classes;
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    83
  these annotations are assertions that a particular polymorphic type
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    84
  provides definitions for overloaded functions.
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    85
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    86
  Indeed, type classes not only allow for simple overloading
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    87
  but form a generic calculus, an instance of order-sorted
23956
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
    88
  algebra \cite{Nipkow-Prehofer:1993,nipkow-sorts93,Wenzel:1997:TPHOL}.
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
    89
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    90
  From a software enigineering point of view, type classes
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    91
  correspond to interfaces in object-oriented languages like Java;
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    92
  so, it is naturally desirable that type classes do not only
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    93
  provide functions (class operations) but also state specifications
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    94
  implementations must obey.  For example, the \isa{class\ eq}
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
    95
  above could be given the following specification, demanding that
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
    96
  \isa{class\ eq} is an equivalence relation obeying reflexivity,
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
    97
  symmetry and transitivity:
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    98
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
    99
  \medskip\noindent\hspace*{2ex}\isa{class\ eq\ where} \\
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   100
  \hspace*{4ex}\isa{eq\ {\isasymColon}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ bool} \\
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   101
  \hspace*{2ex}\isa{satisfying} \\
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   102
  \hspace*{4ex}\isa{refl{\isacharcolon}\ eq\ x\ x} \\
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   103
  \hspace*{4ex}\isa{sym{\isacharcolon}\ eq\ x\ y\ {\isasymlongleftrightarrow}\ eq\ x\ y} \\
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   104
  \hspace*{4ex}\isa{trans{\isacharcolon}\ eq\ x\ y\ {\isasymand}\ eq\ y\ z\ {\isasymlongrightarrow}\ eq\ x\ z}
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   105
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   106
  \medskip\noindent From a theoretic point of view, type classes are leightweight
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   107
  modules; Haskell type classes may be emulated by
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   108
  SML functors \cite{classes_modules}. 
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   109
  Isabelle/Isar offers a discipline of type classes which brings
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   110
  all those aspects together:
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   111
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   112
  \begin{enumerate}
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   113
    \item specifying abstract operations togehter with
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   114
       corresponding specifications,
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   115
    \item instantating those abstract operations by a particular
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   116
       type
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   117
    \item in connection with a ``less ad-hoc'' approach to overloading,
23956
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   118
    \item with a direct link to the Isabelle module system
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   119
      (aka locales \cite{kammueller-locales}).
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   120
  \end{enumerate}
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   121
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   122
  \noindent Isar type classes also directly support code generation
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   123
  in a Haskell like fashion.
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   124
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   125
  This tutorial demonstrates common elements of structured specifications
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   126
  and abstract reasoning with type classes by the algebraic hierarchy of
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   127
  semigroups, monoids and groups.  Our background theory is that of
23956
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   128
  Isabelle/HOL \cite{isa-tutorial}, for which some
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   129
  familiarity is assumed.
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   130
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   131
  Here we merely present the look-and-feel for end users.
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   132
  Internally, those are mapped to more primitive Isabelle concepts.
23956
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   133
  See \cite{Haftmann-Wenzel:2006:classes} for more detail.%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   134
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   135
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   136
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   137
\isamarkupsection{A simple algebra example \label{sec:example}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   138
}
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   139
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   140
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   141
\isamarkupsubsection{Class definition%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   142
}
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   143
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   144
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   145
\begin{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   146
Depending on an arbitrary type \isa{{\isasymalpha}}, class \isa{semigroup} introduces a binary operation \isa{{\isasymcirc}} that is
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   147
  assumed to be associative:%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   148
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   149
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   150
\ \ \ \ \isacommand{class}\isamarkupfalse%
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   151
\ semigroup\ {\isacharequal}\ type\ {\isacharplus}\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   152
\ \ \ \ \ \ \isakeyword{fixes}\ mult\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequoteopen}\isactrlloc {\isasymotimes}{\isachardoublequoteclose}\ {\isadigit{7}}{\isadigit{0}}{\isacharparenright}\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   153
\ \ \ \ \ \ \isakeyword{assumes}\ assoc{\isacharcolon}\ {\isachardoublequoteopen}{\isacharparenleft}x\ \isactrlloc {\isasymotimes}\ y{\isacharparenright}\ \isactrlloc {\isasymotimes}\ z\ {\isacharequal}\ x\ \isactrlloc {\isasymotimes}\ {\isacharparenleft}y\ \isactrlloc {\isasymotimes}\ z{\isacharparenright}{\isachardoublequoteclose}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   154
\begin{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   155
\noindent This \isa{{\isasymCLASS}} specification consists of two
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   156
  parts: the \qn{operational} part names the class operation (\isa{{\isasymFIXES}}), the \qn{logical} part specifies properties on them
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   157
  (\isa{{\isasymASSUMES}}).  The local \isa{{\isasymFIXES}} and \isa{{\isasymASSUMES}} are lifted to the theory toplevel, yielding the global
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   158
  operation \isa{{\isachardoublequote}mult\ {\isasymColon}\ {\isasymalpha}{\isasymColon}semigroup\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequote}} and the
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   159
  global theorem \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
   160
\end{isamarkuptext}%
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
\isamarkupsubsection{Class instantiation \label{sec:class_inst}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   164
}
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   165
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   166
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   167
\begin{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   168
The concrete type \isa{int} is made a \isa{semigroup}
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   169
  instance by providing a suitable definition for the class operation
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   170
  \isa{mult} and a proof for the specification of \isa{assoc}.%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   171
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   172
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   173
\ \ \ \ \isacommand{instance}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   174
\ int\ {\isacharcolon}{\isacharcolon}\ semigroup\isanewline
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   175
\ \ \ \ \ \ mult{\isacharunderscore}int{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}{\isasymAnd}i\ j\ {\isasymColon}\ int{\isachardot}\ i\ {\isasymotimes}\ j\ {\isasymequiv}\ i\ {\isacharplus}\ j{\isachardoublequoteclose}\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   176
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   177
\isadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   178
\ \ \ \ %
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   179
\endisadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   180
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   181
\isatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   182
\isacommand{proof}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   183
\isanewline
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   184
\ \ \ \ \ \ \isacommand{fix}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   185
\ i\ j\ k\ {\isacharcolon}{\isacharcolon}\ int\ \isacommand{have}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   186
\ {\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
   187
\ simp\isanewline
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   188
\ \ \ \ \ \ \isacommand{then}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   189
\ \isacommand{show}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   190
\ {\isachardoublequoteopen}{\isacharparenleft}i\ {\isasymotimes}\ j{\isacharparenright}\ {\isasymotimes}\ k\ {\isacharequal}\ i\ {\isasymotimes}\ {\isacharparenleft}j\ {\isasymotimes}\ k{\isacharparenright}{\isachardoublequoteclose}\ \isacommand{unfolding}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   191
\ mult{\isacharunderscore}int{\isacharunderscore}def\ \isacommand{{\isachardot}}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   192
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   193
\ \ \ \ \isacommand{qed}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   194
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   195
\endisatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   196
{\isafoldproof}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   197
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   198
\isadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   199
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   200
\endisadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   201
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   202
\begin{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   203
\noindent From now on, the type-checker will consider \isa{int}
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   204
  as a \isa{semigroup} automatically, i.e.\ any general results
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   205
  are immediately available on concrete instances.
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   206
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   207
  Note that the first proof step is the \isa{default} method,
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   208
  which for instantiation proofs maps to the \isa{intro{\isacharunderscore}classes} method.
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   209
  This boils down an instantiation judgement to the relevant primitive
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   210
  proof goals and should conveniently always be the first method applied
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   211
  in an instantiation proof.
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   212
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   213
  \medskip Another instance of \isa{semigroup} are the natural numbers:%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   214
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   215
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   216
\ \ \ \ \isacommand{instance}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   217
\ nat\ {\isacharcolon}{\isacharcolon}\ semigroup\isanewline
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   218
\ \ \ \ \ \ mult{\isacharunderscore}nat{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}m\ {\isasymotimes}\ n\ {\isasymequiv}\ m\ {\isacharplus}\ n{\isachardoublequoteclose}\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   219
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   220
\isadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   221
\ \ \ \ %
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   222
\endisadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   223
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   224
\isatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   225
\isacommand{proof}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   226
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   227
\ \ \ \ \ \ \isacommand{fix}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   228
\ m\ n\ q\ {\isacharcolon}{\isacharcolon}\ nat\ \isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   229
\ \ \ \ \ \ \isacommand{show}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   230
\ {\isachardoublequoteopen}m\ {\isasymotimes}\ n\ {\isasymotimes}\ q\ {\isacharequal}\ m\ {\isasymotimes}\ {\isacharparenleft}n\ {\isasymotimes}\ q{\isacharparenright}{\isachardoublequoteclose}\ \isacommand{unfolding}\isamarkupfalse%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   231
\ mult{\isacharunderscore}nat{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   232
\ simp\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   233
\ \ \ \ \isacommand{qed}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   234
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   235
\endisatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   236
{\isafoldproof}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   237
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   238
\isadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   239
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   240
\endisadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   241
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   242
\begin{isamarkuptext}%
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   243
\noindent Also \isa{list}s form a semigroup with \isa{op\ {\isacharat}} as
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   244
  operation:%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   245
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   246
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   247
\ \ \ \ \isacommand{instance}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   248
\ list\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}type{\isacharparenright}\ semigroup\isanewline
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   249
\ \ \ \ \ \ mult{\isacharunderscore}list{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}xs\ {\isasymotimes}\ ys\ {\isasymequiv}\ xs\ {\isacharat}\ ys{\isachardoublequoteclose}\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   250
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   251
\isadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   252
\ \ \ \ %
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   253
\endisadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   254
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   255
\isatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   256
\isacommand{proof}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   257
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   258
\ \ \ \ \ \ \isacommand{fix}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   259
\ xs\ ys\ zs\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}\ list{\isachardoublequoteclose}\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   260
\ \ \ \ \ \ \isacommand{show}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   261
\ {\isachardoublequoteopen}xs\ {\isasymotimes}\ ys\ {\isasymotimes}\ zs\ {\isacharequal}\ xs\ {\isasymotimes}\ {\isacharparenleft}ys\ {\isasymotimes}\ zs{\isacharparenright}{\isachardoublequoteclose}\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   262
\ \ \ \ \ \ \isacommand{proof}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   263
\ {\isacharminus}\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   264
\ \ \ \ \ \ \ \ \isacommand{from}\isamarkupfalse%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   265
\ mult{\isacharunderscore}list{\isacharunderscore}def\ \isacommand{have}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   266
\ {\isachardoublequoteopen}{\isasymAnd}xs\ ys{\isasymColon}{\isasymalpha}\ list{\isachardot}\ xs\ {\isasymotimes}\ ys\ {\isasymequiv}\ xs\ {\isacharat}\ ys{\isachardoublequoteclose}\ \isacommand{{\isachardot}}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   267
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   268
\ \ \ \ \ \ \ \ \isacommand{thus}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   269
\ {\isacharquery}thesis\ \isacommand{by}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   270
\ simp\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   271
\ \ \ \ \ \ \isacommand{qed}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   272
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   273
\ \ \ \ \isacommand{qed}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   274
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   275
\endisatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   276
{\isafoldproof}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   277
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   278
\isadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   279
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   280
\endisadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   281
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   282
\isamarkupsubsection{Subclasses%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   283
}
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   284
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   285
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   286
\begin{isamarkuptext}%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   287
We define a subclass \isa{monoidl} (a semigroup with a left-hand neutral)
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   288
  by extending \isa{semigroup}
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   289
  with one additional operation \isa{neutral} together
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   290
  with its property:%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   291
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   292
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   293
\ \ \ \ \isacommand{class}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   294
\ monoidl\ {\isacharequal}\ semigroup\ {\isacharplus}\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   295
\ \ \ \ \ \ \isakeyword{fixes}\ neutral\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}{\isachardoublequoteclose}\ {\isacharparenleft}{\isachardoublequoteopen}\isactrlloc {\isasymone}{\isachardoublequoteclose}{\isacharparenright}\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   296
\ \ \ \ \ \ \isakeyword{assumes}\ neutl{\isacharcolon}\ {\isachardoublequoteopen}\isactrlloc {\isasymone}\ \isactrlloc {\isasymotimes}\ x\ {\isacharequal}\ x{\isachardoublequoteclose}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   297
\begin{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   298
\noindent Again, we make some instances, by
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   299
  providing suitable operation definitions and proofs for the
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   300
  additional specifications.%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   301
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   302
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   303
\ \ \ \ \isacommand{instance}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   304
\ nat\ {\isacharcolon}{\isacharcolon}\ monoidl\isanewline
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   305
\ \ \ \ \ \ neutral{\isacharunderscore}nat{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}{\isasymone}\ {\isasymequiv}\ {\isadigit{0}}{\isachardoublequoteclose}\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   306
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   307
\isadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   308
\ \ \ \ %
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   309
\endisadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   310
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   311
\isatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   312
\isacommand{proof}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   313
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   314
\ \ \ \ \ \ \isacommand{fix}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   315
\ n\ {\isacharcolon}{\isacharcolon}\ nat\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   316
\ \ \ \ \ \ \isacommand{show}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   317
\ {\isachardoublequoteopen}{\isasymone}\ {\isasymotimes}\ n\ {\isacharequal}\ n{\isachardoublequoteclose}\ \isacommand{unfolding}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   318
\ neutral{\isacharunderscore}nat{\isacharunderscore}def\ mult{\isacharunderscore}nat{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   319
\ simp\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   320
\ \ \ \ \isacommand{qed}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   321
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   322
\endisatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   323
{\isafoldproof}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   324
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   325
\isadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   326
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   327
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   328
\endisadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   329
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   330
\ \ \ \ \isacommand{instance}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   331
\ int\ {\isacharcolon}{\isacharcolon}\ monoidl\isanewline
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   332
\ \ \ \ \ \ neutral{\isacharunderscore}int{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}{\isasymone}\ {\isasymequiv}\ {\isadigit{0}}{\isachardoublequoteclose}\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   333
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   334
\isadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   335
\ \ \ \ %
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   336
\endisadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   337
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   338
\isatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   339
\isacommand{proof}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   340
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   341
\ \ \ \ \ \ \isacommand{fix}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   342
\ k\ {\isacharcolon}{\isacharcolon}\ int\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   343
\ \ \ \ \ \ \isacommand{show}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   344
\ {\isachardoublequoteopen}{\isasymone}\ {\isasymotimes}\ k\ {\isacharequal}\ k{\isachardoublequoteclose}\ \isacommand{unfolding}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   345
\ neutral{\isacharunderscore}int{\isacharunderscore}def\ mult{\isacharunderscore}int{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   346
\ simp\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   347
\ \ \ \ \isacommand{qed}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   348
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   349
\endisatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   350
{\isafoldproof}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   351
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   352
\isadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   353
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   354
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   355
\endisadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   356
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   357
\ \ \ \ \isacommand{instance}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   358
\ list\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}type{\isacharparenright}\ monoidl\isanewline
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   359
\ \ \ \ \ \ neutral{\isacharunderscore}list{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}{\isasymone}\ {\isasymequiv}\ {\isacharbrackleft}{\isacharbrackright}{\isachardoublequoteclose}\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   360
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   361
\isadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   362
\ \ \ \ %
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   363
\endisadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   364
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   365
\isatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   366
\isacommand{proof}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   367
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   368
\ \ \ \ \ \ \isacommand{fix}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   369
\ xs\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}\ list{\isachardoublequoteclose}\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   370
\ \ \ \ \ \ \isacommand{show}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   371
\ {\isachardoublequoteopen}{\isasymone}\ {\isasymotimes}\ xs\ {\isacharequal}\ xs{\isachardoublequoteclose}\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   372
\ \ \ \ \ \ \isacommand{proof}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   373
\ {\isacharminus}\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   374
\ \ \ \ \ \ \ \ \isacommand{from}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   375
\ mult{\isacharunderscore}list{\isacharunderscore}def\ \isacommand{have}\isamarkupfalse%
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   376
\ {\isachardoublequoteopen}{\isasymAnd}xs\ ys{\isasymColon}{\isasymalpha}\ list{\isachardot}\ xs\ {\isasymotimes}\ ys\ {\isasymequiv}\ xs\ {\isacharat}\ ys{\isachardoublequoteclose}\ \isacommand{{\isachardot}}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   377
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   378
\ \ \ \ \ \ \ \ \isacommand{moreover}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   379
\ \isacommand{from}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   380
\ mult{\isacharunderscore}list{\isacharunderscore}def\ neutral{\isacharunderscore}list{\isacharunderscore}def\ \isacommand{have}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   381
\ {\isachardoublequoteopen}{\isasymone}\ {\isasymequiv}\ {\isacharbrackleft}{\isacharbrackright}{\isasymColon}{\isasymalpha}\ list{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   382
\ simp\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   383
\ \ \ \ \ \ \ \ \isacommand{ultimately}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   384
\ \isacommand{show}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   385
\ {\isacharquery}thesis\ \isacommand{by}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   386
\ simp\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   387
\ \ \ \ \ \ \isacommand{qed}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   388
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   389
\ \ \ \ \isacommand{qed}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   390
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   391
\endisatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   392
{\isafoldproof}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   393
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   394
\isadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   395
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   396
\endisadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   397
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   398
\begin{isamarkuptext}%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   399
\noindent Fully-fledged monoids are modelled by another subclass
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   400
  which does not add new operations but tightens the specification:%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   401
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   402
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   403
\ \ \ \ \isacommand{class}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   404
\ monoid\ {\isacharequal}\ monoidl\ {\isacharplus}\isanewline
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   405
\ \ \ \ \ \ \isakeyword{assumes}\ neutr{\isacharcolon}\ {\isachardoublequoteopen}x\ \isactrlloc {\isasymotimes}\ \isactrlloc {\isasymone}\ {\isacharequal}\ x{\isachardoublequoteclose}%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   406
\begin{isamarkuptext}%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   407
\noindent Instantiations may also be given simultaneously for different
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   408
  type constructors:%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   409
\end{isamarkuptext}%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   410
\isamarkuptrue%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   411
\ \ \ \ \isacommand{instance}\isamarkupfalse%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   412
\ nat\ {\isacharcolon}{\isacharcolon}\ monoid\ \isakeyword{and}\ int\ {\isacharcolon}{\isacharcolon}\ monoid\ \isakeyword{and}\ list\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}type{\isacharparenright}\ monoid\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   413
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   414
\isadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   415
\ \ \ \ %
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   416
\endisadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   417
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   418
\isatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   419
\isacommand{proof}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   420
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   421
\ \ \ \ \ \ \isacommand{fix}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   422
\ n\ {\isacharcolon}{\isacharcolon}\ nat\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   423
\ \ \ \ \ \ \isacommand{show}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   424
\ {\isachardoublequoteopen}n\ {\isasymotimes}\ {\isasymone}\ {\isacharequal}\ n{\isachardoublequoteclose}\ \isacommand{unfolding}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   425
\ neutral{\isacharunderscore}nat{\isacharunderscore}def\ mult{\isacharunderscore}nat{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   426
\ simp\isanewline
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   427
\ \ \ \ \isacommand{next}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   428
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   429
\ \ \ \ \ \ \isacommand{fix}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   430
\ k\ {\isacharcolon}{\isacharcolon}\ int\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   431
\ \ \ \ \ \ \isacommand{show}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   432
\ {\isachardoublequoteopen}k\ {\isasymotimes}\ {\isasymone}\ {\isacharequal}\ k{\isachardoublequoteclose}\ \isacommand{unfolding}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   433
\ neutral{\isacharunderscore}int{\isacharunderscore}def\ mult{\isacharunderscore}int{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   434
\ simp\isanewline
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   435
\ \ \ \ \isacommand{next}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   436
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   437
\ \ \ \ \ \ \isacommand{fix}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   438
\ xs\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}\ list{\isachardoublequoteclose}\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   439
\ \ \ \ \ \ \isacommand{show}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   440
\ {\isachardoublequoteopen}xs\ {\isasymotimes}\ {\isasymone}\ {\isacharequal}\ xs{\isachardoublequoteclose}\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   441
\ \ \ \ \ \ \isacommand{proof}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   442
\ {\isacharminus}\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   443
\ \ \ \ \ \ \ \ \isacommand{from}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   444
\ mult{\isacharunderscore}list{\isacharunderscore}def\ \isacommand{have}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   445
\ {\isachardoublequoteopen}{\isasymAnd}xs\ ys{\isasymColon}{\isasymalpha}\ list{\isachardot}\ xs\ {\isasymotimes}\ ys\ {\isasymequiv}\ xs\ {\isacharat}\ ys{\isachardoublequoteclose}\ \isacommand{{\isachardot}}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   446
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   447
\ \ \ \ \ \ \ \ \isacommand{moreover}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   448
\ \isacommand{from}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   449
\ mult{\isacharunderscore}list{\isacharunderscore}def\ neutral{\isacharunderscore}list{\isacharunderscore}def\ \isacommand{have}\isamarkupfalse%
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   450
\ {\isachardoublequoteopen}{\isasymone}\ {\isasymequiv}\ {\isacharbrackleft}{\isacharbrackright}{\isasymColon}{\isasymalpha}\ list{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   451
\ simp\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   452
\ \ \ \ \ \ \ \ \isacommand{ultimately}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   453
\ \isacommand{show}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   454
\ {\isacharquery}thesis\ \isacommand{by}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   455
\ simp\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   456
\ \ \ \ \ \ \isacommand{qed}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   457
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   458
\ \ \ \ \isacommand{qed}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   459
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   460
\endisatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   461
{\isafoldproof}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   462
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   463
\isadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   464
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   465
\endisadelimproof
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   466
%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   467
\begin{isamarkuptext}%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   468
\noindent To finish our small algebra example, we add a \isa{group} class
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   469
  with a corresponding instance:%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   470
\end{isamarkuptext}%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   471
\isamarkuptrue%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   472
\ \ \ \ \isacommand{class}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   473
\ group\ {\isacharequal}\ monoidl\ {\isacharplus}\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   474
\ \ \ \ \ \ \isakeyword{fixes}\ inverse\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}\ \ \ \ {\isacharparenleft}{\isachardoublequoteopen}{\isacharparenleft}{\isacharunderscore}\isactrlloc {\isasymdiv}{\isacharparenright}{\isachardoublequoteclose}\ {\isacharbrackleft}{\isadigit{1}}{\isadigit{0}}{\isadigit{0}}{\isadigit{0}}{\isacharbrackright}\ {\isadigit{9}}{\isadigit{9}}{\isadigit{9}}{\isacharparenright}\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   475
\ \ \ \ \ \ \isakeyword{assumes}\ invl{\isacharcolon}\ {\isachardoublequoteopen}x\isactrlloc {\isasymdiv}\ \isactrlloc {\isasymotimes}\ x\ {\isacharequal}\ \isactrlloc {\isasymone}{\isachardoublequoteclose}\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   476
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   477
\ \ \ \ \isacommand{instance}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   478
\ int\ {\isacharcolon}{\isacharcolon}\ group\isanewline
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   479
\ \ \ \ \ \ inverse{\isacharunderscore}int{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}i{\isasymdiv}\ {\isasymequiv}\ {\isacharminus}\ i{\isachardoublequoteclose}\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   480
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   481
\isadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   482
\ \ \ \ %
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   483
\endisadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   484
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   485
\isatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   486
\isacommand{proof}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   487
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   488
\ \ \ \ \ \ \isacommand{fix}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   489
\ i\ {\isacharcolon}{\isacharcolon}\ int\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   490
\ \ \ \ \ \ \isacommand{have}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   491
\ {\isachardoublequoteopen}{\isacharminus}i\ {\isacharplus}\ i\ {\isacharequal}\ {\isadigit{0}}{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   492
\ simp\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   493
\ \ \ \ \ \ \isacommand{then}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   494
\ \isacommand{show}\isamarkupfalse%
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   495
\ {\isachardoublequoteopen}i{\isasymdiv}\ {\isasymotimes}\ i\ {\isacharequal}\ {\isasymone}{\isachardoublequoteclose}\isanewline
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   496
\ \ \ \ \ \ \isacommand{unfolding}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   497
\ mult{\isacharunderscore}int{\isacharunderscore}def\ \isakeyword{and}\ neutral{\isacharunderscore}int{\isacharunderscore}def\ \isakeyword{and}\ inverse{\isacharunderscore}int{\isacharunderscore}def\ \isacommand{{\isachardot}}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   498
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   499
\ \ \ \ \isacommand{qed}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   500
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   501
\endisatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   502
{\isafoldproof}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   503
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   504
\isadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   505
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   506
\endisadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   507
%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   508
\isamarkupsection{Type classes as locales%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   509
}
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   510
\isamarkuptrue%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   511
%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   512
\isamarkupsubsection{A look behind the scene%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   513
}
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   514
\isamarkuptrue%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   515
%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   516
\begin{isamarkuptext}%
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   517
The example above gives an impression how Isar type classes work
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   518
  in practice.  As stated in the introduction, classes also provide
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   519
  a link to Isar's locale system.  Indeed, the logical core of a class
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   520
  is nothing else than a locale:%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   521
\end{isamarkuptext}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   522
\isamarkuptrue%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   523
\isacommand{class}\isamarkupfalse%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   524
\ idem\ {\isacharequal}\ type\ {\isacharplus}\isanewline
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   525
\ \ \isakeyword{fixes}\ f\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}\isanewline
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   526
\ \ \isakeyword{assumes}\ idem{\isacharcolon}\ {\isachardoublequoteopen}f\ {\isacharparenleft}f\ x{\isacharparenright}\ {\isacharequal}\ f\ x{\isachardoublequoteclose}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   527
\begin{isamarkuptext}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   528
\noindent essentially introduces the locale%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   529
\end{isamarkuptext}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   530
\isamarkuptrue%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   531
%
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   532
\isadelimML
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   533
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   534
\endisadelimML
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   535
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   536
\isatagML
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   537
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   538
\endisatagML
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   539
{\isafoldML}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   540
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   541
\isadelimML
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   542
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   543
\endisadelimML
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   544
\isacommand{locale}\isamarkupfalse%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   545
\ idem\ {\isacharequal}\isanewline
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   546
\ \ \isakeyword{fixes}\ f\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}\isanewline
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   547
\ \ \isakeyword{assumes}\ idem{\isacharcolon}\ {\isachardoublequoteopen}f\ {\isacharparenleft}f\ x{\isacharparenright}\ {\isacharequal}\ f\ x{\isachardoublequoteclose}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   548
\begin{isamarkuptext}%
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   549
\noindent together with corresponding constant(s):%
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   550
\end{isamarkuptext}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   551
\isamarkuptrue%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   552
\isacommand{consts}\isamarkupfalse%
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   553
\ f\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}%
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   554
\begin{isamarkuptext}%
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   555
\noindent The connection to the type system is done by means
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   556
  of a primitive axclass%
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   557
\end{isamarkuptext}%
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   558
\isamarkuptrue%
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   559
\isacommand{axclass}\isamarkupfalse%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   560
\ idem\ {\isacharless}\ type\isanewline
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   561
\ \ idem{\isacharcolon}\ {\isachardoublequoteopen}f\ {\isacharparenleft}f\ x{\isacharparenright}\ {\isacharequal}\ f\ x{\isachardoublequoteclose}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   562
\begin{isamarkuptext}%
22649
6cf96b9f7b9e updated;
wenzelm
parents: 22550
diff changeset
   563
\noindent together with a corresponding interpretation:%
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   564
\end{isamarkuptext}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   565
\isamarkuptrue%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   566
\isacommand{interpretation}\isamarkupfalse%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   567
\ idem{\isacharunderscore}class{\isacharcolon}\isanewline
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   568
\ \ idem\ {\isacharbrackleft}{\isachardoublequoteopen}f\ {\isasymColon}\ {\isacharparenleft}{\isacharprime}a{\isasymColon}idem{\isacharparenright}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}{\isacharbrackright}\isanewline
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   569
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   570
\isadelimproof
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   571
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   572
\endisadelimproof
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   573
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   574
\isatagproof
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   575
\isacommand{by}\isamarkupfalse%
22550
c5039bee2602 updated
haftmann
parents: 22479
diff changeset
   576
\ unfold{\isacharunderscore}locales\ {\isacharparenleft}rule\ idem{\isacharparenright}%
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   577
\endisatagproof
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   578
{\isafoldproof}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   579
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   580
\isadelimproof
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   581
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   582
\endisadelimproof
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   583
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   584
\isadelimML
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   585
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   586
\endisadelimML
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   587
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   588
\isatagML
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   589
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   590
\endisatagML
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   591
{\isafoldML}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   592
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   593
\isadelimML
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   594
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   595
\endisadelimML
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   596
%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   597
\begin{isamarkuptext}%
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   598
This give you at hand the full power of the Isabelle module system;
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   599
  conclusions in locale \isa{idem} are implicitly propagated
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   600
  to class \isa{idem}.%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   601
\end{isamarkuptext}%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   602
\isamarkuptrue%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   603
%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   604
\isamarkupsubsection{Abstract reasoning%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   605
}
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   606
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   607
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   608
\begin{isamarkuptext}%
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   609
Isabelle locales enable reasoning at a general level, while results
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   610
  are implicitly transferred to all instances.  For example, we can
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   611
  now establish the \isa{left{\isacharunderscore}cancel} lemma for groups, which
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   612
  states that the function \isa{{\isacharparenleft}x\ {\isasymcirc}{\isacharparenright}} is injective:%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   613
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   614
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   615
\ \ \ \ \isacommand{lemma}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   616
\ {\isacharparenleft}\isakeyword{in}\ group{\isacharparenright}\ left{\isacharunderscore}cancel{\isacharcolon}\ {\isachardoublequoteopen}x\ \isactrlloc {\isasymotimes}\ y\ {\isacharequal}\ x\ \isactrlloc {\isasymotimes}\ z\ {\isasymlongleftrightarrow}\ y\ {\isacharequal}\ z{\isachardoublequoteclose}\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   617
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   618
\isadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   619
\ \ \ \ %
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   620
\endisadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   621
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   622
\isatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   623
\isacommand{proof}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   624
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   625
\ \ \ \ \isacommand{assume}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   626
\ {\isachardoublequoteopen}x\ \isactrlloc {\isasymotimes}\ y\ {\isacharequal}\ x\ \isactrlloc {\isasymotimes}\ z{\isachardoublequoteclose}\isanewline
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   627
\ \ \ \ \ \ \isacommand{then}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   628
\ \isacommand{have}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   629
\ {\isachardoublequoteopen}x\isactrlloc {\isasymdiv}\ \isactrlloc {\isasymotimes}\ {\isacharparenleft}x\ \isactrlloc {\isasymotimes}\ y{\isacharparenright}\ {\isacharequal}\ x\isactrlloc {\isasymdiv}\ \isactrlloc {\isasymotimes}\ {\isacharparenleft}x\ \isactrlloc {\isasymotimes}\ z{\isacharparenright}{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   630
\ simp\isanewline
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   631
\ \ \ \ \ \ \isacommand{then}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   632
\ \isacommand{have}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   633
\ {\isachardoublequoteopen}{\isacharparenleft}x\isactrlloc {\isasymdiv}\ \isactrlloc {\isasymotimes}\ x{\isacharparenright}\ \isactrlloc {\isasymotimes}\ y\ {\isacharequal}\ {\isacharparenleft}x\isactrlloc {\isasymdiv}\ \isactrlloc {\isasymotimes}\ x{\isacharparenright}\ \isactrlloc {\isasymotimes}\ z{\isachardoublequoteclose}\ \isacommand{using}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   634
\ assoc\ \isacommand{by}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   635
\ simp\isanewline
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   636
\ \ \ \ \ \ \isacommand{then}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   637
\ \isacommand{show}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   638
\ {\isachardoublequoteopen}y\ {\isacharequal}\ z{\isachardoublequoteclose}\ \isacommand{using}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   639
\ neutl\ \isakeyword{and}\ invl\ \isacommand{by}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   640
\ simp\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   641
\ \ \ \ \isacommand{next}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   642
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   643
\ \ \ \ \isacommand{assume}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   644
\ {\isachardoublequoteopen}y\ {\isacharequal}\ z{\isachardoublequoteclose}\isanewline
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   645
\ \ \ \ \ \ \isacommand{then}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   646
\ \isacommand{show}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   647
\ {\isachardoublequoteopen}x\ \isactrlloc {\isasymotimes}\ y\ {\isacharequal}\ x\ \isactrlloc {\isasymotimes}\ z{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   648
\ simp\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   649
\ \ \ \ \isacommand{qed}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   650
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   651
\endisatagproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   652
{\isafoldproof}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   653
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   654
\isadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   655
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   656
\endisadelimproof
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   657
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   658
\begin{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   659
\noindent Here the \qt{\isa{{\isasymIN}\ group}} target specification
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   660
  indicates that the result is recorded within that context for later
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   661
  use.  This local theorem is also lifted to the global one \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
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   662
  \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
   663
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   664
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   665
%
23956
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   666
\isamarkupsubsection{Derived definitions%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   667
}
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   668
\isamarkuptrue%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   669
%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   670
\begin{isamarkuptext}%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   671
Isabelle locales support a concept of local definitions
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   672
  in locales:%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   673
\end{isamarkuptext}%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   674
\isamarkuptrue%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   675
\ \ \ \ \isacommand{fun}\isamarkupfalse%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   676
\ {\isacharparenleft}\isakeyword{in}\ monoid{\isacharparenright}\isanewline
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   677
\ \ \ \ \ \ pow{\isacharunderscore}nat\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   678
\ \ \ \ \ \ {\isachardoublequoteopen}pow{\isacharunderscore}nat\ {\isadigit{0}}\ x\ {\isacharequal}\ \isactrlloc {\isasymone}{\isachardoublequoteclose}\isanewline
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   679
\ \ \ \ \ \ {\isacharbar}\ {\isachardoublequoteopen}pow{\isacharunderscore}nat\ {\isacharparenleft}Suc\ n{\isacharparenright}\ x\ {\isacharequal}\ x\ \isactrlloc {\isasymotimes}\ pow{\isacharunderscore}nat\ n\ x{\isachardoublequoteclose}%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   680
\begin{isamarkuptext}%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   681
\noindent If the locale \isa{group} is also a class, this local
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   682
  definition is propagated onto a global definition of
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   683
  \isa{{\isachardoublequote}pow{\isacharunderscore}nat\ {\isasymColon}\ nat\ {\isasymRightarrow}\ {\isasymalpha}{\isasymColon}monoid\ {\isasymRightarrow}\ {\isasymalpha}{\isasymColon}monoid{\isachardoublequote}}
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   684
  with corresponding theorems
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   685
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   686
  \isa{pow{\isacharunderscore}nat\ {\isadigit{0}}\ x\ {\isacharequal}\ {\isasymone}\isasep\isanewline%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   687
pow{\isacharunderscore}nat\ {\isacharparenleft}Suc\ n{\isacharparenright}\ x\ {\isacharequal}\ x\ {\isasymotimes}\ pow{\isacharunderscore}nat\ n\ x}.
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   688
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   689
  \noindent As you can see from this example, for local
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   690
  definitions you may use any specification tool
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   691
  which works together with locales (e.g. \cite{krauss2006}).%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   692
\end{isamarkuptext}%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   693
\isamarkuptrue%
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   694
%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   695
\isamarkupsection{Further issues%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   696
}
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   697
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   698
%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   699
\isamarkupsubsection{Code generation%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   700
}
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   701
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   702
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   703
\begin{isamarkuptext}%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   704
Turning back to the first motivation for type classes,
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   705
  namely overloading, it is obvious that overloading
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   706
  stemming from \isa{{\isasymCLASS}} and \isa{{\isasymINSTANCE}}
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   707
  statements naturally maps to Haskell type classes.
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   708
  The code generator framework \cite{isabelle-codegen} 
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   709
  takes this into account.  Concerning target languages
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   710
  lacking type classes (e.g.~SML), type classes
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   711
  are implemented by explicit dictionary construction.
23956
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   712
  For example, lets go back to the power function:%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   713
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   714
\isamarkuptrue%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   715
\ \ \ \ \isacommand{fun}\isamarkupfalse%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   716
\isanewline
23956
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   717
\ \ \ \ \ \ pow{\isacharunderscore}nat\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ {\isasymalpha}{\isasymColon}group\ {\isasymRightarrow}\ {\isasymalpha}{\isasymColon}group{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   718
\ \ \ \ \ \ {\isachardoublequoteopen}pow{\isacharunderscore}nat\ {\isadigit{0}}\ x\ {\isacharequal}\ {\isasymone}{\isachardoublequoteclose}\isanewline
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   719
\ \ \ \ \ \ {\isacharbar}\ {\isachardoublequoteopen}pow{\isacharunderscore}nat\ {\isacharparenleft}Suc\ n{\isacharparenright}\ x\ {\isacharequal}\ x\ {\isasymotimes}\ pow{\isacharunderscore}nat\ n\ x{\isachardoublequoteclose}\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   720
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   721
\ \ \ \ \isacommand{definition}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   722
\isanewline
22479
de15ea8fb348 updated code generation sections
haftmann
parents: 22317
diff changeset
   723
\ \ \ \ \ \ pow{\isacharunderscore}int\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}int\ {\isasymRightarrow}\ {\isasymalpha}{\isasymColon}group\ {\isasymRightarrow}\ {\isasymalpha}{\isasymColon}group{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   724
\ \ \ \ \ \ {\isachardoublequoteopen}pow{\isacharunderscore}int\ k\ x\ {\isacharequal}\ {\isacharparenleft}if\ k\ {\isachargreater}{\isacharequal}\ {\isadigit{0}}\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   725
\ \ \ \ \ \ \ \ then\ pow{\isacharunderscore}nat\ {\isacharparenleft}nat\ k{\isacharparenright}\ x\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   726
\ \ \ \ \ \ \ \ else\ {\isacharparenleft}pow{\isacharunderscore}nat\ {\isacharparenleft}nat\ {\isacharparenleft}{\isacharminus}\ k{\isacharparenright}{\isacharparenright}\ x{\isacharparenright}{\isasymdiv}{\isacharparenright}{\isachardoublequoteclose}\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   727
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   728
\ \ \ \ \isacommand{definition}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   729
\isanewline
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   730
\ \ \ \ \ \ example\ {\isacharcolon}{\isacharcolon}\ int\ \isakeyword{where}\isanewline
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   731
\ \ \ \ \ \ {\isachardoublequoteopen}example\ {\isacharequal}\ pow{\isacharunderscore}int\ {\isadigit{1}}{\isadigit{0}}\ {\isacharparenleft}{\isacharminus}{\isadigit{2}}{\isacharparenright}{\isachardoublequoteclose}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   732
\begin{isamarkuptext}%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   733
\noindent This maps to Haskell as:%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   734
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   735
\isamarkuptrue%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   736
\isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
23956
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   737
\ example\ \isakeyword{in}\ Haskell\ \isakeyword{to}\ Classes\ \isakeyword{file}\ {\isachardoublequoteopen}code{\isacharunderscore}examples{\isacharslash}{\isachardoublequoteclose}%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   738
\begin{isamarkuptext}%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   739
\lsthaskell{Thy/code_examples/Classes.hs}
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   740
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   741
  \noindent The whole code in SML with explicit dictionary passing:%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   742
\end{isamarkuptext}%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   743
\isamarkuptrue%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   744
\isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
23956
48494ccfabaf updated
haftmann
parents: 23015
diff changeset
   745
\ example\ \isakeyword{in}\ SML\ \isakeyword{to}\ Classes\ \isakeyword{file}\ {\isachardoublequoteopen}code{\isacharunderscore}examples{\isacharslash}classes{\isachardot}ML{\isachardoublequoteclose}%
22317
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   746
\begin{isamarkuptext}%
b550d2c6ca90 continued class tutorial
haftmann
parents: 20967
diff changeset
   747
\lstsml{Thy/code_examples/classes.ML}%
20967
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   748
\end{isamarkuptext}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   749
\isamarkuptrue%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   750
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   751
\isadelimtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   752
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   753
\endisadelimtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   754
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   755
\isatagtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   756
\isacommand{end}\isamarkupfalse%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   757
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   758
\endisatagtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   759
{\isafoldtheory}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   760
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   761
\isadelimtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   762
%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   763
\endisadelimtheory
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   764
\isanewline
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   765
\end{isabellebody}%
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   766
%%% Local Variables:
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   767
%%% mode: latex
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   768
%%% TeX-master: "root"
1df105407f87 added tex files to CVS
haftmann
parents:
diff changeset
   769
%%% End: