10 an adequate foundation for logical languages --- in the tradition of |
10 an adequate foundation for logical languages --- in the tradition of |
11 \emph{higher-order abstract syntax} --- but end-users require |
11 \emph{higher-order abstract syntax} --- but end-users require |
12 additional means for reading and printing of terms and types. This |
12 additional means for reading and printing of terms and types. This |
13 important add-on outside the logical core is called \emph{inner |
13 important add-on outside the logical core is called \emph{inner |
14 syntax} in Isabelle jargon, as opposed to the \emph{outer syntax} of |
14 syntax} in Isabelle jargon, as opposed to the \emph{outer syntax} of |
15 the theory and proof language \cite{isabelle-isar-ref}. |
15 the theory and proof language @{cite "isabelle-isar-ref"}. |
16 |
16 |
17 For example, according to \cite{church40} quantifiers are represented as |
17 For example, according to @{cite church40} quantifiers are represented as |
18 higher-order constants @{text "All :: ('a \<Rightarrow> bool) \<Rightarrow> bool"} such that @{text |
18 higher-order constants @{text "All :: ('a \<Rightarrow> bool) \<Rightarrow> bool"} such that @{text |
19 "All (\<lambda>x::'a. B x)"} faithfully represents the idea that is displayed in |
19 "All (\<lambda>x::'a. B x)"} faithfully represents the idea that is displayed in |
20 Isabelle as @{text "\<forall>x::'a. B x"} via @{keyword "binder"} notation. |
20 Isabelle as @{text "\<forall>x::'a. B x"} via @{keyword "binder"} notation. |
21 Moreover, type-inference in the style of Hindley-Milner \cite{hindleymilner} |
21 Moreover, type-inference in the style of Hindley-Milner @{cite hindleymilner} |
22 (and extensions) enables users to write @{text "\<forall>x. B x"} concisely, when |
22 (and extensions) enables users to write @{text "\<forall>x. B x"} concisely, when |
23 the type @{text "'a"} is already clear from the |
23 the type @{text "'a"} is already clear from the |
24 context.\footnote{Type-inference taken to the extreme can easily confuse |
24 context.\footnote{Type-inference taken to the extreme can easily confuse |
25 users. Beginners often stumble over unexpectedly general types inferred by |
25 users. Beginners often stumble over unexpectedly general types inferred by |
26 the system.} |
26 the system.} |
131 @{ML Syntax.read_term}, @{ML Syntax.read_prop}, and @{ML |
131 @{ML Syntax.read_term}, @{ML Syntax.read_prop}, and @{ML |
132 Syntax.string_of_term} are the most important operations in practice. |
132 Syntax.string_of_term} are the most important operations in practice. |
133 |
133 |
134 \medskip Note that the string values that are passed in and out are |
134 \medskip Note that the string values that are passed in and out are |
135 annotated by the system, to carry further markup that is relevant for the |
135 annotated by the system, to carry further markup that is relevant for the |
136 Prover IDE \cite{isabelle-jedit}. User code should neither compose its own |
136 Prover IDE @{cite "isabelle-jedit"}. User code should neither compose its |
137 input strings, nor try to analyze the output strings. Conceptually this is |
137 own input strings, nor try to analyze the output strings. Conceptually this |
138 an abstract datatype, encoded as concrete string for historical reasons. |
138 is an abstract datatype, encoded as concrete string for historical reasons. |
139 |
139 |
140 The standard way to provide the required position markup for input works via |
140 The standard way to provide the required position markup for input works via |
141 the outer syntax parser wrapper @{ML Parse.inner_syntax}, which is already |
141 the outer syntax parser wrapper @{ML Parse.inner_syntax}, which is already |
142 part of @{ML Parse.typ}, @{ML Parse.term}, @{ML Parse.prop}. So a string |
142 part of @{ML Parse.typ}, @{ML Parse.term}, @{ML Parse.prop}. So a string |
143 obtained from one of the latter may be directly passed to the corresponding |
143 obtained from one of the latter may be directly passed to the corresponding |
159 Actual parsing is based on traditional lexical analysis and Earley parsing |
159 Actual parsing is based on traditional lexical analysis and Earley parsing |
160 for arbitrary context-free grammars. The user can specify the grammar |
160 for arbitrary context-free grammars. The user can specify the grammar |
161 declaratively via mixfix annotations. Moreover, there are \emph{syntax |
161 declaratively via mixfix annotations. Moreover, there are \emph{syntax |
162 translations} that can be augmented by the user, either declaratively via |
162 translations} that can be augmented by the user, either declaratively via |
163 @{command translations} or programmatically via @{command |
163 @{command translations} or programmatically via @{command |
164 parse_translation}, @{command print_translation} \cite{isabelle-isar-ref}. |
164 parse_translation}, @{command print_translation} @{cite |
165 The final scope-resolution is performed by the system, according to name |
165 "isabelle-isar-ref"}. The final scope-resolution is performed by the system, |
166 spaces for types, term variables and constants determined by the context. |
166 according to name spaces for types, term variables and constants determined |
|
167 by the context. |
167 *} |
168 *} |
168 |
169 |
169 text %mlref {* |
170 text %mlref {* |
170 \begin{mldecls} |
171 \begin{mldecls} |
171 @{index_ML Syntax.parse_typ: "Proof.context -> string -> typ"} \\ |
172 @{index_ML Syntax.parse_typ: "Proof.context -> string -> typ"} \\ |
214 ``type-improvement'', not just type-checking in the narrow sense. |
215 ``type-improvement'', not just type-checking in the narrow sense. |
215 The \emph{uncheck} phase is roughly dual, it prunes type-information |
216 The \emph{uncheck} phase is roughly dual, it prunes type-information |
216 before pretty printing. |
217 before pretty printing. |
217 |
218 |
218 A typical add-on for the check/uncheck syntax layer is the @{command |
219 A typical add-on for the check/uncheck syntax layer is the @{command |
219 abbreviation} mechanism \cite{isabelle-isar-ref}. Here the user specifies |
220 abbreviation} mechanism @{cite "isabelle-isar-ref"}. Here the user specifies |
220 syntactic definitions that are managed by the system as polymorphic @{text |
221 syntactic definitions that are managed by the system as polymorphic @{text |
221 "let"} bindings. These are expanded during the @{text "check"} phase, and |
222 "let"} bindings. These are expanded during the @{text "check"} phase, and |
222 contracted during the @{text "uncheck"} phase, without affecting the |
223 contracted during the @{text "uncheck"} phase, without affecting the |
223 type-assignment of the given terms. |
224 type-assignment of the given terms. |
224 |
225 |
228 For example, the @{command class} command defines a context where |
229 For example, the @{command class} command defines a context where |
229 @{text "check"} treats certain type instances of overloaded |
230 @{text "check"} treats certain type instances of overloaded |
230 constants according to the ``dictionary construction'' of its |
231 constants according to the ``dictionary construction'' of its |
231 logical foundation. This involves ``type improvement'' |
232 logical foundation. This involves ``type improvement'' |
232 (specialization of slightly too general types) and replacement by |
233 (specialization of slightly too general types) and replacement by |
233 certain locale parameters. See also \cite{Haftmann-Wenzel:2009}. |
234 certain locale parameters. See also @{cite "Haftmann-Wenzel:2009"}. |
234 *} |
235 *} |
235 |
236 |
236 text %mlref {* |
237 text %mlref {* |
237 \begin{mldecls} |
238 \begin{mldecls} |
238 @{index_ML Syntax.check_typs: "Proof.context -> typ list -> typ list"} \\ |
239 @{index_ML Syntax.check_typs: "Proof.context -> typ list -> typ list"} \\ |