author | Christian Urban <urbanc@in.tum.de> |
Mon, 26 Jan 2009 16:09:02 +0000 | |
changeset 81 | 8fda6b452f28 |
parent 78 | ef778679d3e0 |
child 82 | 6dfe6975bda0 |
permissions | -rw-r--r-- |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
1 |
theory FirstSteps |
25
e2f9f94b26d4
Antiquotation setup is now contained in theory Base.
berghofe
parents:
21
diff
changeset
|
2 |
imports Base |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
3 |
begin |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
4 |
|
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
5 |
chapter {* First Steps *} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
6 |
|
42
cd612b489504
tuned mostly antiquotation and text
Christian Urban <urbanc@in.tum.de>
parents:
41
diff
changeset
|
7 |
text {* |
cd612b489504
tuned mostly antiquotation and text
Christian Urban <urbanc@in.tum.de>
parents:
41
diff
changeset
|
8 |
|
54
1783211b3494
tuned; added document antiquotation ML_response_fake_both
Christian Urban <urbanc@in.tum.de>
parents:
52
diff
changeset
|
9 |
Isabelle programming is done in ML. Just like lemmas and proofs, ML-code |
50 | 10 |
in Isabelle is part of a theory. If you want to follow the code written in |
54
1783211b3494
tuned; added document antiquotation ML_response_fake_both
Christian Urban <urbanc@in.tum.de>
parents:
52
diff
changeset
|
11 |
this chapter, we assume you are working inside the theory starting with |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
12 |
|
6 | 13 |
\begin{center} |
5
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
14 |
\begin{tabular}{@ {}l} |
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
15 |
\isacommand{theory} FirstSteps\\ |
5
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
16 |
\isacommand{imports} Main\\ |
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
17 |
\isacommand{begin}\\ |
6 | 18 |
\ldots |
5
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
19 |
\end{tabular} |
6 | 20 |
\end{center} |
14
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
21 |
*} |
5
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
22 |
|
20 | 23 |
section {* Including ML-Code *} |
14
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
24 |
|
47
4daf913fdbe1
hakked latex so that it does not display ML {* *}; general tuning
Christian Urban <urbanc@in.tum.de>
parents:
43
diff
changeset
|
25 |
|
4daf913fdbe1
hakked latex so that it does not display ML {* *}; general tuning
Christian Urban <urbanc@in.tum.de>
parents:
43
diff
changeset
|
26 |
|
14
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
27 |
text {* |
5
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
28 |
The easiest and quickest way to include code in a theory is |
49 | 29 |
by using the \isacommand{ML}-command. For example\smallskip |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
30 |
|
75 | 31 |
\begin{isabelle} |
32 |
\begin{graybox} |
|
42
cd612b489504
tuned mostly antiquotation and text
Christian Urban <urbanc@in.tum.de>
parents:
41
diff
changeset
|
33 |
\isa{\isacommand{ML} |
cd612b489504
tuned mostly antiquotation and text
Christian Urban <urbanc@in.tum.de>
parents:
41
diff
changeset
|
34 |
\isacharverbatimopen\isanewline |
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
35 |
\hspace{5mm}@{ML "3 + 4"}\isanewline |
42
cd612b489504
tuned mostly antiquotation and text
Christian Urban <urbanc@in.tum.de>
parents:
41
diff
changeset
|
36 |
\isacharverbatimclose\isanewline |
58 | 37 |
@{text "> 7"}\smallskip} |
75 | 38 |
\end{graybox} |
39 |
\end{isabelle} |
|
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
40 |
|
75 | 41 |
Like ``normal'' Isabelle proof scripts, |
58 | 42 |
\isacommand{ML}-commands can be evaluated by using the advance and undo buttons of |
49 | 43 |
your Isabelle environment. The code inside the \isacommand{ML}-command |
47
4daf913fdbe1
hakked latex so that it does not display ML {* *}; general tuning
Christian Urban <urbanc@in.tum.de>
parents:
43
diff
changeset
|
44 |
can also contain value and function bindings, and even those can be |
75 | 45 |
undone when the proof script is retracted. As mentioned earlier, we will |
46 |
drop the \isacommand{ML} \isa{\isacharverbatimopen \ldots \isacharverbatimclose} |
|
78
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
47 |
whenever we show code. |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
48 |
|
14
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
49 |
Once a portion of code is relatively stable, one usually wants to |
15
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
50 |
export it to a separate ML-file. Such files can then be included in a |
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
51 |
theory by using \isacommand{uses} in the header of the theory, like |
14
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
52 |
|
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
53 |
\begin{center} |
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
54 |
\begin{tabular}{@ {}l} |
54
1783211b3494
tuned; added document antiquotation ML_response_fake_both
Christian Urban <urbanc@in.tum.de>
parents:
52
diff
changeset
|
55 |
\isacommand{theory} FirstSteps\\ |
14
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
56 |
\isacommand{imports} Main\\ |
58 | 57 |
\isacommand{uses} @{text "\"file_to_be_included.ML\""} @{text "\<dots>"}\\ |
14
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
58 |
\isacommand{begin}\\ |
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
59 |
\ldots |
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
60 |
\end{tabular} |
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
61 |
\end{center} |
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
62 |
|
14
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
63 |
*} |
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
64 |
|
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
65 |
section {* Debugging and Printing *} |
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
66 |
|
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
67 |
text {* |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
68 |
|
50 | 69 |
During development you might find it necessary to inspect some data |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
70 |
in your code. This can be done in a ``quick-and-dirty'' fashion using |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
71 |
the function @{ML "warning"}. For example |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
72 |
|
72
7b8c4fe235aa
added an antiquotation option [gray] for gray boxes around displays
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
73 |
@{ML_response_fake [display,gray] "warning \"any string\"" "\"any string\""} |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
74 |
|
58 | 75 |
will print out @{text [quotes] "any string"} inside the response buffer |
76 |
of Isabelle. This function expects a string as argument. If you develop under PolyML, |
|
50 | 77 |
then there is a convenient, though again ``quick-and-dirty'', method for |
75 | 78 |
converting values into strings, namely using the function @{ML makestring}: |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
79 |
|
72
7b8c4fe235aa
added an antiquotation option [gray] for gray boxes around displays
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
80 |
@{ML_response_fake [display,gray] "warning (makestring 1)" "\"1\""} |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
81 |
|
65
c8e9a4f97916
tuned and added a section about creating keyword files
Christian Urban <urbanc@in.tum.de>
parents:
60
diff
changeset
|
82 |
However @{ML makestring} only works if the type of what is converted is monomorphic |
78
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
83 |
and not a function. |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
84 |
|
52 | 85 |
The function @{ML "warning"} should only be used for testing purposes, because any |
86 |
output this function generates will be overwritten as soon as an error is |
|
50 | 87 |
raised. For printing anything more serious and elaborate, the |
54
1783211b3494
tuned; added document antiquotation ML_response_fake_both
Christian Urban <urbanc@in.tum.de>
parents:
52
diff
changeset
|
88 |
function @{ML tracing} is more appropriate. This function writes all output into |
49 | 89 |
a separate tracing buffer. For example |
14
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
90 |
|
72
7b8c4fe235aa
added an antiquotation option [gray] for gray boxes around displays
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
91 |
@{ML_response_fake [display,gray] "tracing \"foo\"" "\"foo\""} |
14
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
92 |
|
58 | 93 |
It is also possible to redirect the ``channel'' where the string @{text "foo"} is |
78
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
94 |
printed to a separate file, e.g.~to prevent ProofGeneral from choking on massive |
52 | 95 |
amounts of trace output. This redirection can be achieved using the code |
43
02f76f1b6e7b
added positions to anti-quotations; removed old antiquotation_setup; tuned the text a bit
Christian Urban <urbanc@in.tum.de>
parents:
42
diff
changeset
|
96 |
*} |
14
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
97 |
|
69
19106a9975c1
highligted the background of ML-code
Christian Urban <urbanc@in.tum.de>
parents:
68
diff
changeset
|
98 |
ML{*val strip_specials = |
42
cd612b489504
tuned mostly antiquotation and text
Christian Urban <urbanc@in.tum.de>
parents:
41
diff
changeset
|
99 |
let |
43
02f76f1b6e7b
added positions to anti-quotations; removed old antiquotation_setup; tuned the text a bit
Christian Urban <urbanc@in.tum.de>
parents:
42
diff
changeset
|
100 |
fun strip ("\^A" :: _ :: cs) = strip cs |
42
cd612b489504
tuned mostly antiquotation and text
Christian Urban <urbanc@in.tum.de>
parents:
41
diff
changeset
|
101 |
| strip (c :: cs) = c :: strip cs |
cd612b489504
tuned mostly antiquotation and text
Christian Urban <urbanc@in.tum.de>
parents:
41
diff
changeset
|
102 |
| strip [] = []; |
cd612b489504
tuned mostly antiquotation and text
Christian Urban <urbanc@in.tum.de>
parents:
41
diff
changeset
|
103 |
in implode o strip o explode end; |
cd612b489504
tuned mostly antiquotation and text
Christian Urban <urbanc@in.tum.de>
parents:
41
diff
changeset
|
104 |
|
cd612b489504
tuned mostly antiquotation and text
Christian Urban <urbanc@in.tum.de>
parents:
41
diff
changeset
|
105 |
fun redirect_tracing stream = |
cd612b489504
tuned mostly antiquotation and text
Christian Urban <urbanc@in.tum.de>
parents:
41
diff
changeset
|
106 |
Output.tracing_fn := (fn s => |
14
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
107 |
(TextIO.output (stream, (strip_specials s)); |
43
02f76f1b6e7b
added positions to anti-quotations; removed old antiquotation_setup; tuned the text a bit
Christian Urban <urbanc@in.tum.de>
parents:
42
diff
changeset
|
108 |
TextIO.output (stream, "\n"); |
69
19106a9975c1
highligted the background of ML-code
Christian Urban <urbanc@in.tum.de>
parents:
68
diff
changeset
|
109 |
TextIO.flushOut stream)) *} |
14
1c17e99f6f66
added a paragraph about "uses" and started a paragraph about tracing
Christian Urban <urbanc@in.tum.de>
parents:
13
diff
changeset
|
110 |
|
43
02f76f1b6e7b
added positions to anti-quotations; removed old antiquotation_setup; tuned the text a bit
Christian Urban <urbanc@in.tum.de>
parents:
42
diff
changeset
|
111 |
text {* |
02f76f1b6e7b
added positions to anti-quotations; removed old antiquotation_setup; tuned the text a bit
Christian Urban <urbanc@in.tum.de>
parents:
42
diff
changeset
|
112 |
Calling @{ML "redirect_tracing"} with @{ML "(TextIO.openOut \"foo.bar\")"} |
58 | 113 |
will cause that all tracing information is printed into the file @{text "foo.bar"}. |
75 | 114 |
|
81 | 115 |
Error messages can be printed using the function @{ML error}, as in |
75 | 116 |
|
117 |
@{ML_response_fake [display,gray] "if 0=1 then 1 else (error \"foo\")" "\"foo\""} |
|
118 |
||
15
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
119 |
*} |
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
120 |
|
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
121 |
|
75 | 122 |
|
123 |
||
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
124 |
section {* Antiquotations *} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
125 |
|
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
126 |
text {* |
49 | 127 |
The main advantage of embedding all code in a theory is that the code can |
58 | 128 |
contain references to entities defined on the logical level of Isabelle. By |
129 |
this we mean definitions, theorems, terms and so on. This kind of reference is |
|
130 |
realised with antiquotations. For example, one can print out the name of the current |
|
49 | 131 |
theory by typing |
132 |
||
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
133 |
|
72
7b8c4fe235aa
added an antiquotation option [gray] for gray boxes around displays
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
134 |
@{ML_response [display,gray] "Context.theory_name @{theory}" "\"FirstSteps\""} |
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
135 |
|
5
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
136 |
where @{text "@{theory}"} is an antiquotation that is substituted with the |
49 | 137 |
current theory (remember that we assumed we are inside the theory |
58 | 138 |
@{text FirstSteps}). The name of this theory can be extracted with |
49 | 139 |
the function @{ML "Context.theory_name"}. |
5
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
140 |
|
81 | 141 |
Note, however, that antiquotations are statically scoped, that is their value is |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
142 |
determined at ``compile-time'', not ``run-time''. For example the function |
43
02f76f1b6e7b
added positions to anti-quotations; removed old antiquotation_setup; tuned the text a bit
Christian Urban <urbanc@in.tum.de>
parents:
42
diff
changeset
|
143 |
*} |
5
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
144 |
|
69
19106a9975c1
highligted the background of ML-code
Christian Urban <urbanc@in.tum.de>
parents:
68
diff
changeset
|
145 |
ML{*fun not_current_thyname () = Context.theory_name @{theory} *} |
43
02f76f1b6e7b
added positions to anti-quotations; removed old antiquotation_setup; tuned the text a bit
Christian Urban <urbanc@in.tum.de>
parents:
42
diff
changeset
|
146 |
|
02f76f1b6e7b
added positions to anti-quotations; removed old antiquotation_setup; tuned the text a bit
Christian Urban <urbanc@in.tum.de>
parents:
42
diff
changeset
|
147 |
text {* |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
148 |
|
58 | 149 |
does, as its name suggest, \emph{not} return the name of the current theory, if it is run in a |
5
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
150 |
different theory. Instead, the code above defines the constant function |
58 | 151 |
that always returns the string @{text [quotes] "FirstSteps"}, no matter where the |
43
02f76f1b6e7b
added positions to anti-quotations; removed old antiquotation_setup; tuned the text a bit
Christian Urban <urbanc@in.tum.de>
parents:
42
diff
changeset
|
152 |
function is called. Operationally speaking, the antiquotation @{text "@{theory}"} is |
5
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
153 |
\emph{not} replaced with code that will look up the current theory in |
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
154 |
some data structure and return it. Instead, it is literally |
e91f54791e14
minor modifiations to the Intro and FirstSteps chapters
Christian Urban <urbanc@in.tum.de>
parents:
2
diff
changeset
|
155 |
replaced with the value representing the theory name. |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
156 |
|
81 | 157 |
In a similar way you can use antiquotations to refer to proved theorems: |
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
158 |
|
72
7b8c4fe235aa
added an antiquotation option [gray] for gray boxes around displays
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
159 |
@{ML_response_fake [display,gray] "@{thm allI}" "(\<And>x. ?P x) \<Longrightarrow> \<forall>x. ?P x"} |
75 | 160 |
|
161 |
or simpsets: |
|
162 |
||
72
7b8c4fe235aa
added an antiquotation option [gray] for gray boxes around displays
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
163 |
@{ML_response_fake [display,gray] |
70
bbb2d5f1d58d
deleted the fixme about simpsets
Christian Urban <urbanc@in.tum.de>
parents:
69
diff
changeset
|
164 |
"let |
bbb2d5f1d58d
deleted the fixme about simpsets
Christian Urban <urbanc@in.tum.de>
parents:
69
diff
changeset
|
165 |
val ({rules,...},_) = MetaSimplifier.rep_ss @{simpset} |
bbb2d5f1d58d
deleted the fixme about simpsets
Christian Urban <urbanc@in.tum.de>
parents:
69
diff
changeset
|
166 |
in |
bbb2d5f1d58d
deleted the fixme about simpsets
Christian Urban <urbanc@in.tum.de>
parents:
69
diff
changeset
|
167 |
map #name (Net.entries rules) |
bbb2d5f1d58d
deleted the fixme about simpsets
Christian Urban <urbanc@in.tum.de>
parents:
69
diff
changeset
|
168 |
end" "[\"Nat.of_nat_eq_id\", \"Int.of_int_eq_id\", \"Nat.One_nat_def\", \<dots>]"} |
54
1783211b3494
tuned; added document antiquotation ML_response_fake_both
Christian Urban <urbanc@in.tum.de>
parents:
52
diff
changeset
|
169 |
|
81 | 170 |
The code about simpsets extracts the theorem names that are stored in the |
171 |
current simpset. We get hold of the current simpset with the antiquotation |
|
172 |
@{text "@{simpset}"}. The function @{ML rep_ss in MetaSimplifier} returns a record |
|
173 |
containing all information about the simpset. The rules of a simpset are |
|
174 |
stored in a \emph{discrimination net} (a datastructure for fast |
|
175 |
indexing). From this net we can extract the entries using the function @{ML |
|
176 |
Net.entries}. |
|
177 |
||
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
178 |
|
75 | 179 |
\begin{readmore} |
81 | 180 |
The infrastructure for simpsets is implemented in @{ML_file "Pure/meta_simplifier.ML"} |
78
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
181 |
and @{ML_file "Pure/simplifier.ML"}. Discrimination nets are implemented |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
182 |
in @{ML_file "Pure/net.ML"}. |
75 | 183 |
\end{readmore} |
184 |
||
185 |
While antiquotations have many applications, they were originally introduced in order |
|
186 |
to avoid explicit bindings for theorems such as |
|
43
02f76f1b6e7b
added positions to anti-quotations; removed old antiquotation_setup; tuned the text a bit
Christian Urban <urbanc@in.tum.de>
parents:
42
diff
changeset
|
187 |
*} |
02f76f1b6e7b
added positions to anti-quotations; removed old antiquotation_setup; tuned the text a bit
Christian Urban <urbanc@in.tum.de>
parents:
42
diff
changeset
|
188 |
|
69
19106a9975c1
highligted the background of ML-code
Christian Urban <urbanc@in.tum.de>
parents:
68
diff
changeset
|
189 |
ML{*val allI = thm "allI" *} |
43
02f76f1b6e7b
added positions to anti-quotations; removed old antiquotation_setup; tuned the text a bit
Christian Urban <urbanc@in.tum.de>
parents:
42
diff
changeset
|
190 |
|
02f76f1b6e7b
added positions to anti-quotations; removed old antiquotation_setup; tuned the text a bit
Christian Urban <urbanc@in.tum.de>
parents:
42
diff
changeset
|
191 |
text {* |
78
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
192 |
These bindings are difficult to maintain and also can be accidentally |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
193 |
overwritten by the user. This often breakes definitional |
49 | 194 |
packages. Antiquotations solve this problem, since they are ``linked'' |
75 | 195 |
statically at compile-time. However, this static linkage also limits their |
196 |
usefulness in cases where data needs to be build up dynamically. In the course of |
|
197 |
this introduction, we will learn more about |
|
49 | 198 |
these antiquotations: they greatly simplify Isabelle programming since one |
199 |
can directly access all kinds of logical elements from ML. |
|
200 |
||
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
201 |
*} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
202 |
|
15
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
203 |
section {* Terms and Types *} |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
204 |
|
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
205 |
text {* |
49 | 206 |
One way to construct terms of Isabelle on the ML-level is by using the antiquotation |
207 |
\mbox{@{text "@{term \<dots>}"}}. For example |
|
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
208 |
|
72
7b8c4fe235aa
added an antiquotation option [gray] for gray boxes around displays
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
209 |
@{ML_response [display,gray] |
75 | 210 |
"@{term \"(a::nat) + b = c\"}" |
211 |
"Const (\"op =\", \<dots>) $ |
|
212 |
(Const (\"HOL.plus_class.plus\", \<dots>) $ \<dots> $ \<dots>) $ \<dots>"} |
|
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
213 |
|
50 | 214 |
This will show the term @{term "(a::nat) + b = c"}, but printed using the internal |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
215 |
representation of this term. This internal representation corresponds to the |
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
216 |
datatype @{ML_type "term"}. |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
217 |
|
34 | 218 |
The internal representation of terms uses the usual de Bruijn index mechanism where bound |
11
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
219 |
variables are represented by the constructor @{ML Bound}. The index in @{ML Bound} refers to |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
220 |
the number of Abstractions (@{ML Abs}) we have to skip until we hit the @{ML Abs} that |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
221 |
binds the corresponding variable. However, in Isabelle the names of bound variables are |
11
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
222 |
kept at abstractions for printing purposes, and so should be treated only as comments. |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
223 |
|
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
224 |
\begin{readmore} |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
225 |
Terms are described in detail in \isccite{sec:terms}. Their |
78
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
226 |
definition and many useful operations are implemented in @{ML_file "Pure/term.ML"}. |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
227 |
\end{readmore} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
228 |
|
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
229 |
Sometimes the internal representation of terms can be surprisingly different |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
230 |
from what you see at the user level, because the layers of |
47
4daf913fdbe1
hakked latex so that it does not display ML {* *}; general tuning
Christian Urban <urbanc@in.tum.de>
parents:
43
diff
changeset
|
231 |
parsing/type-checking/pretty printing can be quite elaborate. |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
232 |
|
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
233 |
\begin{exercise} |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
234 |
Look at the internal term representation of the following terms, and |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
235 |
find out why they are represented like this. |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
236 |
|
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
237 |
\begin{itemize} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
238 |
\item @{term "case x of 0 \<Rightarrow> 0 | Suc y \<Rightarrow> y"} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
239 |
\item @{term "\<lambda>(x,y). P y x"} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
240 |
\item @{term "{ [x::int] | x. x \<le> -2 }"} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
241 |
\end{itemize} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
242 |
|
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
243 |
Hint: The third term is already quite big, and the pretty printer |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
244 |
may omit parts of it by default. If you want to see all of it, you |
52 | 245 |
can use the following ML function to set the limit to a value high |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
246 |
enough: |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
247 |
|
75 | 248 |
@{ML [display,gray] "print_depth 50"} |
72
7b8c4fe235aa
added an antiquotation option [gray] for gray boxes around displays
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
249 |
\end{exercise} |
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
250 |
|
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
251 |
The antiquotation @{text "@{prop \<dots>}"} constructs terms of propositional type, |
50 | 252 |
inserting the invisible @{text "Trueprop"}-coercions whenever necessary. |
68
e7519207c2b7
added more to the "new command section" and tuning
Christian Urban <urbanc@in.tum.de>
parents:
66
diff
changeset
|
253 |
Consider for example the pairs |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
254 |
|
72
7b8c4fe235aa
added an antiquotation option [gray] for gray boxes around displays
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
255 |
@{ML_response [display,gray] "(@{term \"P x\"}, @{prop \"P x\"})" "(Free (\"P\", \<dots>) $ Free (\"x\", \<dots>), |
65
c8e9a4f97916
tuned and added a section about creating keyword files
Christian Urban <urbanc@in.tum.de>
parents:
60
diff
changeset
|
256 |
Const (\"Trueprop\", \<dots>) $ (Free (\"P\", \<dots>) $ Free (\"x\", \<dots>)))"} |
c8e9a4f97916
tuned and added a section about creating keyword files
Christian Urban <urbanc@in.tum.de>
parents:
60
diff
changeset
|
257 |
|
68
e7519207c2b7
added more to the "new command section" and tuning
Christian Urban <urbanc@in.tum.de>
parents:
66
diff
changeset
|
258 |
where an coercion is inserted in the second component and |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
259 |
|
72
7b8c4fe235aa
added an antiquotation option [gray] for gray boxes around displays
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
260 |
@{ML_response [display,gray] "(@{term \"P x \<Longrightarrow> Q x\"}, @{prop \"P x \<Longrightarrow> Q x\"})" |
65
c8e9a4f97916
tuned and added a section about creating keyword files
Christian Urban <urbanc@in.tum.de>
parents:
60
diff
changeset
|
261 |
"(Const (\"==>\", \<dots>) $ \<dots> $ \<dots>, Const (\"==>\", \<dots>) $ \<dots> $ \<dots>)"} |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
262 |
|
72
7b8c4fe235aa
added an antiquotation option [gray] for gray boxes around displays
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
263 |
where it is not (since it is already constructed by a meta-implication). |
19
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
264 |
|
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
265 |
Types can be constructed using the antiquotation @{text "@{typ \<dots>}"}. For example |
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
266 |
|
72
7b8c4fe235aa
added an antiquotation option [gray] for gray boxes around displays
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
267 |
@{ML_response_fake [display,gray] "@{typ \"bool \<Rightarrow> nat\"}" "bool \<Rightarrow> nat"} |
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
268 |
|
19
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
269 |
\begin{readmore} |
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
270 |
Types are described in detail in \isccite{sec:types}. Their |
78
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
271 |
definition and many useful operations are implemented |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
272 |
in @{ML_file "Pure/type.ML"}. |
19
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
273 |
\end{readmore} |
47
4daf913fdbe1
hakked latex so that it does not display ML {* *}; general tuning
Christian Urban <urbanc@in.tum.de>
parents:
43
diff
changeset
|
274 |
*} |
19
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
275 |
|
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
276 |
|
15
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
277 |
section {* Constructing Terms and Types Manually *} |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
278 |
|
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
279 |
text {* |
81 | 280 |
While antiquotations are very convenient for constructing terms, they can |
281 |
only construct fixed terms (remember they are ``linked'' at |
|
282 |
compile-time). See Recipe~\ref{rec:external} on Page~\pageref{rec:external} |
|
283 |
for a function that pattern-matches over terms and where the pattern are |
|
284 |
constructed from antiquotations. However, one often needs to construct |
|
285 |
terms dynamically. For example, a function that returns the implication |
|
286 |
@{text "\<And>(x::\<tau>). P x \<Longrightarrow> Q x"} taking @{term P}, @{term Q} and the type @{term |
|
287 |
"\<tau>"} as arguments can only be written as |
|
43
02f76f1b6e7b
added positions to anti-quotations; removed old antiquotation_setup; tuned the text a bit
Christian Urban <urbanc@in.tum.de>
parents:
42
diff
changeset
|
288 |
*} |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
289 |
|
69
19106a9975c1
highligted the background of ML-code
Christian Urban <urbanc@in.tum.de>
parents:
68
diff
changeset
|
290 |
ML{*fun make_imp P Q tau = |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
291 |
let |
43
02f76f1b6e7b
added positions to anti-quotations; removed old antiquotation_setup; tuned the text a bit
Christian Urban <urbanc@in.tum.de>
parents:
42
diff
changeset
|
292 |
val x = Free ("x",tau) |
75 | 293 |
in |
294 |
Logic.all x (Logic.mk_implies (P $ x, Q $ x)) |
|
69
19106a9975c1
highligted the background of ML-code
Christian Urban <urbanc@in.tum.de>
parents:
68
diff
changeset
|
295 |
end *} |
43
02f76f1b6e7b
added positions to anti-quotations; removed old antiquotation_setup; tuned the text a bit
Christian Urban <urbanc@in.tum.de>
parents:
42
diff
changeset
|
296 |
|
02f76f1b6e7b
added positions to anti-quotations; removed old antiquotation_setup; tuned the text a bit
Christian Urban <urbanc@in.tum.de>
parents:
42
diff
changeset
|
297 |
text {* |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
298 |
|
19
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
299 |
The reason is that one cannot pass the arguments @{term P}, @{term Q} and |
65
c8e9a4f97916
tuned and added a section about creating keyword files
Christian Urban <urbanc@in.tum.de>
parents:
60
diff
changeset
|
300 |
@{term "tau"} into an antiquotation. For example the following does \emph{not} work: |
43
02f76f1b6e7b
added positions to anti-quotations; removed old antiquotation_setup; tuned the text a bit
Christian Urban <urbanc@in.tum.de>
parents:
42
diff
changeset
|
301 |
*} |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
302 |
|
69
19106a9975c1
highligted the background of ML-code
Christian Urban <urbanc@in.tum.de>
parents:
68
diff
changeset
|
303 |
ML{*fun make_wrong_imp P Q tau = @{prop "\<And>x. P x \<Longrightarrow> Q x"} *} |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
304 |
|
43
02f76f1b6e7b
added positions to anti-quotations; removed old antiquotation_setup; tuned the text a bit
Christian Urban <urbanc@in.tum.de>
parents:
42
diff
changeset
|
305 |
text {* |
19
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
306 |
To see this apply @{text "@{term S}"}, @{text "@{term T}"} and @{text "@{typ nat}"} |
75 | 307 |
to both functions. With @{ML make_imp} we obtain the intended term involving |
68
e7519207c2b7
added more to the "new command section" and tuning
Christian Urban <urbanc@in.tum.de>
parents:
66
diff
changeset
|
308 |
@{term "S"}, @{text "T"} and @{text "@{typ nat}"} |
65
c8e9a4f97916
tuned and added a section about creating keyword files
Christian Urban <urbanc@in.tum.de>
parents:
60
diff
changeset
|
309 |
|
72
7b8c4fe235aa
added an antiquotation option [gray] for gray boxes around displays
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
310 |
@{ML_response [display,gray] "make_imp @{term S} @{term T} @{typ nat}" |
65
c8e9a4f97916
tuned and added a section about creating keyword files
Christian Urban <urbanc@in.tum.de>
parents:
60
diff
changeset
|
311 |
"Const \<dots> $ |
c8e9a4f97916
tuned and added a section about creating keyword files
Christian Urban <urbanc@in.tum.de>
parents:
60
diff
changeset
|
312 |
Abs (\"x\", Type (\"nat\",[]), |
c8e9a4f97916
tuned and added a section about creating keyword files
Christian Urban <urbanc@in.tum.de>
parents:
60
diff
changeset
|
313 |
Const \<dots> $ (Free (\"S\",\<dots>) $ \<dots>) $ |
c8e9a4f97916
tuned and added a section about creating keyword files
Christian Urban <urbanc@in.tum.de>
parents:
60
diff
changeset
|
314 |
(Free (\"T\",\<dots>) $ \<dots>))"} |
68
e7519207c2b7
added more to the "new command section" and tuning
Christian Urban <urbanc@in.tum.de>
parents:
66
diff
changeset
|
315 |
|
81 | 316 |
whereas with @{ML make_wrong_imp} we obtain a term involving the @{term "P"} |
68
e7519207c2b7
added more to the "new command section" and tuning
Christian Urban <urbanc@in.tum.de>
parents:
66
diff
changeset
|
317 |
and @{text "Q"} from the antiquotation. |
e7519207c2b7
added more to the "new command section" and tuning
Christian Urban <urbanc@in.tum.de>
parents:
66
diff
changeset
|
318 |
|
72
7b8c4fe235aa
added an antiquotation option [gray] for gray boxes around displays
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
319 |
@{ML_response [display,gray] "make_wrong_imp @{term S} @{term T} @{typ nat}" |
65
c8e9a4f97916
tuned and added a section about creating keyword files
Christian Urban <urbanc@in.tum.de>
parents:
60
diff
changeset
|
320 |
"Const \<dots> $ |
c8e9a4f97916
tuned and added a section about creating keyword files
Christian Urban <urbanc@in.tum.de>
parents:
60
diff
changeset
|
321 |
Abs (\"x\", \<dots>, |
c8e9a4f97916
tuned and added a section about creating keyword files
Christian Urban <urbanc@in.tum.de>
parents:
60
diff
changeset
|
322 |
Const \<dots> $ (Const \<dots> $ (Free (\"P\",\<dots>) $ \<dots>)) $ |
c8e9a4f97916
tuned and added a section about creating keyword files
Christian Urban <urbanc@in.tum.de>
parents:
60
diff
changeset
|
323 |
(Const \<dots> $ (Free (\"Q\",\<dots>) $ \<dots>)))"} |
c8e9a4f97916
tuned and added a section about creating keyword files
Christian Urban <urbanc@in.tum.de>
parents:
60
diff
changeset
|
324 |
|
81 | 325 |
(FIXME: expand the following point) |
326 |
||
68
e7519207c2b7
added more to the "new command section" and tuning
Christian Urban <urbanc@in.tum.de>
parents:
66
diff
changeset
|
327 |
One tricky point in constructing terms by hand is to obtain the fully |
e7519207c2b7
added more to the "new command section" and tuning
Christian Urban <urbanc@in.tum.de>
parents:
66
diff
changeset
|
328 |
qualified name for constants. For example the names for @{text "zero"} and |
e7519207c2b7
added more to the "new command section" and tuning
Christian Urban <urbanc@in.tum.de>
parents:
66
diff
changeset
|
329 |
@{text "+"} are more complex than one first expects, namely |
19
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
330 |
|
15
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
331 |
|
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
332 |
\begin{center} |
58 | 333 |
@{text "HOL.zero_class.zero"} and @{text "HOL.plus_class.plus"}. |
15
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
334 |
\end{center} |
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
335 |
|
68
e7519207c2b7
added more to the "new command section" and tuning
Christian Urban <urbanc@in.tum.de>
parents:
66
diff
changeset
|
336 |
The extra prefixes @{text zero_class} and @{text plus_class} are present |
e7519207c2b7
added more to the "new command section" and tuning
Christian Urban <urbanc@in.tum.de>
parents:
66
diff
changeset
|
337 |
because these constants are defined within type classes; the prefix @{text |
e7519207c2b7
added more to the "new command section" and tuning
Christian Urban <urbanc@in.tum.de>
parents:
66
diff
changeset
|
338 |
"HOL"} indicates in which theory they are defined. Guessing such internal |
e7519207c2b7
added more to the "new command section" and tuning
Christian Urban <urbanc@in.tum.de>
parents:
66
diff
changeset
|
339 |
names can sometimes be quite hard. Therefore Isabelle provides the |
e7519207c2b7
added more to the "new command section" and tuning
Christian Urban <urbanc@in.tum.de>
parents:
66
diff
changeset
|
340 |
antiquotation @{text "@{const_name \<dots>}"} which does the expansion |
e7519207c2b7
added more to the "new command section" and tuning
Christian Urban <urbanc@in.tum.de>
parents:
66
diff
changeset
|
341 |
automatically, for example: |
49 | 342 |
|
72
7b8c4fe235aa
added an antiquotation option [gray] for gray boxes around displays
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
343 |
@{ML_response_fake [display,gray] "@{const_name \"Nil\"}" "List.list.Nil"} |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
344 |
|
19
34b93dbf8c3c
some tuning in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
15
diff
changeset
|
345 |
(FIXME: Is it useful to explain @{text "@{const_syntax}"}?) |
11
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
346 |
|
78
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
347 |
Similarly, one can construct types manually. For example the function returning |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
348 |
a function type is as follows: |
49 | 349 |
|
350 |
*} |
|
351 |
||
69
19106a9975c1
highligted the background of ML-code
Christian Urban <urbanc@in.tum.de>
parents:
68
diff
changeset
|
352 |
ML{*fun make_fun_type tau1 tau2 = Type ("fun",[tau1,tau2]) *} |
49 | 353 |
|
75 | 354 |
text {* This can be equally written as *} |
49 | 355 |
|
69
19106a9975c1
highligted the background of ML-code
Christian Urban <urbanc@in.tum.de>
parents:
68
diff
changeset
|
356 |
ML{*fun make_fun_type tau1 tau2 = tau1 --> tau2 *} |
49 | 357 |
|
358 |
text {* |
|
20 | 359 |
|
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
360 |
\begin{readmore} |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
361 |
There are many functions in @{ML_file "Pure/logic.ML"} and |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
362 |
@{ML_file "HOL/hologic.ML"} that make such manual constructions of terms |
49 | 363 |
and types easier.\end{readmore} |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
364 |
|
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
365 |
Have a look at these files and try to solve the following two exercises: |
11
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
366 |
|
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
367 |
*} |
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
368 |
|
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
369 |
text {* |
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
370 |
|
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
371 |
\begin{exercise}\label{fun:revsum} |
58 | 372 |
Write a function @{text "rev_sum : term -> term"} that takes a |
11
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
373 |
term of the form @{text "t\<^isub>1 + t\<^isub>2 + \<dots> + t\<^isub>n"} (whereby @{text "i"} might be zero) |
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
374 |
and returns the reversed sum @{text "t\<^isub>n + \<dots> + t\<^isub>2 + t\<^isub>1"}. Assume |
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
375 |
the @{text "t\<^isub>i"} can be arbitrary expressions and also note that @{text "+"} |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
376 |
associates to the left. Try your function on some examples. |
11
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
377 |
\end{exercise} |
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
378 |
|
15
9da9ba2b095b
added a solution section and some other minor additions
Christian Urban <urbanc@in.tum.de>
parents:
14
diff
changeset
|
379 |
\begin{exercise}\label{fun:makesum} |
11
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
380 |
Write a function which takes two terms representing natural numbers |
75 | 381 |
in unary notation (like @{term "Suc (Suc (Suc 0))"}), and produce the |
11
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
382 |
number representing their sum. |
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
383 |
\end{exercise} |
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
384 |
|
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
385 |
*} |
733614e236a3
tuned and updated antquote_setup.ML
Christian Urban <urbanc@in.tum.de>
parents:
10
diff
changeset
|
386 |
|
49 | 387 |
section {* Type-Checking *} |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
388 |
|
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
389 |
text {* |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
390 |
|
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
391 |
We can freely construct and manipulate terms, since they are just |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
392 |
arbitrary unchecked trees. However, we eventually want to see if a |
54
1783211b3494
tuned; added document antiquotation ML_response_fake_both
Christian Urban <urbanc@in.tum.de>
parents:
52
diff
changeset
|
393 |
term is well-formed, or type-checks, relative to a theory. |
50 | 394 |
Type-checking is done via the function @{ML cterm_of}, which converts |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
395 |
a @{ML_type term} into a @{ML_type cterm}, a \emph{certified} term. |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
396 |
Unlike @{ML_type term}s, which are just trees, @{ML_type |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
397 |
"cterm"}s are abstract objects that are guaranteed to be |
81 | 398 |
type-correct, and they can only be constructed via ``official |
50 | 399 |
interfaces''. |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
400 |
|
54
1783211b3494
tuned; added document antiquotation ML_response_fake_both
Christian Urban <urbanc@in.tum.de>
parents:
52
diff
changeset
|
401 |
Type-checking is always relative to a theory context. For now we use |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
402 |
the @{ML "@{theory}"} antiquotation to get hold of the current theory. |
47
4daf913fdbe1
hakked latex so that it does not display ML {* *}; general tuning
Christian Urban <urbanc@in.tum.de>
parents:
43
diff
changeset
|
403 |
For example we can write |
4daf913fdbe1
hakked latex so that it does not display ML {* *}; general tuning
Christian Urban <urbanc@in.tum.de>
parents:
43
diff
changeset
|
404 |
|
72
7b8c4fe235aa
added an antiquotation option [gray] for gray boxes around displays
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
405 |
@{ML_response_fake [display,gray] "cterm_of @{theory} @{term \"a + b = c\"}" "a + b = c"} |
47
4daf913fdbe1
hakked latex so that it does not display ML {* *}; general tuning
Christian Urban <urbanc@in.tum.de>
parents:
43
diff
changeset
|
406 |
|
81 | 407 |
This can also be wirtten with an antiquotation |
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
408 |
|
72
7b8c4fe235aa
added an antiquotation option [gray] for gray boxes around displays
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
409 |
@{ML_response_fake [display,gray] "@{cterm \"(a::nat) + b = c\"}" "a + b = c"} |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
410 |
|
78
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
411 |
Attempting to obtain the certified term for |
54
1783211b3494
tuned; added document antiquotation ML_response_fake_both
Christian Urban <urbanc@in.tum.de>
parents:
52
diff
changeset
|
412 |
|
72
7b8c4fe235aa
added an antiquotation option [gray] for gray boxes around displays
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
413 |
@{ML_response_fake_both [display,gray] "@{cterm \"1 + True\"}" "Type unification failed \<dots>"} |
54
1783211b3494
tuned; added document antiquotation ML_response_fake_both
Christian Urban <urbanc@in.tum.de>
parents:
52
diff
changeset
|
414 |
|
78
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
415 |
yields an error (since the term is not typable). A slightly more elaborate |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
416 |
example that type-checks is |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
417 |
|
20 | 418 |
|
72
7b8c4fe235aa
added an antiquotation option [gray] for gray boxes around displays
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
419 |
@{ML_response_fake [display,gray] |
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
420 |
"let |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
421 |
val natT = @{typ \"nat\"} |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
422 |
val zero = @{term \"0::nat\"} |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
423 |
in |
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
424 |
cterm_of @{theory} |
75 | 425 |
(Const (@{const_name plus}, natT --> natT --> natT) $ zero $ zero) |
41
b11653b11bd3
further progress on the parsing section and tuning on the antiqu's
Christian Urban <urbanc@in.tum.de>
parents:
40
diff
changeset
|
426 |
end" "0 + 0"} |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
427 |
|
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
428 |
\begin{exercise} |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
429 |
Check that the function defined in Exercise~\ref{fun:revsum} returns a |
50 | 430 |
result that type-checks. |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
431 |
\end{exercise} |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
432 |
|
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
433 |
*} |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
434 |
|
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
435 |
section {* Theorems *} |
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
436 |
|
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
437 |
text {* |
50 | 438 |
Just like @{ML_type cterm}s, theorems are abstract objects of type @{ML_type thm} |
78
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
439 |
that can only be built by going through interfaces. As a consequence, every proof |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
440 |
in Isabelle is correct by construction (FIXME reference LCF-philosophy) |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
441 |
|
78
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
442 |
To see theorems in ``action'', let us give a proof on the ML-level for the following |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
443 |
statement: |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
444 |
*} |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
445 |
|
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
446 |
lemma |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
447 |
assumes assm\<^isub>1: "\<And>(x::nat). P x \<Longrightarrow> Q x" |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
448 |
and assm\<^isub>2: "P t" |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
449 |
shows "Q t" (*<*)oops(*>*) |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
450 |
|
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
451 |
text {* |
78
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
452 |
The corresponding ML-code is as follows:\footnote{Note that @{text "|>"} is reverse |
75 | 453 |
application. See Section~\ref{sec:combinators}.} |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
454 |
|
72
7b8c4fe235aa
added an antiquotation option [gray] for gray boxes around displays
Christian Urban <urbanc@in.tum.de>
parents:
71
diff
changeset
|
455 |
@{ML_response_fake [display,gray] |
42
cd612b489504
tuned mostly antiquotation and text
Christian Urban <urbanc@in.tum.de>
parents:
41
diff
changeset
|
456 |
"let |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
457 |
val thy = @{theory} |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
458 |
|
42
cd612b489504
tuned mostly antiquotation and text
Christian Urban <urbanc@in.tum.de>
parents:
41
diff
changeset
|
459 |
val assm1 = cterm_of thy @{prop \"\<And>(x::nat). P x \<Longrightarrow> Q x\"} |
49 | 460 |
val assm2 = cterm_of thy @{prop \"(P::nat\<Rightarrow>bool) t\"} |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
461 |
|
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
462 |
val Pt_implies_Qt = |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
463 |
assume assm1 |
42
cd612b489504
tuned mostly antiquotation and text
Christian Urban <urbanc@in.tum.de>
parents:
41
diff
changeset
|
464 |
|> forall_elim (cterm_of thy @{term \"t::nat\"}); |
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
465 |
|
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
466 |
val Qt = implies_elim Pt_implies_Qt (assume assm2); |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
467 |
in |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
468 |
|
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
469 |
Qt |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
470 |
|> implies_intr assm2 |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
471 |
|> implies_intr assm1 |
48
609f9ef73494
fixed FIXME's in fake responses
Christian Urban <urbanc@in.tum.de>
parents:
47
diff
changeset
|
472 |
end" "\<lbrakk>\<And>x. P x \<Longrightarrow> Q x; P t\<rbrakk> \<Longrightarrow> Q t"} |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
473 |
|
21
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
474 |
This code-snippet constructs the following proof: |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
475 |
|
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
476 |
\[ |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
477 |
\infer[(@{text "\<Longrightarrow>"}$-$intro)]{\vdash @{prop "(\<And>x. P x \<Longrightarrow> Q x) \<Longrightarrow> P t \<Longrightarrow> Q t"}} |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
478 |
{\infer[(@{text "\<Longrightarrow>"}$-$intro)]{@{prop "\<And>x. P x \<Longrightarrow> Q x"} \vdash @{prop "P t \<Longrightarrow> Q t"}} |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
479 |
{\infer[(@{text "\<Longrightarrow>"}$-$elim)]{@{prop "\<And>x. P x \<Longrightarrow> Q x"}, @{prop "P t"} \vdash @{prop "Q t"}} |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
480 |
{\infer[(@{text "\<And>"}$-$elim)]{@{prop "\<And>x. P x \<Longrightarrow> Q x"} \vdash @{prop "P t \<Longrightarrow> Q t"}} |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
481 |
{\infer[(assume)]{@{prop "\<And>x. P x \<Longrightarrow> Q x"} \vdash @{prop "\<And>x. P x \<Longrightarrow> Q x"}}{}} |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
482 |
& |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
483 |
\infer[(assume)]{@{prop "P t"} \vdash @{prop "P t"}}{} |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
484 |
} |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
485 |
} |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
486 |
} |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
487 |
\] |
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
488 |
|
2356e5c70d98
added a proof and tuned the rest
Christian Urban <urbanc@in.tum.de>
parents:
20
diff
changeset
|
489 |
|
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
490 |
\begin{readmore} |
50 | 491 |
For the functions @{text "assume"}, @{text "forall_elim"} etc |
13
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
492 |
see \isccite{sec:thms}. The basic functions for theorems are defined in |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
493 |
@{ML_file "Pure/thm.ML"}. |
2b07da8b310d
polished and added a subdirectory for the recipes
Christian Urban <urbanc@in.tum.de>
parents:
12
diff
changeset
|
494 |
\end{readmore} |
12
2f1736cb8f26
various changes by Alex and Christian
Christian Urban <urbanc@in.tum.de>
parents:
11
diff
changeset
|
495 |
|
10
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
496 |
*} |
df09e49b19bf
many changes in the FirstSteps section
Christian Urban <urbanc@in.tum.de>
parents:
6
diff
changeset
|
497 |
|
20 | 498 |
section {* Storing Theorems *} |
499 |
||
500 |
section {* Theorem Attributes *} |
|
501 |
||
75 | 502 |
section {* Operations on Constants (Names) *} |
39
631d12c25bde
substantial changes to the antiquotations (preliminary version)
Christian Urban <urbanc@in.tum.de>
parents:
34
diff
changeset
|
503 |
|
68
e7519207c2b7
added more to the "new command section" and tuning
Christian Urban <urbanc@in.tum.de>
parents:
66
diff
changeset
|
504 |
text {* |
78
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
505 |
|
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
506 |
@{ML_response [display] "Sign.base_name \"List.list.Nil\"" "\"Nil\""} |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
507 |
|
75 | 508 |
*} |
509 |
||
510 |
section {* Combinators\label{sec:combinators} *} |
|
511 |
||
512 |
text {* |
|
81 | 513 |
Perhaps one of the most puzzling aspect for a beginner when reading |
514 |
existing Isabelle code special purpose combinators. At first they |
|
75 | 515 |
seem to obstruct the comprehension of the code, but after getting familiar |
81 | 516 |
with them they actually ease the understanding and also the programming. |
73
bcbcf5c839ae
used newly exported break reference in ThyOutput for writing separate output_list function
Christian Urban <urbanc@in.tum.de>
parents:
72
diff
changeset
|
517 |
|
bcbcf5c839ae
used newly exported break reference in ThyOutput for writing separate output_list function
Christian Urban <urbanc@in.tum.de>
parents:
72
diff
changeset
|
518 |
\begin{readmore} |
75 | 519 |
The most frequently used combinator are defined in the files @{ML_file "Pure/library.ML"} |
73
bcbcf5c839ae
used newly exported break reference in ThyOutput for writing separate output_list function
Christian Urban <urbanc@in.tum.de>
parents:
72
diff
changeset
|
520 |
and @{ML_file "Pure/General/basics.ML"}. |
bcbcf5c839ae
used newly exported break reference in ThyOutput for writing separate output_list function
Christian Urban <urbanc@in.tum.de>
parents:
72
diff
changeset
|
521 |
\end{readmore} |
bcbcf5c839ae
used newly exported break reference in ThyOutput for writing separate output_list function
Christian Urban <urbanc@in.tum.de>
parents:
72
diff
changeset
|
522 |
|
78
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
523 |
The simplest combinator is @{ML I} which is just the identity function. |
73
bcbcf5c839ae
used newly exported break reference in ThyOutput for writing separate output_list function
Christian Urban <urbanc@in.tum.de>
parents:
72
diff
changeset
|
524 |
*} |
bcbcf5c839ae
used newly exported break reference in ThyOutput for writing separate output_list function
Christian Urban <urbanc@in.tum.de>
parents:
72
diff
changeset
|
525 |
|
bcbcf5c839ae
used newly exported break reference in ThyOutput for writing separate output_list function
Christian Urban <urbanc@in.tum.de>
parents:
72
diff
changeset
|
526 |
ML{*fun I x = x*} |
bcbcf5c839ae
used newly exported break reference in ThyOutput for writing separate output_list function
Christian Urban <urbanc@in.tum.de>
parents:
72
diff
changeset
|
527 |
|
81 | 528 |
text {* Another combinator is @{ML K}, defined as *} |
75 | 529 |
|
530 |
ML{*fun K x = fn _ => x*} |
|
531 |
||
73
bcbcf5c839ae
used newly exported break reference in ThyOutput for writing separate output_list function
Christian Urban <urbanc@in.tum.de>
parents:
72
diff
changeset
|
532 |
text {* |
81 | 533 |
It ``wraps'' a function around the argument @{text "x"}. However, this |
534 |
function ignores its argument. |
|
73
bcbcf5c839ae
used newly exported break reference in ThyOutput for writing separate output_list function
Christian Urban <urbanc@in.tum.de>
parents:
72
diff
changeset
|
535 |
|
81 | 536 |
The next combinator is reverse application, @{ML "(op |>)"}, defined as |
68
e7519207c2b7
added more to the "new command section" and tuning
Christian Urban <urbanc@in.tum.de>
parents:
66
diff
changeset
|
537 |
*} |
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
538 |
|
75 | 539 |
ML{*fun x |> f = f x*} |
540 |
||
81 | 541 |
text {* While just syntactic sugar for the usual function application, |
542 |
the purpose of this combinator is to implement functions in a |
|
78
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
543 |
``waterfall fashion''. Consider for example the function *} |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
544 |
|
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
545 |
ML %linenumbers{*fun inc_by_five x = |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
546 |
x |> (fn x => x + 1) |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
547 |
|> (fn x => (x, x)) |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
548 |
|> fst |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
549 |
|> (fn x => x + 4)*} |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
550 |
|
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
551 |
text {* |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
552 |
which increments the argument @{text x} by 5. It does this by first incrementing |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
553 |
the argument by 1 (Line 2); then storing the result in a pair (Line 3); taking |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
554 |
the first component of the pair (Line 4) and finally incrementing the first |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
555 |
component by 4 (Line 5). This kind of cascading manipulations of values is quite |
81 | 556 |
common when dealing with theories (for example by adding a definition, followed by |
78
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
557 |
lemmas and so on). Writing the function @{ML inc_by_five} using the reverse |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
558 |
application is much clearer than writing |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
559 |
*} |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
560 |
|
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
561 |
ML{*fun inc_by_five x = fst ((fn x => (x, x)) (x + 1)) + 4*} |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
562 |
|
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
563 |
text {* or *} |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
564 |
|
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
565 |
ML{*fun inc_by_five x = |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
566 |
((fn x => x + 4) o fst o (fn x => (x, x)) o (fn x => x + 1)) x*} |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
567 |
|
81 | 568 |
text {* and typographically more economical than *} |
78
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
569 |
|
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
570 |
ML{*fun inc_by_five x = |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
571 |
let val y1 = x + 1 |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
572 |
val y2 = (y1, y1) |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
573 |
val y3 = fst y2 |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
574 |
val y4 = y3 + 4 |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
575 |
in y4 end*} |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
576 |
|
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
577 |
text {* |
81 | 578 |
(FIXME: give a real world example involving theories) |
579 |
||
78
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
580 |
Similarly, the combinator @{ML "(op #>)"} is the reverse function |
81 | 581 |
composition. It can be used to define functions as follows |
78
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
582 |
*} |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
583 |
|
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
584 |
ML{*val inc_by_six = |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
585 |
(fn x => x + 1) |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
586 |
#> (fn x => x + 2) |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
587 |
#> (fn x => x + 3)*} |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
588 |
|
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
589 |
text {* |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
590 |
which is the function composed of first the increment-by-one function and then |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
591 |
increment-by-two, followed by increment-by-three. Applying 6 to this function |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
592 |
yields |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
593 |
|
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
594 |
@{ML_response [display,gray] "inc_by_six 6" "12"} |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
595 |
|
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
596 |
as expected. |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
597 |
|
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
598 |
The remaining combinators add convenience for the ``waterfall method'' |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
599 |
of writing functions. The combinator @{ML tap} allows one to get |
81 | 600 |
hold of an intermediate result (to do some side-calculations for instance). |
601 |
The function *} |
|
78
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
602 |
|
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
603 |
ML{*fun inc_by_three x = |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
604 |
x |> (fn x => x + 1) |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
605 |
|> tap (fn x => tracing (makestring x)) |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
606 |
|> (fn x => x + 2)*} |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
607 |
|
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
608 |
text {* increments the argument first by one and then by two. In the middle, |
81 | 609 |
however, it uses @{ML tap} for printing the ``plus-one'' intermediate |
610 |
result inside the tracing buffer. |
|
78
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
611 |
|
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
612 |
The combinator @{ML "(op `)"} is similar, but applies a function to the value |
81 | 613 |
and returns the result together with the original value (as pair). For example |
614 |
the following function takes @{text x} as argument, and then first |
|
615 |
increments @{text x}, but also keeps @{text x}. The intermediate result is |
|
616 |
therefore the pair @{ML "(x + 1,x)" for x}. The function then increments the |
|
617 |
right-hand component of the pair. |
|
78
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
618 |
*} |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
619 |
|
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
620 |
ML{*fun inc_as_pair x = |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
621 |
x |> `(fn x => x + 1) |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
622 |
|> (fn (x, y) => (x, y + 1))*} |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
623 |
|
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
624 |
text {* |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
625 |
The combinators @{ML "(op |>>)"} and @{ML "(op ||>)"} are defined for |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
626 |
functions manipulating pairs. The first applies the function to |
81 | 627 |
the first component of the pair, defined as: |
78
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
628 |
*} |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
629 |
|
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
630 |
ML{*fun (x, y) |>> f = (f x, y)*} |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
631 |
|
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
632 |
text {* |
81 | 633 |
and the second combinator to the second component, defined as |
78
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
634 |
*} |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
635 |
|
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
636 |
ML{*fun (x, y) ||> f = (x, f y)*} |
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
637 |
|
81 | 638 |
text {* |
639 |
(FIXME: find a good exercise for combinators) |
|
640 |
*} |
|
78
ef778679d3e0
added a section about combinators
Christian Urban <urbanc@in.tum.de>
parents:
75
diff
changeset
|
641 |
|
2
978a3c2ed7ce
split the document into smaller pieces;
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
642 |
end |