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