10 Pure \<open>\<lambda>\<close>-calculus as introduced in \chref{ch:logic} is an adequate |
10 Pure \<open>\<lambda>\<close>-calculus as introduced in \chref{ch:logic} is an adequate |
11 foundation for logical languages --- in the tradition of \<^emph>\<open>higher-order |
11 foundation for logical languages --- in the tradition of \<^emph>\<open>higher-order |
12 abstract syntax\<close> --- but end-users require additional means for reading and |
12 abstract syntax\<close> --- but end-users require additional means for reading and |
13 printing of terms and types. This important add-on outside the logical core |
13 printing of terms and types. This important add-on outside the logical core |
14 is called \<^emph>\<open>inner syntax\<close> in Isabelle jargon, as opposed to the \<^emph>\<open>outer |
14 is called \<^emph>\<open>inner syntax\<close> in Isabelle jargon, as opposed to the \<^emph>\<open>outer |
15 syntax\<close> of the theory and proof language @{cite "isabelle-isar-ref"}. |
15 syntax\<close> of the theory and proof language \<^cite>\<open>"isabelle-isar-ref"\<close>. |
16 |
16 |
17 For example, according to @{cite church40} quantifiers are represented as |
17 For example, according to \<^cite>\<open>church40\<close> quantifiers are represented as |
18 higher-order constants \<open>All :: ('a \<Rightarrow> bool) \<Rightarrow> bool\<close> such that \<open>All (\<lambda>x::'a. B |
18 higher-order constants \<open>All :: ('a \<Rightarrow> bool) \<Rightarrow> bool\<close> such that \<open>All (\<lambda>x::'a. B |
19 x)\<close> faithfully represents the idea that is displayed in Isabelle as \<open>\<forall>x::'a. |
19 x)\<close> faithfully represents the idea that is displayed in Isabelle as \<open>\<forall>x::'a. |
20 B x\<close> via @{keyword "binder"} notation. Moreover, type-inference in the style |
20 B x\<close> via @{keyword "binder"} notation. Moreover, type-inference in the style |
21 of Hindley-Milner @{cite hindleymilner} (and extensions) enables users to |
21 of Hindley-Milner \<^cite>\<open>hindleymilner\<close> (and extensions) enables users to |
22 write \<open>\<forall>x. B x\<close> concisely, when the type \<open>'a\<close> is already clear from the |
22 write \<open>\<forall>x. B x\<close> concisely, when the type \<open>'a\<close> is already clear from the |
23 context.\<^footnote>\<open>Type-inference taken to the extreme can easily confuse users. |
23 context.\<^footnote>\<open>Type-inference taken to the extreme can easily confuse users. |
24 Beginners often stumble over unexpectedly general types inferred by the |
24 Beginners often stumble over unexpectedly general types inferred by the |
25 system.\<close> |
25 system.\<close> |
26 |
26 |
119 |
119 |
120 \<^ML>\<open>Syntax.read_term\<close>, \<^ML>\<open>Syntax.read_prop\<close>, and \<^ML>\<open>Syntax.string_of_term\<close> are the most important operations in practice. |
120 \<^ML>\<open>Syntax.read_term\<close>, \<^ML>\<open>Syntax.read_prop\<close>, and \<^ML>\<open>Syntax.string_of_term\<close> are the most important operations in practice. |
121 |
121 |
122 \<^medskip> |
122 \<^medskip> |
123 Note that the string values that are passed in and out are annotated by the |
123 Note that the string values that are passed in and out are annotated by the |
124 system, to carry further markup that is relevant for the Prover IDE @{cite |
124 system, to carry further markup that is relevant for the Prover IDE \<^cite>\<open>"isabelle-jedit"\<close>. User code should neither compose its own input strings, |
125 "isabelle-jedit"}. User code should neither compose its own input strings, |
|
126 nor try to analyze the output strings. Conceptually this is an abstract |
125 nor try to analyze the output strings. Conceptually this is an abstract |
127 datatype, encoded as concrete string for historical reasons. |
126 datatype, encoded as concrete string for historical reasons. |
128 |
127 |
129 The standard way to provide the required position markup for input works via |
128 The standard way to provide the required position markup for input works via |
130 the outer syntax parser wrapper \<^ML>\<open>Parse.inner_syntax\<close>, which is already |
129 the outer syntax parser wrapper \<^ML>\<open>Parse.inner_syntax\<close>, which is already |
148 Actual parsing is based on traditional lexical analysis and Earley parsing |
147 Actual parsing is based on traditional lexical analysis and Earley parsing |
149 for arbitrary context-free grammars. The user can specify the grammar |
148 for arbitrary context-free grammars. The user can specify the grammar |
150 declaratively via mixfix annotations. Moreover, there are \<^emph>\<open>syntax |
149 declaratively via mixfix annotations. Moreover, there are \<^emph>\<open>syntax |
151 translations\<close> that can be augmented by the user, either declaratively via |
150 translations\<close> that can be augmented by the user, either declaratively via |
152 @{command translations} or programmatically via @{command |
151 @{command translations} or programmatically via @{command |
153 parse_translation}, @{command print_translation} @{cite |
152 parse_translation}, @{command print_translation} \<^cite>\<open>"isabelle-isar-ref"\<close>. The final scope-resolution is performed by the system, |
154 "isabelle-isar-ref"}. The final scope-resolution is performed by the system, |
|
155 according to name spaces for types, term variables and constants determined |
153 according to name spaces for types, term variables and constants determined |
156 by the context. |
154 by the context. |
157 \<close> |
155 \<close> |
158 |
156 |
159 text %mlref \<open> |
157 text %mlref \<open> |
198 of ``type-inference'' or ``type-reconstruction'' or ``type-improvement'', |
196 of ``type-inference'' or ``type-reconstruction'' or ``type-improvement'', |
199 not just type-checking in the narrow sense. The \<^emph>\<open>uncheck\<close> phase is roughly |
197 not just type-checking in the narrow sense. The \<^emph>\<open>uncheck\<close> phase is roughly |
200 dual, it prunes type-information before pretty printing. |
198 dual, it prunes type-information before pretty printing. |
201 |
199 |
202 A typical add-on for the check/uncheck syntax layer is the @{command |
200 A typical add-on for the check/uncheck syntax layer is the @{command |
203 abbreviation} mechanism @{cite "isabelle-isar-ref"}. Here the user specifies |
201 abbreviation} mechanism \<^cite>\<open>"isabelle-isar-ref"\<close>. Here the user specifies |
204 syntactic definitions that are managed by the system as polymorphic \<open>let\<close> |
202 syntactic definitions that are managed by the system as polymorphic \<open>let\<close> |
205 bindings. These are expanded during the \<open>check\<close> phase, and contracted during |
203 bindings. These are expanded during the \<open>check\<close> phase, and contracted during |
206 the \<open>uncheck\<close> phase, without affecting the type-assignment of the given |
204 the \<open>uncheck\<close> phase, without affecting the type-assignment of the given |
207 terms. |
205 terms. |
208 |
206 |
212 |
210 |
213 For example, the @{command class} command defines a context where \<open>check\<close> |
211 For example, the @{command class} command defines a context where \<open>check\<close> |
214 treats certain type instances of overloaded constants according to the |
212 treats certain type instances of overloaded constants according to the |
215 ``dictionary construction'' of its logical foundation. This involves ``type |
213 ``dictionary construction'' of its logical foundation. This involves ``type |
216 improvement'' (specialization of slightly too general types) and replacement |
214 improvement'' (specialization of slightly too general types) and replacement |
217 by certain locale parameters. See also @{cite "Haftmann-Wenzel:2009"}. |
215 by certain locale parameters. See also \<^cite>\<open>"Haftmann-Wenzel:2009"\<close>. |
218 \<close> |
216 \<close> |
219 |
217 |
220 text %mlref \<open> |
218 text %mlref \<open> |
221 \begin{mldecls} |
219 \begin{mldecls} |
222 @{define_ML Syntax.check_typs: "Proof.context -> typ list -> typ list"} \\ |
220 @{define_ML Syntax.check_typs: "Proof.context -> typ list -> typ list"} \\ |