| author | hoelzl | 
| Tue, 29 Mar 2011 14:27:42 +0200 | |
| changeset 42148 | d596e7bb251f | 
| parent 40964 | 482a8334ee9e | 
| child 42358 | b47d41d9f4b5 | 
| permissions | -rw-r--r-- | 
| 29755 | 1 | theory Prelim | 
| 2 | imports Base | |
| 3 | begin | |
| 18537 | 4 | |
| 5 | chapter {* Preliminaries *}
 | |
| 6 | ||
| 20429 | 7 | section {* Contexts \label{sec:context} *}
 | 
| 18537 | 8 | |
| 20429 | 9 | text {*
 | 
| 20451 | 10 | A logical context represents the background that is required for | 
| 11 | formulating statements and composing proofs. It acts as a medium to | |
| 12 | produce formal content, depending on earlier material (declarations, | |
| 13 | results etc.). | |
| 18537 | 14 | |
| 20451 | 15 | For example, derivations within the Isabelle/Pure logic can be | 
| 16 |   described as a judgment @{text "\<Gamma> \<turnstile>\<^sub>\<Theta> \<phi>"}, which means that a
 | |
| 20429 | 17 |   proposition @{text "\<phi>"} is derivable from hypotheses @{text "\<Gamma>"}
 | 
| 18 |   within the theory @{text "\<Theta>"}.  There are logical reasons for
 | |
| 20451 | 19 |   keeping @{text "\<Theta>"} and @{text "\<Gamma>"} separate: theories can be
 | 
| 20 | liberal about supporting type constructors and schematic | |
| 21 | polymorphism of constants and axioms, while the inner calculus of | |
| 22 |   @{text "\<Gamma> \<turnstile> \<phi>"} is strictly limited to Simple Type Theory (with
 | |
| 23 | fixed type variables in the assumptions). | |
| 18537 | 24 | |
| 20429 | 25 | \medskip Contexts and derivations are linked by the following key | 
| 26 | principles: | |
| 27 | ||
| 28 |   \begin{itemize}
 | |
| 29 | ||
| 30 | \item Transfer: monotonicity of derivations admits results to be | |
| 20451 | 31 |   transferred into a \emph{larger} context, i.e.\ @{text "\<Gamma> \<turnstile>\<^sub>\<Theta>
 | 
| 32 |   \<phi>"} implies @{text "\<Gamma>' \<turnstile>\<^sub>\<Theta>\<^sub>' \<phi>"} for contexts @{text "\<Theta>'
 | |
| 33 |   \<supseteq> \<Theta>"} and @{text "\<Gamma>' \<supseteq> \<Gamma>"}.
 | |
| 18537 | 34 | |
| 20429 | 35 | \item Export: discharge of hypotheses admits results to be exported | 
| 20451 | 36 |   into a \emph{smaller} context, i.e.\ @{text "\<Gamma>' \<turnstile>\<^sub>\<Theta> \<phi>"}
 | 
| 37 |   implies @{text "\<Gamma> \<turnstile>\<^sub>\<Theta> \<Delta> \<Longrightarrow> \<phi>"} where @{text "\<Gamma>' \<supseteq> \<Gamma>"} and
 | |
| 38 |   @{text "\<Delta> = \<Gamma>' - \<Gamma>"}.  Note that @{text "\<Theta>"} remains unchanged here,
 | |
| 39 |   only the @{text "\<Gamma>"} part is affected.
 | |
| 20429 | 40 | |
| 41 |   \end{itemize}
 | |
| 18537 | 42 | |
| 20451 | 43 | \medskip By modeling the main characteristics of the primitive | 
| 44 |   @{text "\<Theta>"} and @{text "\<Gamma>"} above, and abstracting over any
 | |
| 45 | particular logical content, we arrive at the fundamental notions of | |
| 46 |   \emph{theory context} and \emph{proof context} in Isabelle/Isar.
 | |
| 47 |   These implement a certain policy to manage arbitrary \emph{context
 | |
| 48 | data}. There is a strongly-typed mechanism to declare new kinds of | |
| 20429 | 49 | data at compile time. | 
| 18537 | 50 | |
| 20451 | 51 | The internal bootstrap process of Isabelle/Pure eventually reaches a | 
| 52 |   stage where certain data slots provide the logical content of @{text
 | |
| 53 |   "\<Theta>"} and @{text "\<Gamma>"} sketched above, but this does not stop there!
 | |
| 54 | Various additional data slots support all kinds of mechanisms that | |
| 55 | are not necessarily part of the core logic. | |
| 18537 | 56 | |
| 20429 | 57 | For example, there would be data for canonical introduction and | 
| 58 | elimination rules for arbitrary operators (depending on the | |
| 59 | object-logic and application), which enables users to perform | |
| 20451 | 60 |   standard proof steps implicitly (cf.\ the @{text "rule"} method
 | 
| 61 |   \cite{isabelle-isar-ref}).
 | |
| 18537 | 62 | |
| 20451 | 63 | \medskip Thus Isabelle/Isar is able to bring forth more and more | 
| 64 | concepts successively. In particular, an object-logic like | |
| 65 | Isabelle/HOL continues the Isabelle/Pure setup by adding specific | |
| 66 | components for automated reasoning (classical reasoner, tableau | |
| 67 | prover, structured induction etc.) and derived specification | |
| 68 | mechanisms (inductive predicates, recursive functions etc.). All of | |
| 69 | this is ultimately based on the generic data management by theory | |
| 70 | and proof contexts introduced here. | |
| 18537 | 71 | *} | 
| 72 | ||
| 73 | ||
| 74 | subsection {* Theory context \label{sec:context-theory} *}
 | |
| 75 | ||
| 34921 | 76 | text {* A \emph{theory} is a data container with explicit name and
 | 
| 77 | unique identifier. Theories are related by a (nominal) sub-theory | |
| 20451 | 78 | relation, which corresponds to the dependency graph of the original | 
| 79 | construction; each theory is derived from a certain sub-graph of | |
| 34921 | 80 | ancestor theories. To this end, the system maintains a set of | 
| 81 | symbolic ``identification stamps'' within each theory. | |
| 18537 | 82 | |
| 34921 | 83 | In order to avoid the full-scale overhead of explicit sub-theory | 
| 84 | identification of arbitrary intermediate stages, a theory is | |
| 85 |   switched into @{text "draft"} mode under certain circumstances.  A
 | |
| 86 | draft theory acts like a linear type, where updates invalidate | |
| 87 |   earlier versions.  An invalidated draft is called \emph{stale}.
 | |
| 20429 | 88 | |
| 34921 | 89 |   The @{text "checkpoint"} operation produces a safe stepping stone
 | 
| 90 | that will survive the next update without becoming stale: both the | |
| 91 | old and the new theory remain valid and are related by the | |
| 92 | sub-theory relation. Checkpointing essentially recovers purely | |
| 93 | functional theory values, at the expense of some extra internal | |
| 94 | bookkeeping. | |
| 20447 | 95 | |
| 96 |   The @{text "copy"} operation produces an auxiliary version that has
 | |
| 97 | the same data content, but is unrelated to the original: updates of | |
| 98 | the copy do not affect the original, neither does the sub-theory | |
| 99 | relation hold. | |
| 20429 | 100 | |
| 34921 | 101 |   The @{text "merge"} operation produces the least upper bound of two
 | 
| 102 | theories, which actually degenerates into absorption of one theory | |
| 103 | into the other (according to the nominal sub-theory relation). | |
| 104 | ||
| 105 |   The @{text "begin"} operation starts a new theory by importing
 | |
| 106 | several parent theories and entering a special mode of nameless | |
| 107 |   incremental updates, until the final @{text "end"} operation is
 | |
| 108 | performed. | |
| 109 | ||
| 20447 | 110 |   \medskip The example in \figref{fig:ex-theory} below shows a theory
 | 
| 20451 | 111 |   graph derived from @{text "Pure"}, with theory @{text "Length"}
 | 
| 112 |   importing @{text "Nat"} and @{text "List"}.  The body of @{text
 | |
| 113 | "Length"} consists of a sequence of updates, working mostly on | |
| 34921 | 114 | drafts internally, while transaction boundaries of Isar top-level | 
| 115 |   commands (\secref{sec:isar-toplevel}) are guaranteed to be safe
 | |
| 116 | checkpoints. | |
| 20447 | 117 | |
| 118 |   \begin{figure}[htb]
 | |
| 119 |   \begin{center}
 | |
| 20429 | 120 |   \begin{tabular}{rcccl}
 | 
| 20447 | 121 |         &            & @{text "Pure"} \\
 | 
| 122 |         &            & @{text "\<down>"} \\
 | |
| 123 |         &            & @{text "FOL"} \\
 | |
| 18537 | 124 | & $\swarrow$ & & $\searrow$ & \\ | 
| 21852 | 125 |   @{text "Nat"} &    &              &            & @{text "List"} \\
 | 
| 18537 | 126 | & $\searrow$ & & $\swarrow$ \\ | 
| 20447 | 127 |         &            & @{text "Length"} \\
 | 
| 26864 | 128 |         &            & \multicolumn{3}{l}{~~@{keyword "imports"}} \\
 | 
| 129 |         &            & \multicolumn{3}{l}{~~@{keyword "begin"}} \\
 | |
| 18537 | 130 | & & $\vdots$~~ \\ | 
| 20447 | 131 |         &            & @{text "\<bullet>"}~~ \\
 | 
| 132 | & & $\vdots$~~ \\ | |
| 133 |         &            & @{text "\<bullet>"}~~ \\
 | |
| 134 | & & $\vdots$~~ \\ | |
| 26864 | 135 |         &            & \multicolumn{3}{l}{~~@{command "end"}} \\
 | 
| 20429 | 136 |   \end{tabular}
 | 
| 20451 | 137 |   \caption{A theory definition depending on ancestors}\label{fig:ex-theory}
 | 
| 20447 | 138 |   \end{center}
 | 
| 139 |   \end{figure}
 | |
| 20451 | 140 | |
| 141 |   \medskip There is a separate notion of \emph{theory reference} for
 | |
| 142 | maintaining a live link to an evolving theory context: updates on | |
| 39821 | 143 | drafts are propagated automatically. Dynamic updating stops when | 
| 144 |   the next @{text "checkpoint"} is reached.
 | |
| 20451 | 145 | |
| 146 | Derived entities may store a theory reference in order to indicate | |
| 39821 | 147 | the formal context from which they are derived. This implicitly | 
| 148 | assumes monotonic reasoning, because the referenced context may | |
| 149 | become larger without further notice. | |
| 18537 | 150 | *} | 
| 151 | ||
| 20430 | 152 | text %mlref {*
 | 
| 20447 | 153 |   \begin{mldecls}
 | 
| 154 |   @{index_ML_type theory} \\
 | |
| 39837 | 155 |   @{index_ML Theory.eq_thy: "theory * theory -> bool"} \\
 | 
| 20447 | 156 |   @{index_ML Theory.subthy: "theory * theory -> bool"} \\
 | 
| 157 |   @{index_ML Theory.checkpoint: "theory -> theory"} \\
 | |
| 20547 | 158 |   @{index_ML Theory.copy: "theory -> theory"} \\
 | 
| 34921 | 159 |   @{index_ML Theory.merge: "theory * theory -> theory"} \\
 | 
| 160 |   @{index_ML Theory.begin_theory: "string -> theory list -> theory"} \\
 | |
| 39837 | 161 |   @{index_ML Theory.parents_of: "theory -> theory list"} \\
 | 
| 162 |   @{index_ML Theory.ancestors_of: "theory -> theory list"} \\
 | |
| 20547 | 163 |   \end{mldecls}
 | 
| 164 |   \begin{mldecls}
 | |
| 20447 | 165 |   @{index_ML_type theory_ref} \\
 | 
| 166 |   @{index_ML Theory.deref: "theory_ref -> theory"} \\
 | |
| 24137 
8d7896398147
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
 wenzelm parents: 
22869diff
changeset | 167 |   @{index_ML Theory.check_thy: "theory -> theory_ref"} \\
 | 
| 20447 | 168 |   \end{mldecls}
 | 
| 169 | ||
| 170 |   \begin{description}
 | |
| 171 | ||
| 39864 | 172 |   \item Type @{ML_type theory} represents theory contexts.  This is
 | 
| 39821 | 173 | essentially a linear type, with explicit runtime checking. | 
| 174 | Primitive theory operations destroy the original version, which then | |
| 175 | becomes ``stale''. This can be prevented by explicit checkpointing, | |
| 176 | which the system does at least at the boundary of toplevel command | |
| 177 |   transactions \secref{sec:isar-toplevel}.
 | |
| 20447 | 178 | |
| 39837 | 179 |   \item @{ML "Theory.eq_thy"}~@{text "(thy\<^sub>1, thy\<^sub>2)"} check strict
 | 
| 180 | identity of two theories. | |
| 181 | ||
| 34921 | 182 |   \item @{ML "Theory.subthy"}~@{text "(thy\<^sub>1, thy\<^sub>2)"} compares theories
 | 
| 183 | according to the intrinsic graph structure of the construction. | |
| 184 | This sub-theory relation is a nominal approximation of inclusion | |
| 185 |   (@{text "\<subseteq>"}) of the corresponding content (according to the
 | |
| 186 | semantics of the ML modules that implement the data). | |
| 20447 | 187 | |
| 188 |   \item @{ML "Theory.checkpoint"}~@{text "thy"} produces a safe
 | |
| 34921 | 189 |   stepping stone in the linear development of @{text "thy"}.  This
 | 
| 190 | changes the old theory, but the next update will result in two | |
| 191 | related, valid theories. | |
| 20447 | 192 | |
| 193 |   \item @{ML "Theory.copy"}~@{text "thy"} produces a variant of @{text
 | |
| 34921 | 194 | "thy"} with the same data. The copy is not related to the original, | 
| 195 | but the original is unchanged. | |
| 196 | ||
| 197 |   \item @{ML "Theory.merge"}~@{text "(thy\<^sub>1, thy\<^sub>2)"} absorbs one theory
 | |
| 198 |   into the other, without changing @{text "thy\<^sub>1"} or @{text "thy\<^sub>2"}.
 | |
| 199 | This version of ad-hoc theory merge fails for unrelated theories! | |
| 200 | ||
| 201 |   \item @{ML "Theory.begin_theory"}~@{text "name parents"} constructs
 | |
| 39825 
f9066b94bf07
eliminated fancy \ML logo for the sake of simpler source text (less dependence on LaTeX);
 wenzelm parents: 
39821diff
changeset | 202 | a new theory based on the given parents. This ML function is | 
| 34921 | 203 | normally not invoked directly. | 
| 20447 | 204 | |
| 39837 | 205 |   \item @{ML "Theory.parents_of"}~@{text "thy"} returns the direct
 | 
| 206 |   ancestors of @{text thy}.
 | |
| 207 | ||
| 208 |   \item @{ML "Theory.ancestors_of"}~@{text "thy"} returns all
 | |
| 209 |   ancestors of @{text thy} (not including @{text thy} itself).
 | |
| 210 | ||
| 39864 | 211 |   \item Type @{ML_type theory_ref} represents a sliding reference to
 | 
| 212 | an always valid theory; updates on the original are propagated | |
| 20447 | 213 | automatically. | 
| 214 | ||
| 24137 
8d7896398147
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
 wenzelm parents: 
22869diff
changeset | 215 |   \item @{ML "Theory.deref"}~@{text "thy_ref"} turns a @{ML_type
 | 
| 
8d7896398147
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
 wenzelm parents: 
22869diff
changeset | 216 |   "theory_ref"} into an @{ML_type "theory"} value.  As the referenced
 | 
| 
8d7896398147
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
 wenzelm parents: 
22869diff
changeset | 217 |   theory evolves monotonically over time, later invocations of @{ML
 | 
| 20451 | 218 | "Theory.deref"} may refer to a larger context. | 
| 20447 | 219 | |
| 24137 
8d7896398147
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
 wenzelm parents: 
22869diff
changeset | 220 |   \item @{ML "Theory.check_thy"}~@{text "thy"} produces a @{ML_type
 | 
| 
8d7896398147
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
 wenzelm parents: 
22869diff
changeset | 221 |   "theory_ref"} from a valid @{ML_type "theory"} value.
 | 
| 
8d7896398147
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
 wenzelm parents: 
22869diff
changeset | 222 | |
| 20447 | 223 |   \end{description}
 | 
| 20430 | 224 | *} | 
| 225 | ||
| 39832 | 226 | text %mlantiq {*
 | 
| 227 |   \begin{matharray}{rcl}
 | |
| 228 |   @{ML_antiquotation_def "theory"} & : & @{text ML_antiquotation} \\
 | |
| 229 |   \end{matharray}
 | |
| 230 | ||
| 231 |   \begin{rail}
 | |
| 40241 
56fad09655a5
discontinued obsolete ML antiquotation @{theory_ref};
 wenzelm parents: 
40153diff
changeset | 232 | 'theory' nameref? | 
| 39832 | 233 | ; | 
| 234 |   \end{rail}
 | |
| 235 | ||
| 236 |   \begin{description}
 | |
| 237 | ||
| 238 |   \item @{text "@{theory}"} refers to the background theory of the
 | |
| 239 | current context --- as abstract value. | |
| 240 | ||
| 241 |   \item @{text "@{theory A}"} refers to an explicitly named ancestor
 | |
| 242 |   theory @{text "A"} of the background theory of the current context
 | |
| 243 | --- as abstract value. | |
| 244 | ||
| 245 |   \end{description}
 | |
| 246 | *} | |
| 247 | ||
| 18537 | 248 | |
| 249 | subsection {* Proof context \label{sec:context-proof} *}
 | |
| 250 | ||
| 34921 | 251 | text {* A proof context is a container for pure data with a
 | 
| 39821 | 252 |   back-reference to the theory from which it is derived.  The @{text
 | 
| 253 | "init"} operation creates a proof context from a given theory. | |
| 34921 | 254 | Modifications to draft theories are propagated to the proof context | 
| 255 |   as usual, but there is also an explicit @{text "transfer"} operation
 | |
| 256 | to force resynchronization with more substantial updates to the | |
| 257 | underlying theory. | |
| 20429 | 258 | |
| 34921 | 259 | Entities derived in a proof context need to record logical | 
| 20447 | 260 | requirements explicitly, since there is no separate context | 
| 34921 | 261 | identification or symbolic inclusion as for theories. For example, | 
| 262 |   hypotheses used in primitive derivations (cf.\ \secref{sec:thms})
 | |
| 263 |   are recorded separately within the sequent @{text "\<Gamma> \<turnstile> \<phi>"}, just to
 | |
| 264 | make double sure. Results could still leak into an alien proof | |
| 265 | context due to programming errors, but Isabelle/Isar includes some | |
| 266 | extra validity checks in critical positions, notably at the end of a | |
| 267 | sub-proof. | |
| 20429 | 268 | |
| 20451 | 269 | Proof contexts may be manipulated arbitrarily, although the common | 
| 270 | discipline is to follow block structure as a mental model: a given | |
| 271 | context is extended consecutively, and results are exported back | |
| 34921 | 272 | into the original context. Note that an Isar proof state models | 
| 20451 | 273 | block-structured reasoning explicitly, using a stack of proof | 
| 34921 | 274 | contexts internally. For various technical reasons, the background | 
| 275 | theory of an Isar proof state must not be changed while the proof is | |
| 276 | still under construction! | |
| 18537 | 277 | *} | 
| 278 | ||
| 20449 | 279 | text %mlref {*
 | 
| 280 |   \begin{mldecls}
 | |
| 281 |   @{index_ML_type Proof.context} \\
 | |
| 36611 | 282 |   @{index_ML ProofContext.init_global: "theory -> Proof.context"} \\
 | 
| 20449 | 283 |   @{index_ML ProofContext.theory_of: "Proof.context -> theory"} \\
 | 
| 284 |   @{index_ML ProofContext.transfer: "theory -> Proof.context -> Proof.context"} \\
 | |
| 285 |   \end{mldecls}
 | |
| 286 | ||
| 287 |   \begin{description}
 | |
| 288 | ||
| 39864 | 289 |   \item Type @{ML_type Proof.context} represents proof contexts.
 | 
| 290 | Elements of this type are essentially pure values, with a sliding | |
| 291 | reference to the background theory. | |
| 20449 | 292 | |
| 36611 | 293 |   \item @{ML ProofContext.init_global}~@{text "thy"} produces a proof context
 | 
| 20449 | 294 |   derived from @{text "thy"}, initializing all data.
 | 
| 295 | ||
| 296 |   \item @{ML ProofContext.theory_of}~@{text "ctxt"} selects the
 | |
| 20451 | 297 |   background theory from @{text "ctxt"}, dereferencing its internal
 | 
| 298 |   @{ML_type theory_ref}.
 | |
| 20449 | 299 | |
| 300 |   \item @{ML ProofContext.transfer}~@{text "thy ctxt"} promotes the
 | |
| 301 |   background theory of @{text "ctxt"} to the super theory @{text
 | |
| 302 | "thy"}. | |
| 303 | ||
| 304 |   \end{description}
 | |
| 305 | *} | |
| 306 | ||
| 39832 | 307 | text %mlantiq {*
 | 
| 308 |   \begin{matharray}{rcl}
 | |
| 309 |   @{ML_antiquotation_def "context"} & : & @{text ML_antiquotation} \\
 | |
| 310 |   \end{matharray}
 | |
| 311 | ||
| 312 |   \begin{description}
 | |
| 313 | ||
| 314 |   \item @{text "@{context}"} refers to \emph{the} context at
 | |
| 315 | compile-time --- as abstract value. Independently of (local) theory | |
| 316 | or proof mode, this always produces a meaningful result. | |
| 317 | ||
| 318 | This is probably the most common antiquotation in interactive | |
| 319 | experimentation with ML inside Isar. | |
| 320 | ||
| 321 |   \end{description}
 | |
| 322 | *} | |
| 323 | ||
| 20430 | 324 | |
| 20451 | 325 | subsection {* Generic contexts \label{sec:generic-context} *}
 | 
| 20429 | 326 | |
| 20449 | 327 | text {*
 | 
| 328 | A generic context is the disjoint sum of either a theory or proof | |
| 20451 | 329 | context. Occasionally, this enables uniform treatment of generic | 
| 20450 | 330 | context data, typically extra-logical information. Operations on | 
| 20449 | 331 | generic contexts include the usual injections, partial selections, | 
| 332 | and combinators for lifting operations on either component of the | |
| 333 | disjoint sum. | |
| 334 | ||
| 335 |   Moreover, there are total operations @{text "theory_of"} and @{text
 | |
| 336 | "proof_of"} to convert a generic context into either kind: a theory | |
| 20451 | 337 | can always be selected from the sum, while a proof context might | 
| 34921 | 338 |   have to be constructed by an ad-hoc @{text "init"} operation, which
 | 
| 339 | incurs a small runtime overhead. | |
| 20449 | 340 | *} | 
| 20430 | 341 | |
| 20449 | 342 | text %mlref {*
 | 
| 343 |   \begin{mldecls}
 | |
| 344 |   @{index_ML_type Context.generic} \\
 | |
| 345 |   @{index_ML Context.theory_of: "Context.generic -> theory"} \\
 | |
| 346 |   @{index_ML Context.proof_of: "Context.generic -> Proof.context"} \\
 | |
| 347 |   \end{mldecls}
 | |
| 348 | ||
| 349 |   \begin{description}
 | |
| 20430 | 350 | |
| 39864 | 351 |   \item Type @{ML_type Context.generic} is the direct sum of @{ML_type
 | 
| 20451 | 352 |   "theory"} and @{ML_type "Proof.context"}, with the datatype
 | 
| 353 |   constructors @{ML "Context.Theory"} and @{ML "Context.Proof"}.
 | |
| 20449 | 354 | |
| 355 |   \item @{ML Context.theory_of}~@{text "context"} always produces a
 | |
| 356 |   theory from the generic @{text "context"}, using @{ML
 | |
| 357 | "ProofContext.theory_of"} as required. | |
| 358 | ||
| 359 |   \item @{ML Context.proof_of}~@{text "context"} always produces a
 | |
| 360 |   proof context from the generic @{text "context"}, using @{ML
 | |
| 36611 | 361 | "ProofContext.init_global"} as required (note that this re-initializes the | 
| 20451 | 362 | context data with each invocation). | 
| 20449 | 363 | |
| 364 |   \end{description}
 | |
| 365 | *} | |
| 20437 | 366 | |
| 20476 | 367 | |
| 368 | subsection {* Context data \label{sec:context-data} *}
 | |
| 20447 | 369 | |
| 33524 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 370 | text {* The main purpose of theory and proof contexts is to manage
 | 
| 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 371 | arbitrary (pure) data. New data types can be declared incrementally | 
| 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 372 | at compile time. There are separate declaration mechanisms for any | 
| 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 373 | of the three kinds of contexts: theory, proof, generic. | 
| 20449 | 374 | |
| 33524 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 375 |   \paragraph{Theory data} declarations need to implement the following
 | 
| 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 376 | SML signature: | 
| 20449 | 377 | |
| 378 | \medskip | |
| 379 |   \begin{tabular}{ll}
 | |
| 22869 | 380 |   @{text "\<type> T"} & representing type \\
 | 
| 381 |   @{text "\<val> empty: T"} & empty default value \\
 | |
| 382 |   @{text "\<val> extend: T \<rightarrow> T"} & re-initialize on import \\
 | |
| 383 |   @{text "\<val> merge: T \<times> T \<rightarrow> T"} & join on import \\
 | |
| 20449 | 384 |   \end{tabular}
 | 
| 385 | \medskip | |
| 386 | ||
| 39861 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 387 |   The @{text "empty"} value acts as initial default for \emph{any}
 | 
| 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 388 |   theory that does not declare actual data content; @{text "extend"}
 | 
| 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 389 |   is acts like a unitary version of @{text "merge"}.
 | 
| 20449 | 390 | |
| 34921 | 391 |   Implementing @{text "merge"} can be tricky.  The general idea is
 | 
| 392 |   that @{text "merge (data\<^sub>1, data\<^sub>2)"} inserts those parts of @{text
 | |
| 393 |   "data\<^sub>2"} into @{text "data\<^sub>1"} that are not yet present, while
 | |
| 394 |   keeping the general order of things.  The @{ML Library.merge}
 | |
| 395 | function on plain lists may serve as canonical template. | |
| 396 | ||
| 397 | Particularly note that shared parts of the data must not be | |
| 398 | duplicated by naive concatenation, or a theory graph that is like a | |
| 399 | chain of diamonds would cause an exponential blowup! | |
| 400 | ||
| 33524 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 401 |   \paragraph{Proof context data} declarations need to implement the
 | 
| 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 402 | following SML signature: | 
| 20449 | 403 | |
| 404 | \medskip | |
| 405 |   \begin{tabular}{ll}
 | |
| 22869 | 406 |   @{text "\<type> T"} & representing type \\
 | 
| 407 |   @{text "\<val> init: theory \<rightarrow> T"} & produce initial value \\
 | |
| 20449 | 408 |   \end{tabular}
 | 
| 409 | \medskip | |
| 410 | ||
| 39861 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 411 |   The @{text "init"} operation is supposed to produce a pure value
 | 
| 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 412 | from the given background theory and should be somehow | 
| 34921 | 413 | ``immediate''. Whenever a proof context is initialized, which | 
| 414 |   happens frequently, the the system invokes the @{text "init"}
 | |
| 39821 | 415 |   operation of \emph{all} theory data slots ever declared.  This also
 | 
| 416 | means that one needs to be economic about the total number of proof | |
| 417 | data declarations in the system, i.e.\ each ML module should declare | |
| 418 | at most one, sometimes two data slots for its internal use. | |
| 419 | Repeated data declarations to simulate a record type should be | |
| 420 | avoided! | |
| 20449 | 421 | |
| 20451 | 422 |   \paragraph{Generic data} provides a hybrid interface for both theory
 | 
| 33524 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 423 |   and proof data.  The @{text "init"} operation for proof contexts is
 | 
| 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 424 | predefined to select the current data value from the background | 
| 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 425 | theory. | 
| 20449 | 426 | |
| 39821 | 427 |   \bigskip Any of the above data declarations over type @{text "T"}
 | 
| 428 | result in an ML structure with the following signature: | |
| 20449 | 429 | |
| 430 | \medskip | |
| 431 |   \begin{tabular}{ll}
 | |
| 432 |   @{text "get: context \<rightarrow> T"} \\
 | |
| 433 |   @{text "put: T \<rightarrow> context \<rightarrow> context"} \\
 | |
| 434 |   @{text "map: (T \<rightarrow> T) \<rightarrow> context \<rightarrow> context"} \\
 | |
| 435 |   \end{tabular}
 | |
| 436 | \medskip | |
| 437 | ||
| 39861 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 438 | These other operations provide exclusive access for the particular | 
| 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 439 | kind of context (theory, proof, or generic context). This interface | 
| 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 440 | observes the ML discipline for types and scopes: there is no other | 
| 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 441 | way to access the corresponding data slot of a context. By keeping | 
| 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 442 | these operations private, an Isabelle/ML module may maintain | 
| 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 443 | abstract values authentically. *} | 
| 20447 | 444 | |
| 20450 | 445 | text %mlref {*
 | 
| 446 |   \begin{mldecls}
 | |
| 33524 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 447 |   @{index_ML_functor Theory_Data} \\
 | 
| 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 448 |   @{index_ML_functor Proof_Data} \\
 | 
| 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 449 |   @{index_ML_functor Generic_Data} \\
 | 
| 20450 | 450 |   \end{mldecls}
 | 
| 451 | ||
| 452 |   \begin{description}
 | |
| 453 | ||
| 33524 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 454 |   \item @{ML_functor Theory_Data}@{text "(spec)"} declares data for
 | 
| 20450 | 455 |   type @{ML_type theory} according to the specification provided as
 | 
| 20451 | 456 | argument structure. The resulting structure provides data init and | 
| 457 | access operations as described above. | |
| 20450 | 458 | |
| 33524 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 459 |   \item @{ML_functor Proof_Data}@{text "(spec)"} is analogous to
 | 
| 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 460 |   @{ML_functor Theory_Data} for type @{ML_type Proof.context}.
 | 
| 20450 | 461 | |
| 33524 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 462 |   \item @{ML_functor Generic_Data}@{text "(spec)"} is analogous to
 | 
| 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 463 |   @{ML_functor Theory_Data} for type @{ML_type Context.generic}.
 | 
| 20450 | 464 | |
| 465 |   \end{description}
 | |
| 466 | *} | |
| 467 | ||
| 34928 | 468 | text %mlex {*
 | 
| 469 | The following artificial example demonstrates theory | |
| 470 | data: we maintain a set of terms that are supposed to be wellformed | |
| 471 | wrt.\ the enclosing theory. The public interface is as follows: | |
| 472 | *} | |
| 473 | ||
| 474 | ML {*
 | |
| 475 | signature WELLFORMED_TERMS = | |
| 476 | sig | |
| 477 | val get: theory -> term list | |
| 478 | val add: term -> theory -> theory | |
| 479 | end; | |
| 480 | *} | |
| 481 | ||
| 39861 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 482 | text {* The implementation uses private theory data internally, and
 | 
| 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 483 | only exposes an operation that involves explicit argument checking | 
| 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 484 | wrt.\ the given theory. *} | 
| 34928 | 485 | |
| 486 | ML {*
 | |
| 487 | structure Wellformed_Terms: WELLFORMED_TERMS = | |
| 488 | struct | |
| 489 | ||
| 490 | structure Terms = Theory_Data | |
| 491 | ( | |
| 39687 | 492 | type T = term Ord_List.T; | 
| 34928 | 493 | val empty = []; | 
| 494 | val extend = I; | |
| 495 | fun merge (ts1, ts2) = | |
| 39687 | 496 | Ord_List.union Term_Ord.fast_term_ord ts1 ts2; | 
| 39861 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 497 | ); | 
| 34928 | 498 | |
| 499 | val get = Terms.get; | |
| 500 | ||
| 501 | fun add raw_t thy = | |
| 39821 | 502 | let | 
| 503 | val t = Sign.cert_term thy raw_t; | |
| 504 | in | |
| 505 | Terms.map (Ord_List.insert Term_Ord.fast_term_ord t) thy | |
| 506 | end; | |
| 34928 | 507 | |
| 508 | end; | |
| 509 | *} | |
| 510 | ||
| 39864 | 511 | text {* Type @{ML_type "term Ord_List.T"} is used for reasonably
 | 
| 512 | efficient representation of a set of terms: all operations are | |
| 513 | linear in the number of stored elements. Here we assume that users | |
| 514 | of this module do not care about the declaration order, since that | |
| 515 | data structure forces its own arrangement of elements. | |
| 34928 | 516 | |
| 40153 | 517 |   Observe how the @{ML_text merge} operation joins the data slots of
 | 
| 39687 | 518 |   the two constituents: @{ML Ord_List.union} prevents duplication of
 | 
| 34928 | 519 | common data from different branches, thus avoiding the danger of | 
| 39821 | 520 | exponential blowup. Plain list append etc.\ must never be used for | 
| 521 | theory data merges! | |
| 34928 | 522 | |
| 523 | \medskip Our intended invariant is achieved as follows: | |
| 524 |   \begin{enumerate}
 | |
| 525 | ||
| 526 |   \item @{ML Wellformed_Terms.add} only admits terms that have passed
 | |
| 527 |   the @{ML Sign.cert_term} check of the given theory at that point.
 | |
| 528 | ||
| 529 |   \item Wellformedness in the sense of @{ML Sign.cert_term} is
 | |
| 530 | monotonic wrt.\ the sub-theory relation. So our data can move | |
| 531 | upwards in the hierarchy (via extension or merges), and maintain | |
| 532 | wellformedness without further checks. | |
| 533 | ||
| 534 |   \end{enumerate}
 | |
| 535 | ||
| 536 | Note that all basic operations of the inference kernel (which | |
| 537 |   includes @{ML Sign.cert_term}) observe this monotonicity principle,
 | |
| 538 | but other user-space tools don't. For example, fully-featured | |
| 539 |   type-inference via @{ML Syntax.check_term} (cf.\
 | |
| 540 |   \secref{sec:term-check}) is not necessarily monotonic wrt.\ the
 | |
| 541 | background theory, since constraints of term constants can be | |
| 39821 | 542 | modified by later declarations, for example. | 
| 34928 | 543 | |
| 544 | In most cases, user-space context data does not have to take such | |
| 545 | invariants too seriously. The situation is different in the | |
| 546 | implementation of the inference kernel itself, which uses the very | |
| 547 | same data mechanisms for types, constants, axioms etc. | |
| 548 | *} | |
| 549 | ||
| 20447 | 550 | |
| 39865 | 551 | subsection {* Configuration options \label{sec:config-options} *}
 | 
| 552 | ||
| 553 | text {* A \emph{configuration option} is a named optional value of
 | |
| 554 | some basic type (Boolean, integer, string) that is stored in the | |
| 555 | context. It is a simple application of general context data | |
| 556 |   (\secref{sec:context-data}) that is sufficiently common to justify
 | |
| 557 | customized setup, which includes some concrete declarations for | |
| 558 | end-users using existing notation for attributes (cf.\ | |
| 559 |   \secref{sec:attributes}).
 | |
| 560 | ||
| 561 |   For example, the predefined configuration option @{attribute
 | |
| 562 | show_types} controls output of explicit type constraints for | |
| 39876 
1ff9bce085bd
preliminary material on "Concrete syntax and type-checking";
 wenzelm parents: 
39866diff
changeset | 563 |   variables in printed terms (cf.\ \secref{sec:read-print}).  Its
 | 
| 39865 | 564 | value can be modified within Isar text like this: | 
| 565 | *} | |
| 566 | ||
| 567 | declare [[show_types = false]] | |
| 568 |   -- {* declaration within (local) theory context *}
 | |
| 569 | ||
| 40964 | 570 | notepad | 
| 571 | begin | |
| 39865 | 572 | note [[show_types = true]] | 
| 573 |     -- {* declaration within proof (forward mode) *}
 | |
| 574 | term x | |
| 575 | ||
| 576 | have "x = x" | |
| 577 | using [[show_types = false]] | |
| 578 |       -- {* declaration within proof (backward mode) *}
 | |
| 579 | .. | |
| 40964 | 580 | end | 
| 39865 | 581 | |
| 582 | text {* Configuration options that are not set explicitly hold a
 | |
| 583 | default value that can depend on the application context. This | |
| 584 | allows to retrieve the value from another slot within the context, | |
| 585 | or fall back on a global preference mechanism, for example. | |
| 586 | ||
| 587 | The operations to declare configuration options and get/map their | |
| 588 | values are modeled as direct replacements for historic global | |
| 589 | references, only that the context is made explicit. This allows | |
| 590 | easy configuration of tools, without relying on the execution order | |
| 591 | as required for old-style mutable references. *} | |
| 592 | ||
| 593 | text %mlref {*
 | |
| 594 |   \begin{mldecls}
 | |
| 595 |   @{index_ML Config.get: "Proof.context -> 'a Config.T -> 'a"} \\
 | |
| 596 |   @{index_ML Config.map: "'a Config.T -> ('a -> 'a) -> Proof.context -> Proof.context"} \\
 | |
| 597 |   @{index_ML Attrib.config_bool: "string -> (Context.generic -> bool) ->
 | |
| 598 | bool Config.T * (theory -> theory)"} \\ | |
| 599 |   @{index_ML Attrib.config_int: "string -> (Context.generic -> int) ->
 | |
| 600 | int Config.T * (theory -> theory)"} \\ | |
| 40291 | 601 |   @{index_ML Attrib.config_real: "string -> (Context.generic -> real) ->
 | 
| 602 | real Config.T * (theory -> theory)"} \\ | |
| 39865 | 603 |   @{index_ML Attrib.config_string: "string -> (Context.generic -> string) ->
 | 
| 604 | string Config.T * (theory -> theory)"} \\ | |
| 605 |   \end{mldecls}
 | |
| 606 | ||
| 607 |   \begin{description}
 | |
| 608 | ||
| 609 |   \item @{ML Config.get}~@{text "ctxt config"} gets the value of
 | |
| 610 |   @{text "config"} in the given context.
 | |
| 611 | ||
| 612 |   \item @{ML Config.map}~@{text "config f ctxt"} updates the context
 | |
| 613 |   by updating the value of @{text "config"}.
 | |
| 614 | ||
| 615 |   \item @{text "(config, setup) ="}~@{ML Attrib.config_bool}~@{text
 | |
| 616 | "name default"} creates a named configuration option of type | |
| 617 |   @{ML_type bool}, with the given @{text "default"} depending on the
 | |
| 618 |   application context.  The resulting @{text "config"} can be used to
 | |
| 619 |   get/map its value in a given context.  The @{text "setup"} function
 | |
| 620 | needs to be applied to the theory initially, in order to make | |
| 621 | concrete declaration syntax available to the user. | |
| 622 | ||
| 40291 | 623 |   \item @{ML Attrib.config_int}, @{ML Attrib.config_real}, and @{ML
 | 
| 624 |   Attrib.config_string} work like @{ML Attrib.config_bool}, but for
 | |
| 625 |   types @{ML_type int} and @{ML_type string}, respectively.
 | |
| 39865 | 626 | |
| 627 |   \end{description}
 | |
| 628 | *} | |
| 629 | ||
| 630 | text %mlex {* The following example shows how to declare and use a
 | |
| 631 |   Boolean configuration option called @{text "my_flag"} with constant
 | |
| 632 |   default value @{ML false}.  *}
 | |
| 633 | ||
| 634 | ML {*
 | |
| 635 | val (my_flag, my_flag_setup) = | |
| 636 | Attrib.config_bool "my_flag" (K false) | |
| 637 | *} | |
| 638 | setup my_flag_setup | |
| 639 | ||
| 640 | text {* Now the user can refer to @{attribute my_flag} in
 | |
| 40126 | 641 | declarations, while ML tools can retrieve the current value from the | 
| 39865 | 642 |   context via @{ML Config.get}.  *}
 | 
| 643 | ||
| 39866 
5ec01d5acd0c
more robust examples: explicit @{assert} instead of unchecked output;
 wenzelm parents: 
39865diff
changeset | 644 | ML_val {* @{assert} (Config.get @{context} my_flag = false) *}
 | 
| 39865 | 645 | |
| 646 | declare [[my_flag = true]] | |
| 647 | ||
| 39866 
5ec01d5acd0c
more robust examples: explicit @{assert} instead of unchecked output;
 wenzelm parents: 
39865diff
changeset | 648 | ML_val {* @{assert} (Config.get @{context} my_flag = true) *}
 | 
| 39865 | 649 | |
| 40964 | 650 | notepad | 
| 651 | begin | |
| 39866 
5ec01d5acd0c
more robust examples: explicit @{assert} instead of unchecked output;
 wenzelm parents: 
39865diff
changeset | 652 |   {
 | 
| 
5ec01d5acd0c
more robust examples: explicit @{assert} instead of unchecked output;
 wenzelm parents: 
39865diff
changeset | 653 | note [[my_flag = false]] | 
| 
5ec01d5acd0c
more robust examples: explicit @{assert} instead of unchecked output;
 wenzelm parents: 
39865diff
changeset | 654 |     ML_val {* @{assert} (Config.get @{context} my_flag = false) *}
 | 
| 
5ec01d5acd0c
more robust examples: explicit @{assert} instead of unchecked output;
 wenzelm parents: 
39865diff
changeset | 655 | } | 
| 
5ec01d5acd0c
more robust examples: explicit @{assert} instead of unchecked output;
 wenzelm parents: 
39865diff
changeset | 656 |   ML_val {* @{assert} (Config.get @{context} my_flag = true) *}
 | 
| 40964 | 657 | end | 
| 39865 | 658 | |
| 40291 | 659 | text {* Here is another example involving ML type @{ML_type real}
 | 
| 660 | (floating-point numbers). *} | |
| 661 | ||
| 662 | ML {*
 | |
| 663 | val (airspeed_velocity, airspeed_velocity_setup) = | |
| 664 | Attrib.config_real "airspeed_velocity" (K 0.0) | |
| 665 | *} | |
| 666 | setup airspeed_velocity_setup | |
| 667 | ||
| 40296 | 668 | declare [[airspeed_velocity = 10]] | 
| 40291 | 669 | declare [[airspeed_velocity = 9.9]] | 
| 670 | ||
| 39865 | 671 | |
| 26872 | 672 | section {* Names \label{sec:names} *}
 | 
| 20451 | 673 | |
| 34925 | 674 | text {* In principle, a name is just a string, but there are various
 | 
| 675 | conventions for representing additional structure. For example, | |
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 676 |   ``@{text "Foo.bar.baz"}'' is considered as a long name consisting of
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 677 |   qualifier @{text "Foo.bar"} and base name @{text "baz"}.  The
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 678 | individual constituents of a name may have further substructure, | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 679 | e.g.\ the string ``\verb,\,\verb,<alpha>,'' encodes as a single | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 680 | symbol. | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 681 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 682 | \medskip Subsequently, we shall introduce specific categories of | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 683 | names. Roughly speaking these correspond to logical entities as | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 684 | follows: | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 685 |   \begin{itemize}
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 686 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 687 |   \item Basic names (\secref{sec:basic-name}): free and bound
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 688 | variables. | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 689 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 690 |   \item Indexed names (\secref{sec:indexname}): schematic variables.
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 691 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 692 |   \item Long names (\secref{sec:long-name}): constants of any kind
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 693 | (type constructors, term constants, other concepts defined in user | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 694 | space). Such entities are typically managed via name spaces | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 695 |   (\secref{sec:name-space}).
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 696 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 697 |   \end{itemize}
 | 
| 20451 | 698 | *} | 
| 20437 | 699 | |
| 700 | ||
| 39863 | 701 | subsection {* Strings of symbols \label{sec:symbols} *}
 | 
| 20437 | 702 | |
| 34925 | 703 | text {* A \emph{symbol} constitutes the smallest textual unit in
 | 
| 704 | Isabelle --- raw ML characters are normally not encountered at all! | |
| 705 | Isabelle strings consist of a sequence of symbols, represented as a | |
| 706 | packed string or an exploded list of strings. Each symbol is in | |
| 707 | itself a small string, which has either one of the following forms: | |
| 20437 | 708 | |
| 20451 | 709 |   \begin{enumerate}
 | 
| 20437 | 710 | |
| 37533 
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
 wenzelm parents: 
36611diff
changeset | 711 |   \item a single ASCII character ``@{text "c"}'', for example
 | 
| 
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
 wenzelm parents: 
36611diff
changeset | 712 | ``\verb,a,'', | 
| 
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
 wenzelm parents: 
36611diff
changeset | 713 | |
| 
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
 wenzelm parents: 
36611diff
changeset | 714 | \item a codepoint according to UTF8 (non-ASCII byte sequence), | 
| 20437 | 715 | |
| 20488 | 716 |   \item a regular symbol ``\verb,\,\verb,<,@{text "ident"}\verb,>,'',
 | 
| 20476 | 717 | for example ``\verb,\,\verb,<alpha>,'', | 
| 20437 | 718 | |
| 20488 | 719 |   \item a control symbol ``\verb,\,\verb,<^,@{text "ident"}\verb,>,'',
 | 
| 20476 | 720 | for example ``\verb,\,\verb,<^bold>,'', | 
| 20437 | 721 | |
| 20488 | 722 |   \item a raw symbol ``\verb,\,\verb,<^raw:,@{text text}\verb,>,''
 | 
| 34925 | 723 |   where @{text text} consists of printable characters excluding
 | 
| 20476 | 724 | ``\verb,.,'' and ``\verb,>,'', for example | 
| 725 |   ``\verb,\,\verb,<^raw:$\sum_{i = 1}^n$>,'',
 | |
| 20437 | 726 | |
| 20488 | 727 |   \item a numbered raw control symbol ``\verb,\,\verb,<^raw,@{text
 | 
| 20476 | 728 |   n}\verb,>, where @{text n} consists of digits, for example
 | 
| 20451 | 729 | ``\verb,\,\verb,<^raw42>,''. | 
| 20437 | 730 | |
| 20451 | 731 |   \end{enumerate}
 | 
| 20437 | 732 | |
| 39861 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 733 |   The @{text "ident"} syntax for symbol names is @{text "letter
 | 
| 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 734 |   (letter | digit)\<^sup>*"}, where @{text "letter = A..Za..z"} and @{text
 | 
| 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 735 | "digit = 0..9"}. There are infinitely many regular symbols and | 
| 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 736 | control symbols, but a fixed collection of standard symbols is | 
| 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 737 | treated specifically. For example, ``\verb,\,\verb,<alpha>,'' is | 
| 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 738 | classified as a letter, which means it may occur within regular | 
| 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 739 | Isabelle identifiers. | 
| 20437 | 740 | |
| 37533 
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
 wenzelm parents: 
36611diff
changeset | 741 | The character set underlying Isabelle symbols is 7-bit ASCII, but | 
| 
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
 wenzelm parents: 
36611diff
changeset | 742 | 8-bit character sequences are passed-through unchanged. Unicode/UCS | 
| 
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
 wenzelm parents: 
36611diff
changeset | 743 | data in UTF-8 encoding is processed in a non-strict fashion, such | 
| 
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
 wenzelm parents: 
36611diff
changeset | 744 | that well-formed code sequences are recognized | 
| 
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
 wenzelm parents: 
36611diff
changeset | 745 |   accordingly.\footnote{Note that ISO-Latin-1 differs from UTF-8 only
 | 
| 
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
 wenzelm parents: 
36611diff
changeset | 746 | in some special punctuation characters that even have replacements | 
| 
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
 wenzelm parents: 
36611diff
changeset | 747 | within the standard collection of Isabelle symbols. Text consisting | 
| 
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
 wenzelm parents: 
36611diff
changeset | 748 | of ASCII plus accented letters can be processed in either encoding.} | 
| 
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
 wenzelm parents: 
36611diff
changeset | 749 | Unicode provides its own collection of mathematical symbols, but | 
| 
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
 wenzelm parents: 
36611diff
changeset | 750 | within the core Isabelle/ML world there is no link to the standard | 
| 
d775bd70f571
explicit treatment of UTF8 character sequences as Isabelle symbols;
 wenzelm parents: 
36611diff
changeset | 751 | collection of Isabelle regular symbols. | 
| 20476 | 752 | |
| 753 | \medskip Output of Isabelle symbols depends on the print mode | |
| 29758 | 754 |   (\secref{print-mode}).  For example, the standard {\LaTeX} setup of
 | 
| 755 | the Isabelle document preparation system would present | |
| 20451 | 756 |   ``\verb,\,\verb,<alpha>,'' as @{text "\<alpha>"}, and
 | 
| 757 |   ``\verb,\,\verb,<^bold>,\verb,\,\verb,<alpha>,'' as @{text
 | |
| 34925 | 758 | "\<^bold>\<alpha>"}. On-screen rendering usually works by mapping a finite | 
| 759 | subset of Isabelle symbols to suitable Unicode characters. | |
| 20451 | 760 | *} | 
| 20437 | 761 | |
| 762 | text %mlref {*
 | |
| 763 |   \begin{mldecls}
 | |
| 34921 | 764 |   @{index_ML_type "Symbol.symbol": string} \\
 | 
| 20437 | 765 |   @{index_ML Symbol.explode: "string -> Symbol.symbol list"} \\
 | 
| 766 |   @{index_ML Symbol.is_letter: "Symbol.symbol -> bool"} \\
 | |
| 767 |   @{index_ML Symbol.is_digit: "Symbol.symbol -> bool"} \\
 | |
| 768 |   @{index_ML Symbol.is_quasi: "Symbol.symbol -> bool"} \\
 | |
| 20547 | 769 |   @{index_ML Symbol.is_blank: "Symbol.symbol -> bool"} \\
 | 
| 770 |   \end{mldecls}
 | |
| 771 |   \begin{mldecls}
 | |
| 20437 | 772 |   @{index_ML_type "Symbol.sym"} \\
 | 
| 773 |   @{index_ML Symbol.decode: "Symbol.symbol -> Symbol.sym"} \\
 | |
| 774 |   \end{mldecls}
 | |
| 775 | ||
| 776 |   \begin{description}
 | |
| 777 | ||
| 39864 | 778 |   \item Type @{ML_type "Symbol.symbol"} represents individual Isabelle
 | 
| 34921 | 779 | symbols. | 
| 20437 | 780 | |
| 20476 | 781 |   \item @{ML "Symbol.explode"}~@{text "str"} produces a symbol list
 | 
| 39821 | 782 |   from the packed form.  This function supersedes @{ML
 | 
| 20476 | 783 | "String.explode"} for virtually all purposes of manipulating text in | 
| 34925 | 784 |   Isabelle!\footnote{The runtime overhead for exploded strings is
 | 
| 785 | mainly that of the list structure: individual symbols that happen to | |
| 39821 | 786 | be a singleton string do not require extra memory in Poly/ML.} | 
| 20437 | 787 | |
| 788 |   \item @{ML "Symbol.is_letter"}, @{ML "Symbol.is_digit"}, @{ML
 | |
| 20476 | 789 |   "Symbol.is_quasi"}, @{ML "Symbol.is_blank"} classify standard
 | 
| 790 | symbols according to fixed syntactic conventions of Isabelle, cf.\ | |
| 791 |   \cite{isabelle-isar-ref}.
 | |
| 20437 | 792 | |
| 39864 | 793 |   \item Type @{ML_type "Symbol.sym"} is a concrete datatype that
 | 
| 794 | represents the different kinds of symbols explicitly, with | |
| 795 |   constructors @{ML "Symbol.Char"}, @{ML "Symbol.Sym"}, @{ML
 | |
| 796 |   "Symbol.UTF8"}, @{ML "Symbol.Ctrl"}, @{ML "Symbol.Raw"}.
 | |
| 20437 | 797 | |
| 798 |   \item @{ML "Symbol.decode"} converts the string representation of a
 | |
| 20451 | 799 | symbol into the datatype version. | 
| 20437 | 800 | |
| 801 |   \end{description}
 | |
| 34925 | 802 | |
| 803 |   \paragraph{Historical note.} In the original SML90 standard the
 | |
| 40628 | 804 |   primitive ML type @{ML_type char} did not exists, and the @{ML_text
 | 
| 34925 | 805 | "explode: string -> string list"} operation would produce a list of | 
| 40628 | 806 |   singleton strings as does @{ML "raw_explode: string -> string list"}
 | 
| 807 | in Isabelle/ML today. When SML97 came out, Isabelle did not adopt | |
| 808 | its slightly anachronistic 8-bit characters, but the idea of | |
| 809 | exploding a string into a list of small strings was extended to | |
| 810 | ``symbols'' as explained above. Thus Isabelle sources can refer to | |
| 811 | an infinite store of user-defined symbols, without having to worry | |
| 812 | about the multitude of Unicode encodings. *} | |
| 20437 | 813 | |
| 814 | ||
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 815 | subsection {* Basic names \label{sec:basic-name} *}
 | 
| 20476 | 816 | |
| 817 | text {*
 | |
| 818 |   A \emph{basic name} essentially consists of a single Isabelle
 | |
| 819 | identifier. There are conventions to mark separate classes of basic | |
| 29761 | 820 | names, by attaching a suffix of underscores: one underscore means | 
| 821 |   \emph{internal name}, two underscores means \emph{Skolem name},
 | |
| 822 |   three underscores means \emph{internal Skolem name}.
 | |
| 20476 | 823 | |
| 824 |   For example, the basic name @{text "foo"} has the internal version
 | |
| 825 |   @{text "foo_"}, with Skolem versions @{text "foo__"} and @{text
 | |
| 826 | "foo___"}, respectively. | |
| 827 | ||
| 20488 | 828 | These special versions provide copies of the basic name space, apart | 
| 829 | from anything that normally appears in the user text. For example, | |
| 830 | system generated variables in Isar proof contexts are usually marked | |
| 34926 | 831 |   as internal, which prevents mysterious names like @{text "xaa"} to
 | 
| 832 | appear in human-readable text. | |
| 20476 | 833 | |
| 20488 | 834 | \medskip Manipulating binding scopes often requires on-the-fly | 
| 835 |   renamings.  A \emph{name context} contains a collection of already
 | |
| 836 |   used names.  The @{text "declare"} operation adds names to the
 | |
| 837 | context. | |
| 20476 | 838 | |
| 20488 | 839 |   The @{text "invents"} operation derives a number of fresh names from
 | 
| 840 | a given starting point. For example, the first three names derived | |
| 841 |   from @{text "a"} are @{text "a"}, @{text "b"}, @{text "c"}.
 | |
| 20476 | 842 | |
| 843 |   The @{text "variants"} operation produces fresh names by
 | |
| 20488 | 844 |   incrementing tentative names as base-26 numbers (with digits @{text
 | 
| 845 |   "a..z"}) until all clashes are resolved.  For example, name @{text
 | |
| 846 |   "foo"} results in variants @{text "fooa"}, @{text "foob"}, @{text
 | |
| 847 |   "fooc"}, \dots, @{text "fooaa"}, @{text "fooab"} etc.; each renaming
 | |
| 848 | step picks the next unused variant from this sequence. | |
| 20476 | 849 | *} | 
| 850 | ||
| 851 | text %mlref {*
 | |
| 852 |   \begin{mldecls}
 | |
| 853 |   @{index_ML Name.internal: "string -> string"} \\
 | |
| 20547 | 854 |   @{index_ML Name.skolem: "string -> string"} \\
 | 
| 855 |   \end{mldecls}
 | |
| 856 |   \begin{mldecls}
 | |
| 20476 | 857 |   @{index_ML_type Name.context} \\
 | 
| 858 |   @{index_ML Name.context: Name.context} \\
 | |
| 859 |   @{index_ML Name.declare: "string -> Name.context -> Name.context"} \\
 | |
| 860 |   @{index_ML Name.invents: "Name.context -> string -> int -> string list"} \\
 | |
| 861 |   @{index_ML Name.variants: "string list -> Name.context -> string list * Name.context"} \\
 | |
| 862 |   \end{mldecls}
 | |
| 34926 | 863 |   \begin{mldecls}
 | 
| 864 |   @{index_ML Variable.names_of: "Proof.context -> Name.context"} \\
 | |
| 865 |   \end{mldecls}
 | |
| 20476 | 866 | |
| 867 |   \begin{description}
 | |
| 868 | ||
| 869 |   \item @{ML Name.internal}~@{text "name"} produces an internal name
 | |
| 870 | by adding one underscore. | |
| 871 | ||
| 872 |   \item @{ML Name.skolem}~@{text "name"} produces a Skolem name by
 | |
| 873 | adding two underscores. | |
| 874 | ||
| 39864 | 875 |   \item Type @{ML_type Name.context} represents the context of already
 | 
| 876 |   used names; the initial value is @{ML "Name.context"}.
 | |
| 20476 | 877 | |
| 20488 | 878 |   \item @{ML Name.declare}~@{text "name"} enters a used name into the
 | 
| 879 | context. | |
| 20437 | 880 | |
| 20488 | 881 |   \item @{ML Name.invents}~@{text "context name n"} produces @{text
 | 
| 882 |   "n"} fresh names derived from @{text "name"}.
 | |
| 883 | ||
| 884 |   \item @{ML Name.variants}~@{text "names context"} produces fresh
 | |
| 29761 | 885 |   variants of @{text "names"}; the result is entered into the context.
 | 
| 20476 | 886 | |
| 34926 | 887 |   \item @{ML Variable.names_of}~@{text "ctxt"} retrieves the context
 | 
| 888 | of declared type and term variable names. Projecting a proof | |
| 889 | context down to a primitive name context is occasionally useful when | |
| 890 | invoking lower-level operations. Regular management of ``fresh | |
| 891 |   variables'' is done by suitable operations of structure @{ML_struct
 | |
| 892 | Variable}, which is also able to provide an official status of | |
| 893 | ``locally fixed variable'' within the logical environment (cf.\ | |
| 894 |   \secref{sec:variables}).
 | |
| 895 | ||
| 20476 | 896 |   \end{description}
 | 
| 897 | *} | |
| 898 | ||
| 39857 | 899 | text %mlex {* The following simple examples demonstrate how to produce
 | 
| 900 |   fresh names from the initial @{ML Name.context}. *}
 | |
| 901 | ||
| 902 | ML {*
 | |
| 39866 
5ec01d5acd0c
more robust examples: explicit @{assert} instead of unchecked output;
 wenzelm parents: 
39865diff
changeset | 903 | val list1 = Name.invents Name.context "a" 5; | 
| 
5ec01d5acd0c
more robust examples: explicit @{assert} instead of unchecked output;
 wenzelm parents: 
39865diff
changeset | 904 |   @{assert} (list1 = ["a", "b", "c", "d", "e"]);
 | 
| 
5ec01d5acd0c
more robust examples: explicit @{assert} instead of unchecked output;
 wenzelm parents: 
39865diff
changeset | 905 | |
| 
5ec01d5acd0c
more robust examples: explicit @{assert} instead of unchecked output;
 wenzelm parents: 
39865diff
changeset | 906 | val list2 = | 
| 
5ec01d5acd0c
more robust examples: explicit @{assert} instead of unchecked output;
 wenzelm parents: 
39865diff
changeset | 907 | #1 (Name.variants ["x", "x", "a", "a", "'a", "'a"] Name.context); | 
| 
5ec01d5acd0c
more robust examples: explicit @{assert} instead of unchecked output;
 wenzelm parents: 
39865diff
changeset | 908 |   @{assert} (list2 = ["x", "xa", "a", "aa", "'a", "'aa"]);
 | 
| 39857 | 909 | *} | 
| 910 | ||
| 40126 | 911 | text {* \medskip The same works relatively to the formal context as
 | 
| 39861 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 912 | follows. *} | 
| 39857 | 913 | |
| 914 | locale ex = fixes a b c :: 'a | |
| 915 | begin | |
| 916 | ||
| 917 | ML {*
 | |
| 918 |   val names = Variable.names_of @{context};
 | |
| 39866 
5ec01d5acd0c
more robust examples: explicit @{assert} instead of unchecked output;
 wenzelm parents: 
39865diff
changeset | 919 | |
| 
5ec01d5acd0c
more robust examples: explicit @{assert} instead of unchecked output;
 wenzelm parents: 
39865diff
changeset | 920 | val list1 = Name.invents names "a" 5; | 
| 
5ec01d5acd0c
more robust examples: explicit @{assert} instead of unchecked output;
 wenzelm parents: 
39865diff
changeset | 921 |   @{assert} (list1 = ["d", "e", "f", "g", "h"]);
 | 
| 
5ec01d5acd0c
more robust examples: explicit @{assert} instead of unchecked output;
 wenzelm parents: 
39865diff
changeset | 922 | |
| 
5ec01d5acd0c
more robust examples: explicit @{assert} instead of unchecked output;
 wenzelm parents: 
39865diff
changeset | 923 | val list2 = | 
| 
5ec01d5acd0c
more robust examples: explicit @{assert} instead of unchecked output;
 wenzelm parents: 
39865diff
changeset | 924 | #1 (Name.variants ["x", "x", "a", "a", "'a", "'a"] names); | 
| 
5ec01d5acd0c
more robust examples: explicit @{assert} instead of unchecked output;
 wenzelm parents: 
39865diff
changeset | 925 |   @{assert} (list2 = ["x", "xa", "aa", "ab", "'aa", "'ab"]);
 | 
| 39857 | 926 | *} | 
| 927 | ||
| 928 | end | |
| 929 | ||
| 20476 | 930 | |
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 931 | subsection {* Indexed names \label{sec:indexname} *}
 | 
| 20476 | 932 | |
| 933 | text {*
 | |
| 934 |   An \emph{indexed name} (or @{text "indexname"}) is a pair of a basic
 | |
| 20488 | 935 | name and a natural number. This representation allows efficient | 
| 936 | renaming by incrementing the second component only. The canonical | |
| 937 | way to rename two collections of indexnames apart from each other is | |
| 938 |   this: determine the maximum index @{text "maxidx"} of the first
 | |
| 939 | collection, then increment all indexes of the second collection by | |
| 940 |   @{text "maxidx + 1"}; the maximum index of an empty collection is
 | |
| 941 |   @{text "-1"}.
 | |
| 20476 | 942 | |
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 943 | Occasionally, basic names are injected into the same pair type of | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 944 |   indexed names: then @{text "(x, -1)"} is used to encode the basic
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 945 |   name @{text "x"}.
 | 
| 20488 | 946 | |
| 947 | \medskip Isabelle syntax observes the following rules for | |
| 948 |   representing an indexname @{text "(x, i)"} as a packed string:
 | |
| 20476 | 949 | |
| 950 |   \begin{itemize}
 | |
| 951 | ||
| 20479 | 952 |   \item @{text "?x"} if @{text "x"} does not end with a digit and @{text "i = 0"},
 | 
| 20476 | 953 | |
| 954 |   \item @{text "?xi"} if @{text "x"} does not end with a digit,
 | |
| 955 | ||
| 20488 | 956 |   \item @{text "?x.i"} otherwise.
 | 
| 20476 | 957 | |
| 958 |   \end{itemize}
 | |
| 20470 | 959 | |
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 960 | Indexnames may acquire large index numbers after several maxidx | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 961 | shifts have been applied. Results are usually normalized towards | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 962 |   @{text "0"} at certain checkpoints, notably at the end of a proof.
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 963 | This works by producing variants of the corresponding basic name | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 964 |   components.  For example, the collection @{text "?x1, ?x7, ?x42"}
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 965 |   becomes @{text "?x, ?xa, ?xb"}.
 | 
| 20476 | 966 | *} | 
| 967 | ||
| 968 | text %mlref {*
 | |
| 969 |   \begin{mldecls}
 | |
| 39861 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 970 |   @{index_ML_type indexname: "string * int"} \\
 | 
| 20476 | 971 |   \end{mldecls}
 | 
| 972 | ||
| 973 |   \begin{description}
 | |
| 974 | ||
| 39864 | 975 |   \item Type @{ML_type indexname} represents indexed names.  This is
 | 
| 976 |   an abbreviation for @{ML_type "string * int"}.  The second component
 | |
| 977 |   is usually non-negative, except for situations where @{text "(x,
 | |
| 978 | -1)"} is used to inject basic names into this type. Other negative | |
| 34926 | 979 | indexes should not be used. | 
| 20476 | 980 | |
| 981 |   \end{description}
 | |
| 982 | *} | |
| 983 | ||
| 984 | ||
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 985 | subsection {* Long names \label{sec:long-name} *}
 | 
| 20476 | 986 | |
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 987 | text {* A \emph{long name} consists of a sequence of non-empty name
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 988 | components. The packed representation uses a dot as separator, as | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 989 |   in ``@{text "A.b.c"}''.  The last component is called \emph{base
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 990 |   name}, the remaining prefix is called \emph{qualifier} (which may be
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 991 | empty). The qualifier can be understood as the access path to the | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 992 | named entity while passing through some nested block-structure, | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 993 | although our free-form long names do not really enforce any strict | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 994 | discipline. | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 995 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 996 |   For example, an item named ``@{text "A.b.c"}'' may be understood as
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 997 |   a local entity @{text "c"}, within a local structure @{text "b"},
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 998 |   within a global structure @{text "A"}.  In practice, long names
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 999 | usually represent 1--3 levels of qualification. User ML code should | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1000 | not make any assumptions about the particular structure of long | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1001 | names! | 
| 20437 | 1002 | |
| 20476 | 1003 | The empty name is commonly used as an indication of unnamed | 
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1004 | entities, or entities that are not entered into the corresponding | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1005 | name space, whenever this makes any sense. The basic operations on | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1006 | long names map empty names again to empty names. | 
| 20437 | 1007 | *} | 
| 1008 | ||
| 20476 | 1009 | text %mlref {*
 | 
| 1010 |   \begin{mldecls}
 | |
| 30365 | 1011 |   @{index_ML Long_Name.base_name: "string -> string"} \\
 | 
| 1012 |   @{index_ML Long_Name.qualifier: "string -> string"} \\
 | |
| 1013 |   @{index_ML Long_Name.append: "string -> string -> string"} \\
 | |
| 1014 |   @{index_ML Long_Name.implode: "string list -> string"} \\
 | |
| 1015 |   @{index_ML Long_Name.explode: "string -> string list"} \\
 | |
| 20547 | 1016 |   \end{mldecls}
 | 
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1017 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1018 |   \begin{description}
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1019 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1020 |   \item @{ML Long_Name.base_name}~@{text "name"} returns the base name
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1021 | of a long name. | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1022 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1023 |   \item @{ML Long_Name.qualifier}~@{text "name"} returns the qualifier
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1024 | of a long name. | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1025 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1026 |   \item @{ML Long_Name.append}~@{text "name\<^isub>1 name\<^isub>2"} appends two long
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1027 | names. | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1028 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1029 |   \item @{ML Long_Name.implode}~@{text "names"} and @{ML
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1030 |   Long_Name.explode}~@{text "name"} convert between the packed string
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1031 | representation and the explicit list form of long names. | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1032 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1033 |   \end{description}
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1034 | *} | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1035 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1036 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1037 | subsection {* Name spaces \label{sec:name-space} *}
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1038 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1039 | text {* A @{text "name space"} manages a collection of long names,
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1040 | together with a mapping between partially qualified external names | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1041 | and fully qualified internal names (in both directions). Note that | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1042 |   the corresponding @{text "intern"} and @{text "extern"} operations
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1043 |   are mostly used for parsing and printing only!  The @{text
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1044 | "declare"} operation augments a name space according to the accesses | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1045 | determined by a given binding, and a naming policy from the context. | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1046 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1047 |   \medskip A @{text "binding"} specifies details about the prospective
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1048 | long name of a newly introduced formal entity. It consists of a | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1049 | base name, prefixes for qualification (separate ones for system | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1050 | infrastructure and user-space mechanisms), a slot for the original | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1051 | source position, and some additional flags. | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1052 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1053 |   \medskip A @{text "naming"} provides some additional details for
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1054 | producing a long name from a binding. Normally, the naming is | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1055 |   implicit in the theory or proof context.  The @{text "full"}
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1056 | operation (and its variants for different context types) produces a | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1057 | fully qualified internal name to be entered into a name space. The | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1058 | main equation of this ``chemical reaction'' when binding new | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1059 | entities in a context is as follows: | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1060 | |
| 39861 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 1061 | \medskip | 
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1062 |   \begin{tabular}{l}
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1063 |   @{text "binding + naming \<longrightarrow> long name + name space accesses"}
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1064 |   \end{tabular}
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1065 | |
| 39861 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 1066 | \bigskip As a general principle, there is a separate name space for | 
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1067 | each kind of formal entity, e.g.\ fact, logical constant, type | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1068 | constructor, type class. It is usually clear from the occurrence in | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1069 | concrete syntax (or from the scope) which kind of entity a name | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1070 |   refers to.  For example, the very same name @{text "c"} may be used
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1071 | uniformly for a constant, type constructor, and type class. | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1072 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1073 | There are common schemes to name derived entities systematically | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1074 | according to the name of the main logical entity involved, e.g.\ | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1075 |   fact @{text "c.intro"} for a canonical introduction rule related to
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1076 |   constant @{text "c"}.  This technique of mapping names from one
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1077 | space into another requires some care in order to avoid conflicts. | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1078 | In particular, theorem names derived from a type constructor or type | 
| 39839 | 1079 | class should get an additional suffix in addition to the usual | 
| 1080 | qualification. This leads to the following conventions for derived | |
| 1081 | names: | |
| 1082 | ||
| 1083 | \medskip | |
| 1084 |   \begin{tabular}{ll}
 | |
| 1085 | logical entity & fact name \\\hline | |
| 1086 |   constant @{text "c"} & @{text "c.intro"} \\
 | |
| 1087 |   type @{text "c"} & @{text "c_type.intro"} \\
 | |
| 1088 |   class @{text "c"} & @{text "c_class.intro"} \\
 | |
| 1089 |   \end{tabular}
 | |
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1090 | *} | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1091 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1092 | text %mlref {*
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1093 |   \begin{mldecls}
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1094 |   @{index_ML_type binding} \\
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1095 |   @{index_ML Binding.empty: binding} \\
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1096 |   @{index_ML Binding.name: "string -> binding"} \\
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1097 |   @{index_ML Binding.qualify: "bool -> string -> binding -> binding"} \\
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1098 |   @{index_ML Binding.prefix: "bool -> string -> binding -> binding"} \\
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1099 |   @{index_ML Binding.conceal: "binding -> binding"} \\
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1100 |   @{index_ML Binding.str_of: "binding -> string"} \\
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1101 |   \end{mldecls}
 | 
| 20547 | 1102 |   \begin{mldecls}
 | 
| 33174 | 1103 |   @{index_ML_type Name_Space.naming} \\
 | 
| 1104 |   @{index_ML Name_Space.default_naming: Name_Space.naming} \\
 | |
| 1105 |   @{index_ML Name_Space.add_path: "string -> Name_Space.naming -> Name_Space.naming"} \\
 | |
| 1106 |   @{index_ML Name_Space.full_name: "Name_Space.naming -> binding -> string"} \\
 | |
| 20547 | 1107 |   \end{mldecls}
 | 
| 1108 |   \begin{mldecls}
 | |
| 33174 | 1109 |   @{index_ML_type Name_Space.T} \\
 | 
| 1110 |   @{index_ML Name_Space.empty: "string -> Name_Space.T"} \\
 | |
| 1111 |   @{index_ML Name_Space.merge: "Name_Space.T * Name_Space.T -> Name_Space.T"} \\
 | |
| 1112 |   @{index_ML Name_Space.declare: "bool -> Name_Space.naming -> binding -> Name_Space.T ->
 | |
| 1113 | string * Name_Space.T"} \\ | |
| 1114 |   @{index_ML Name_Space.intern: "Name_Space.T -> string -> string"} \\
 | |
| 1115 |   @{index_ML Name_Space.extern: "Name_Space.T -> string -> string"} \\
 | |
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1116 |   @{index_ML Name_Space.is_concealed: "Name_Space.T -> string -> bool"}
 | 
| 20476 | 1117 |   \end{mldecls}
 | 
| 20437 | 1118 | |
| 20476 | 1119 |   \begin{description}
 | 
| 1120 | ||
| 39864 | 1121 |   \item Type @{ML_type binding} represents the abstract concept of
 | 
| 1122 | name bindings. | |
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1123 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1124 |   \item @{ML Binding.empty} is the empty binding.
 | 
| 20476 | 1125 | |
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1126 |   \item @{ML Binding.name}~@{text "name"} produces a binding with base
 | 
| 39832 | 1127 |   name @{text "name"}.  Note that this lacks proper source position
 | 
| 1128 |   information; see also the ML antiquotation @{ML_antiquotation
 | |
| 1129 | binding}. | |
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1130 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1131 |   \item @{ML Binding.qualify}~@{text "mandatory name binding"}
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1132 |   prefixes qualifier @{text "name"} to @{text "binding"}.  The @{text
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1133 | "mandatory"} flag tells if this name component always needs to be | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1134 |   given in name space accesses --- this is mostly @{text "false"} in
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1135 | practice. Note that this part of qualification is typically used in | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1136 | derived specification mechanisms. | 
| 20437 | 1137 | |
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1138 |   \item @{ML Binding.prefix} is similar to @{ML Binding.qualify}, but
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1139 | affects the system prefix. This part of extra qualification is | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1140 | typically used in the infrastructure for modular specifications, | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1141 |   notably ``local theory targets'' (see also \chref{ch:local-theory}).
 | 
| 20437 | 1142 | |
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1143 |   \item @{ML Binding.conceal}~@{text "binding"} indicates that the
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1144 | binding shall refer to an entity that serves foundational purposes | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1145 | only. This flag helps to mark implementation details of | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1146 | specification mechanism etc. Other tools should not depend on the | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1147 |   particulars of concealed entities (cf.\ @{ML
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1148 | Name_Space.is_concealed}). | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1149 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1150 |   \item @{ML Binding.str_of}~@{text "binding"} produces a string
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1151 | representation for human-readable output, together with some formal | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1152 | markup that might get used in GUI front-ends, for example. | 
| 20476 | 1153 | |
| 39864 | 1154 |   \item Type @{ML_type Name_Space.naming} represents the abstract
 | 
| 1155 | concept of a naming policy. | |
| 20437 | 1156 | |
| 33174 | 1157 |   \item @{ML Name_Space.default_naming} is the default naming policy.
 | 
| 20476 | 1158 | In a theory context, this is usually augmented by a path prefix | 
| 1159 | consisting of the theory name. | |
| 1160 | ||
| 33174 | 1161 |   \item @{ML Name_Space.add_path}~@{text "path naming"} augments the
 | 
| 20488 | 1162 | naming policy by extending its path component. | 
| 20437 | 1163 | |
| 33174 | 1164 |   \item @{ML Name_Space.full_name}~@{text "naming binding"} turns a
 | 
| 30281 
9ad15d8ed311
renamed NameSpace.base to NameSpace.base_name (in accordance with "full_name");
 wenzelm parents: 
30272diff
changeset | 1165 | name binding (usually a basic name) into the fully qualified | 
| 29008 | 1166 | internal name, according to the given naming policy. | 
| 20476 | 1167 | |
| 39864 | 1168 |   \item Type @{ML_type Name_Space.T} represents name spaces.
 | 
| 20476 | 1169 | |
| 33174 | 1170 |   \item @{ML Name_Space.empty}~@{text "kind"} and @{ML Name_Space.merge}~@{text
 | 
| 20488 | 1171 | "(space\<^isub>1, space\<^isub>2)"} are the canonical operations for | 
| 1172 | maintaining name spaces according to theory data management | |
| 33174 | 1173 |   (\secref{sec:context-data}); @{text "kind"} is a formal comment
 | 
| 1174 | to characterize the purpose of a name space. | |
| 20437 | 1175 | |
| 33174 | 1176 |   \item @{ML Name_Space.declare}~@{text "strict naming bindings
 | 
| 1177 | space"} enters a name binding as fully qualified internal name into | |
| 1178 | the name space, with external accesses determined by the naming | |
| 1179 | policy. | |
| 20476 | 1180 | |
| 33174 | 1181 |   \item @{ML Name_Space.intern}~@{text "space name"} internalizes a
 | 
| 20476 | 1182 | (partially qualified) external name. | 
| 20437 | 1183 | |
| 20488 | 1184 | This operation is mostly for parsing! Note that fully qualified | 
| 20476 | 1185 |   names stemming from declarations are produced via @{ML
 | 
| 33174 | 1186 |   "Name_Space.full_name"} and @{ML "Name_Space.declare"}
 | 
| 29008 | 1187 |   (or their derivatives for @{ML_type theory} and
 | 
| 20488 | 1188 |   @{ML_type Proof.context}).
 | 
| 20437 | 1189 | |
| 33174 | 1190 |   \item @{ML Name_Space.extern}~@{text "space name"} externalizes a
 | 
| 20476 | 1191 | (fully qualified) internal name. | 
| 1192 | ||
| 30281 
9ad15d8ed311
renamed NameSpace.base to NameSpace.base_name (in accordance with "full_name");
 wenzelm parents: 
30272diff
changeset | 1193 | This operation is mostly for printing! User code should not rely on | 
| 
9ad15d8ed311
renamed NameSpace.base to NameSpace.base_name (in accordance with "full_name");
 wenzelm parents: 
30272diff
changeset | 1194 | the precise result too much. | 
| 20476 | 1195 | |
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1196 |   \item @{ML Name_Space.is_concealed}~@{text "space name"} indicates
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1197 |   whether @{text "name"} refers to a strictly private entity that
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1198 | other tools are supposed to ignore! | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 1199 | |
| 20476 | 1200 |   \end{description}
 | 
| 1201 | *} | |
| 30272 | 1202 | |
| 39832 | 1203 | text %mlantiq {*
 | 
| 1204 |   \begin{matharray}{rcl}
 | |
| 1205 |   @{ML_antiquotation_def "binding"} & : & @{text ML_antiquotation} \\
 | |
| 1206 |   \end{matharray}
 | |
| 1207 | ||
| 1208 |   \begin{rail}
 | |
| 1209 | 'binding' name | |
| 1210 | ; | |
| 1211 |   \end{rail}
 | |
| 1212 | ||
| 1213 |   \begin{description}
 | |
| 1214 | ||
| 1215 |   \item @{text "@{binding name}"} produces a binding with base name
 | |
| 1216 |   @{text "name"} and the source position taken from the concrete
 | |
| 1217 | syntax of this antiquotation. In many situations this is more | |
| 1218 |   appropriate than the more basic @{ML Binding.name} function.
 | |
| 1219 | ||
| 1220 |   \end{description}
 | |
| 1221 | *} | |
| 1222 | ||
| 39833 | 1223 | text %mlex {* The following example yields the source position of some
 | 
| 40126 | 1224 | concrete binding inlined into the text: | 
| 39833 | 1225 | *} | 
| 1226 | ||
| 1227 | ML {* Binding.pos_of @{binding here} *}
 | |
| 1228 | ||
| 39861 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 1229 | text {* \medskip That position can be also printed in a message as
 | 
| 40126 | 1230 | follows: *} | 
| 39833 | 1231 | |
| 1232 | ML_command {*
 | |
| 1233 | writeln | |
| 1234 |     ("Look here" ^ Position.str_of (Binding.pos_of @{binding here}))
 | |
| 1235 | *} | |
| 1236 | ||
| 39861 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 1237 | text {* This illustrates a key virtue of formalized bindings as
 | 
| 
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
 wenzelm parents: 
39857diff
changeset | 1238 | opposed to raw specifications of base names: the system can use this | 
| 40126 | 1239 | additional information for feedback given to the user (error | 
| 1240 | messages etc.). *} | |
| 39833 | 1241 | |
| 18537 | 1242 | end |