76 parentheses are omitted, e.g.\ @{text "\<alpha> list"} instead of @{text |
76 parentheses are omitted, e.g.\ @{text "\<alpha> list"} instead of @{text |
77 "(\<alpha>)list"}. Further notation is provided for specific constructors, |
77 "(\<alpha>)list"}. Further notation is provided for specific constructors, |
78 notably the right-associative infix @{text "\<alpha> \<Rightarrow> \<beta>"} instead of |
78 notably the right-associative infix @{text "\<alpha> \<Rightarrow> \<beta>"} instead of |
79 @{text "(\<alpha>, \<beta>)fun"}. |
79 @{text "(\<alpha>, \<beta>)fun"}. |
80 |
80 |
81 A \emph{type} is defined inductively over type variables and type |
81 A \emph{type} @{text "\<tau>"} is defined inductively over type variables |
82 constructors as follows: @{text "\<tau> = \<alpha>\<^isub>s | ?\<alpha>\<^isub>s | |
82 and type constructors as follows: @{text "\<tau> = \<alpha>\<^isub>s | |
83 (\<tau>\<^sub>1, \<dots>, \<tau>\<^sub>k)k"}. |
83 ?\<alpha>\<^isub>s | (\<tau>\<^sub>1, \<dots>, \<tau>\<^sub>k)k"}. |
84 |
84 |
85 A \emph{type abbreviation} is a syntactic abbreviation @{text |
85 A \emph{type abbreviation} is a syntactic definition @{text |
86 "(\<^vec>\<alpha>)\<kappa> = \<tau>"} of an arbitrary type expression @{text "\<tau>"} over |
86 "(\<^vec>\<alpha>)\<kappa> = \<tau>"} of an arbitrary type expression @{text "\<tau>"} over |
87 variables @{text "\<^vec>\<alpha>"}. Type abbreviations looks like type |
87 variables @{text "\<^vec>\<alpha>"}. Type abbreviations looks like type |
88 constructors at the surface, but are fully expanded before entering |
88 constructors at the surface, but are fully expanded before entering |
89 the logical core. |
89 the logical core. |
90 |
90 |
186 |
186 |
187 text {* |
187 text {* |
188 \glossary{Term}{FIXME} |
188 \glossary{Term}{FIXME} |
189 |
189 |
190 The language of terms is that of simply-typed @{text "\<lambda>"}-calculus |
190 The language of terms is that of simply-typed @{text "\<lambda>"}-calculus |
191 with de-Bruijn indices for bound variables, and named free |
191 with de-Bruijn indices for bound variables, and named free variables |
192 variables, and constants. Terms with loose bound variables are |
192 and constants. Terms with loose bound variables are usually |
193 usually considered malformed. The types of variables and constants |
193 considered malformed. The types of variables and constants is |
194 is stored explicitly at each occurrence in the term (which is a |
194 stored explicitly at each occurrence in the term. |
195 known performance issue). |
195 |
196 |
196 \medskip A \emph{bound variable} is a natural number @{text "b"}, |
197 FIXME de-Bruijn representation of lambda terms |
197 which refers to the next binder that is @{text "b"} steps upwards |
198 |
198 from the occurrence of @{text "b"} (counting from zero). Bindings |
199 Term syntax provides explicit abstraction @{text "\<lambda>x :: \<alpha>. b(x)"} |
199 may be introduced as abstractions within the term, or as a separate |
200 and application @{text "t u"}, while types are usually implicit |
200 context (an inside-out list). This associates each bound variable |
201 thanks to type-inference. |
201 with a type, and a name that is maintained as a comment for parsing |
202 |
202 and printing. A \emph{loose variables} is a bound variable that is |
203 |
203 outside the current scope of local binders or the context. For |
|
204 example, the de-Bruijn term @{text "\<lambda>\<^isub>\<tau>. \<lambda>\<^isub>\<tau>. 1 + 0"} |
|
205 corresponds to @{text "\<lambda>x\<^isub>\<tau>. \<lambda>y\<^isub>\<tau>. x + y"} in a named |
|
206 representation. Also note that the very same bound variable may get |
|
207 different numbers at different occurrences. |
|
208 |
|
209 A \emph{fixed variable} is a pair of a basic name and a type. For |
|
210 example, @{text "(x, \<tau>)"} which is usually printed @{text |
|
211 "x\<^isub>\<tau>"}. A \emph{schematic variable} is a pair of an |
|
212 indexname and a type. For example, @{text "((x, 0), \<tau>)"} which is |
|
213 usually printed as @{text "?x\<^isub>\<tau>"}. |
|
214 |
|
215 \medskip A \emph{constant} is a atomic terms consisting of a basic |
|
216 name and a type. Constants are declared in the context as |
|
217 polymorphic families @{text "c :: \<sigma>"}, meaning that any @{text |
|
218 "c\<^isub>\<tau>"} is a valid constant for all substitution instances |
|
219 @{text "\<tau> \<le> \<sigma>"}. |
|
220 |
|
221 The list of \emph{type arguments} of @{text "c\<^isub>\<tau>"} wrt.\ the |
|
222 declaration @{text "c :: \<sigma>"} is the codomain of the type matcher |
|
223 presented in canonical order (according to the left-to-right |
|
224 occurrences of type variables in in @{text "\<sigma>"}). Thus @{text |
|
225 "c\<^isub>\<tau>"} can be represented more compactly as @{text |
|
226 "c(\<tau>\<^isub>1, \<dots>, \<tau>\<^isub>n)"}. For example, the instance @{text |
|
227 "plus\<^bsub>nat \<Rightarrow> nat \<Rightarrow> nat\<^esub>"} of some @{text "plus :: \<alpha> \<Rightarrow> \<alpha> |
|
228 \<Rightarrow> \<alpha>"} has the singleton list @{text "nat"} as type arguments, the |
|
229 constant may be represented as @{text "plus(nat)"}. |
|
230 |
|
231 Constant declarations @{text "c :: \<sigma>"} may contain sort constraints |
|
232 for type variables in @{text "\<sigma>"}. These are observed by |
|
233 type-inference as expected, but \emph{ignored} by the core logic. |
|
234 This means the primitive logic is able to reason with instances of |
|
235 polymorphic constants that the user-level type-checker would reject. |
|
236 |
|
237 \medskip A \emph{term} @{text "t"} is defined inductively over |
|
238 variables and constants, with abstraction and application as |
|
239 follows: @{text "t = b | x\<^isub>\<tau> | ?x\<^isub>\<tau> | c\<^isub>\<tau> | |
|
240 \<lambda>\<^isub>\<tau>. t | t\<^isub>1 t\<^isub>2"}. Parsing and printing takes |
|
241 care of converting between an external representation with named |
|
242 bound variables. Subsequently, we shall use the latter notation |
|
243 instead of internal de-Bruijn representation. |
|
244 |
|
245 The subsequent inductive relation @{text "t :: \<tau>"} assigns a |
|
246 (unique) type to a term, using the special type constructor @{text |
|
247 "(\<alpha>, \<beta>)fun"}, which is written @{text "\<alpha> \<Rightarrow> \<beta>"}. |
204 \[ |
248 \[ |
205 \infer{@{text "a\<^isub>\<tau> :: \<tau>"}}{} |
249 \infer{@{text "a\<^isub>\<tau> :: \<tau>"}}{} |
206 \qquad |
250 \qquad |
207 \infer{@{text "(\<lambda>x\<^sub>\<tau>. t) :: \<tau> \<Rightarrow> \<sigma>"}}{@{text "t :: \<sigma>"}} |
251 \infer{@{text "(\<lambda>x\<^sub>\<tau>. t) :: \<tau> \<Rightarrow> \<sigma>"}}{@{text "t :: \<sigma>"}} |
208 \qquad |
252 \qquad |
209 \infer{@{text "t u :: \<sigma>"}}{@{text "t :: \<tau> \<Rightarrow> \<sigma>"} & @{text "u :: \<tau>"}} |
253 \infer{@{text "t u :: \<sigma>"}}{@{text "t :: \<tau> \<Rightarrow> \<sigma>"} & @{text "u :: \<tau>"}} |
210 \] |
254 \] |
211 |
255 A \emph{well-typed term} is a term that can be typed according to these rules. |
212 *} |
256 |
213 |
257 Typing information can be omitted: type-inference is able to |
214 |
258 reconstruct the most general type of a raw term, while assigning |
215 text {* |
259 most general types to all of its variables and constants. |
216 |
260 Type-inference depends on a context of type constraints for fixed |
217 FIXME |
261 variables, and declarations for polymorphic constants. |
218 |
262 |
219 \glossary{Schematic polymorphism}{FIXME} |
263 The identity of atomic terms consists both of the name and the type. |
220 |
264 Thus different entities @{text "c\<^bsub>\<tau>\<^isub>1\<^esub>"} and |
221 \glossary{Type variable}{FIXME} |
265 @{text "c\<^bsub>\<tau>\<^isub>2\<^esub>"} may well identified by type |
222 |
266 instantiation, by mapping @{text "\<tau>\<^isub>1"} and @{text |
|
267 "\<tau>\<^isub>2"} to the same @{text "\<tau>"}. Although, |
|
268 different type instances of constants of the same basic name are |
|
269 commonplace, this rarely happens for variables: type-inference |
|
270 always demands ``consistent'' type constraints. |
|
271 |
|
272 \medskip The \emph{hidden polymorphism} of a term @{text "t :: \<sigma>"} |
|
273 is the set of type variables occurring in @{text "t"}, but not in |
|
274 @{text "\<sigma>"}. This means that the term implicitly depends on the |
|
275 values of various type variables that are not visible in the overall |
|
276 type, i.e.\ there are different type instances @{text "t\<vartheta> |
|
277 :: \<sigma>"} and @{text "t\<vartheta>' :: \<sigma>"} with the same type. This |
|
278 slightly pathological situation is apt to cause strange effects. |
|
279 |
|
280 \medskip A \emph{term abbreviation} is a syntactic definition @{text |
|
281 "c\<^isub>\<sigma> \<equiv> t"} of an arbitrary closed term @{text "t"} of type |
|
282 @{text "\<sigma>"} without any hidden polymorphism. A term abbreviation |
|
283 looks like a constant at the surface, but is fully expanded before |
|
284 entering the logical core. Abbreviations are usually reverted when |
|
285 printing terms, using rules @{text "t \<rightarrow> c\<^isub>\<sigma>"} has a |
|
286 higher-order term rewrite system. |
|
287 *} |
|
288 |
|
289 text %mlref {* |
|
290 \begin{mldecls} |
|
291 @{index_ML_type term} \\ |
|
292 @{index_ML map_aterms: "(term -> term) -> term -> term"} \\ |
|
293 @{index_ML fold_aterms: "(term -> 'a -> 'a) -> term -> 'a -> 'a"} \\ |
|
294 @{index_ML fastype_of: "term -> typ"} \\ |
|
295 @{index_ML fold_types: "(typ -> 'a -> 'a) -> term -> 'a -> 'a"} \\ |
|
296 \end{mldecls} |
|
297 |
|
298 \begin{description} |
|
299 |
|
300 \item @{ML_type term} FIXME |
|
301 |
|
302 \end{description} |
223 *} |
303 *} |
224 |
304 |
225 |
305 |
226 section {* Theorems \label{sec:thms} *} |
306 section {* Theorems \label{sec:thms} *} |
227 |
307 |