10305
|
1 |
%
|
|
2 |
\begin{isabellebody}%
|
|
3 |
\def\isabellecontext{Overloading{\isadigit{0}}}%
|
11866
|
4 |
\isamarkupfalse%
|
10305
|
5 |
%
|
10328
|
6 |
\begin{isamarkuptext}%
|
|
7 |
We start with a concept that is required for type classes but already
|
|
8 |
useful on its own: \emph{overloading}. Isabelle allows overloading: a
|
|
9 |
constant may have multiple definitions at non-overlapping types.%
|
|
10 |
\end{isamarkuptext}%
|
11866
|
11 |
\isamarkuptrue%
|
10328
|
12 |
%
|
10878
|
13 |
\isamarkupsubsubsection{An Initial Example%
|
10397
|
14 |
}
|
11866
|
15 |
\isamarkuptrue%
|
10305
|
16 |
%
|
|
17 |
\begin{isamarkuptext}%
|
10328
|
18 |
If we want to introduce the notion of an \emph{inverse} for arbitrary types we
|
10305
|
19 |
give it a polymorphic type%
|
|
20 |
\end{isamarkuptext}%
|
11866
|
21 |
\isamarkuptrue%
|
|
22 |
\isacommand{consts}\ inverse\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a{\isachardoublequote}\isamarkupfalse%
|
|
23 |
%
|
10305
|
24 |
\begin{isamarkuptext}%
|
|
25 |
\noindent
|
|
26 |
and provide different definitions at different instances:%
|
|
27 |
\end{isamarkuptext}%
|
11866
|
28 |
\isamarkuptrue%
|
10305
|
29 |
\isacommand{defs}\ {\isacharparenleft}\isakeyword{overloaded}{\isacharparenright}\isanewline
|
|
30 |
inverse{\isacharunderscore}bool{\isacharcolon}\ {\isachardoublequote}inverse{\isacharparenleft}b{\isacharcolon}{\isacharcolon}bool{\isacharparenright}\ {\isasymequiv}\ {\isasymnot}\ b{\isachardoublequote}\isanewline
|
|
31 |
inverse{\isacharunderscore}set{\isacharcolon}\ \ {\isachardoublequote}inverse{\isacharparenleft}A{\isacharcolon}{\isacharcolon}{\isacharprime}a\ set{\isacharparenright}\ {\isasymequiv}\ {\isacharminus}A{\isachardoublequote}\isanewline
|
11866
|
32 |
inverse{\isacharunderscore}pair{\isacharcolon}\ {\isachardoublequote}inverse{\isacharparenleft}p{\isacharparenright}\ {\isasymequiv}\ {\isacharparenleft}inverse{\isacharparenleft}fst\ p{\isacharparenright}{\isacharcomma}\ inverse{\isacharparenleft}snd\ p{\isacharparenright}{\isacharparenright}{\isachardoublequote}\isamarkupfalse%
|
|
33 |
%
|
10305
|
34 |
\begin{isamarkuptext}%
|
|
35 |
\noindent
|
|
36 |
Isabelle will not complain because the three definitions do not overlap: no
|
|
37 |
two of the three types \isa{bool}, \isa{{\isacharprime}a\ set} and \isa{{\isacharprime}a\ {\isasymtimes}\ {\isacharprime}b} have a
|
|
38 |
common instance. What is more, the recursion in \isa{inverse{\isacharunderscore}pair} is
|
10538
|
39 |
benign because the type of \isa{inverse} becomes smaller: on the
|
|
40 |
left it is \isa{{\isacharprime}a\ {\isasymtimes}\ {\isacharprime}b\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymtimes}\ {\isacharprime}b} but on the right \isa{{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a} and
|
11196
|
41 |
\isa{{\isacharprime}b\ {\isasymRightarrow}\ {\isacharprime}b}. The annotation \isa{{\isacharparenleft}}\isacommand{overloaded}\isa{{\isacharparenright}} tells Isabelle that
|
10538
|
42 |
the definitions do intentionally define \isa{inverse} only at
|
11310
|
43 |
instances of its declared type \isa{{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a} --- this merely suppresses
|
10538
|
44 |
warnings to that effect.
|
10305
|
45 |
|
|
46 |
However, there is nothing to prevent the user from forming terms such as
|
11494
|
47 |
\isa{inverse\ {\isacharbrackleft}{\isacharbrackright}} and proving theorems such as \isa{inverse\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharequal}\ inverse\ {\isacharbrackleft}{\isacharbrackright}} when inverse is not defined on lists. Proving theorems about
|
12332
|
48 |
unspecified constants does not endanger soundness, but it is pointless.
|
11494
|
49 |
To prevent such terms from even being formed requires the use of type classes.%
|
10305
|
50 |
\end{isamarkuptext}%
|
11866
|
51 |
\isamarkuptrue%
|
|
52 |
\isamarkupfalse%
|
10305
|
53 |
\end{isabellebody}%
|
|
54 |
%%% Local Variables:
|
|
55 |
%%% mode: latex
|
|
56 |
%%% TeX-master: "root"
|
|
57 |
%%% End:
|