| author | wenzelm | 
| Mon, 26 Apr 2010 11:20:18 +0200 | |
| changeset 36345 | 3cbce59ed78d | 
| parent 35408 | b48ab741683b | 
| child 36611 | b0c047d03208 | 
| 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 | |
| 20488 | 143 | drafts are propagated automatically. Dynamic updating stops after | 
| 144 |   an explicit @{text "end"} only.
 | |
| 20451 | 145 | |
| 146 | Derived entities may store a theory reference in order to indicate | |
| 147 | the context they belong to. This implicitly assumes monotonic | |
| 148 | reasoning, because the referenced context may become larger without | |
| 149 | further notice. | |
| 18537 | 150 | *} | 
| 151 | ||
| 20430 | 152 | text %mlref {*
 | 
| 20447 | 153 |   \begin{mldecls}
 | 
| 154 |   @{index_ML_type theory} \\
 | |
| 155 |   @{index_ML Theory.subthy: "theory * theory -> bool"} \\
 | |
| 156 |   @{index_ML Theory.checkpoint: "theory -> theory"} \\
 | |
| 20547 | 157 |   @{index_ML Theory.copy: "theory -> theory"} \\
 | 
| 34921 | 158 |   @{index_ML Theory.merge: "theory * theory -> theory"} \\
 | 
| 159 |   @{index_ML Theory.begin_theory: "string -> theory list -> theory"} \\
 | |
| 20547 | 160 |   \end{mldecls}
 | 
| 161 |   \begin{mldecls}
 | |
| 20447 | 162 |   @{index_ML_type theory_ref} \\
 | 
| 163 |   @{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 | 164 |   @{index_ML Theory.check_thy: "theory -> theory_ref"} \\
 | 
| 20447 | 165 |   \end{mldecls}
 | 
| 166 | ||
| 167 |   \begin{description}
 | |
| 168 | ||
| 20451 | 169 |   \item @{ML_type theory} represents theory contexts.  This is
 | 
| 34921 | 170 | essentially a linear type, with explicit runtime checking! Most | 
| 171 | internal theory operations destroy the original version, which then | |
| 172 | becomes ``stale''. | |
| 20447 | 173 | |
| 34921 | 174 |   \item @{ML "Theory.subthy"}~@{text "(thy\<^sub>1, thy\<^sub>2)"} compares theories
 | 
| 175 | according to the intrinsic graph structure of the construction. | |
| 176 | This sub-theory relation is a nominal approximation of inclusion | |
| 177 |   (@{text "\<subseteq>"}) of the corresponding content (according to the
 | |
| 178 | semantics of the ML modules that implement the data). | |
| 20447 | 179 | |
| 180 |   \item @{ML "Theory.checkpoint"}~@{text "thy"} produces a safe
 | |
| 34921 | 181 |   stepping stone in the linear development of @{text "thy"}.  This
 | 
| 182 | changes the old theory, but the next update will result in two | |
| 183 | related, valid theories. | |
| 20447 | 184 | |
| 185 |   \item @{ML "Theory.copy"}~@{text "thy"} produces a variant of @{text
 | |
| 34921 | 186 | "thy"} with the same data. The copy is not related to the original, | 
| 187 | but the original is unchanged. | |
| 188 | ||
| 189 |   \item @{ML "Theory.merge"}~@{text "(thy\<^sub>1, thy\<^sub>2)"} absorbs one theory
 | |
| 190 |   into the other, without changing @{text "thy\<^sub>1"} or @{text "thy\<^sub>2"}.
 | |
| 191 | This version of ad-hoc theory merge fails for unrelated theories! | |
| 192 | ||
| 193 |   \item @{ML "Theory.begin_theory"}~@{text "name parents"} constructs
 | |
| 194 |   a new theory based on the given parents.  This {\ML} function is
 | |
| 195 | normally not invoked directly. | |
| 20447 | 196 | |
| 20451 | 197 |   \item @{ML_type theory_ref} represents a sliding reference to an
 | 
| 198 | always valid theory; updates on the original are propagated | |
| 20447 | 199 | automatically. | 
| 200 | ||
| 24137 
8d7896398147
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
 wenzelm parents: 
22869diff
changeset | 201 |   \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 | 202 |   "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 | 203 |   theory evolves monotonically over time, later invocations of @{ML
 | 
| 20451 | 204 | "Theory.deref"} may refer to a larger context. | 
| 20447 | 205 | |
| 24137 
8d7896398147
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
 wenzelm parents: 
22869diff
changeset | 206 |   \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 | 207 |   "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 | 208 | |
| 20447 | 209 |   \end{description}
 | 
| 20430 | 210 | *} | 
| 211 | ||
| 18537 | 212 | |
| 213 | subsection {* Proof context \label{sec:context-proof} *}
 | |
| 214 | ||
| 34921 | 215 | text {* A proof context is a container for pure data with a
 | 
| 216 |   back-reference to the theory it belongs to.  The @{text "init"}
 | |
| 217 | operation creates a proof context from a given theory. | |
| 218 | Modifications to draft theories are propagated to the proof context | |
| 219 |   as usual, but there is also an explicit @{text "transfer"} operation
 | |
| 220 | to force resynchronization with more substantial updates to the | |
| 221 | underlying theory. | |
| 20429 | 222 | |
| 34921 | 223 | Entities derived in a proof context need to record logical | 
| 20447 | 224 | requirements explicitly, since there is no separate context | 
| 34921 | 225 | identification or symbolic inclusion as for theories. For example, | 
| 226 |   hypotheses used in primitive derivations (cf.\ \secref{sec:thms})
 | |
| 227 |   are recorded separately within the sequent @{text "\<Gamma> \<turnstile> \<phi>"}, just to
 | |
| 228 | make double sure. Results could still leak into an alien proof | |
| 229 | context due to programming errors, but Isabelle/Isar includes some | |
| 230 | extra validity checks in critical positions, notably at the end of a | |
| 231 | sub-proof. | |
| 20429 | 232 | |
| 20451 | 233 | Proof contexts may be manipulated arbitrarily, although the common | 
| 234 | discipline is to follow block structure as a mental model: a given | |
| 235 | context is extended consecutively, and results are exported back | |
| 34921 | 236 | into the original context. Note that an Isar proof state models | 
| 20451 | 237 | block-structured reasoning explicitly, using a stack of proof | 
| 34921 | 238 | contexts internally. For various technical reasons, the background | 
| 239 | theory of an Isar proof state must not be changed while the proof is | |
| 240 | still under construction! | |
| 18537 | 241 | *} | 
| 242 | ||
| 20449 | 243 | text %mlref {*
 | 
| 244 |   \begin{mldecls}
 | |
| 245 |   @{index_ML_type Proof.context} \\
 | |
| 246 |   @{index_ML ProofContext.init: "theory -> Proof.context"} \\
 | |
| 247 |   @{index_ML ProofContext.theory_of: "Proof.context -> theory"} \\
 | |
| 248 |   @{index_ML ProofContext.transfer: "theory -> Proof.context -> Proof.context"} \\
 | |
| 249 |   \end{mldecls}
 | |
| 250 | ||
| 251 |   \begin{description}
 | |
| 252 | ||
| 253 |   \item @{ML_type Proof.context} represents proof contexts.  Elements
 | |
| 254 | of this type are essentially pure values, with a sliding reference | |
| 255 | to the background theory. | |
| 256 | ||
| 257 |   \item @{ML ProofContext.init}~@{text "thy"} produces a proof context
 | |
| 258 |   derived from @{text "thy"}, initializing all data.
 | |
| 259 | ||
| 260 |   \item @{ML ProofContext.theory_of}~@{text "ctxt"} selects the
 | |
| 20451 | 261 |   background theory from @{text "ctxt"}, dereferencing its internal
 | 
| 262 |   @{ML_type theory_ref}.
 | |
| 20449 | 263 | |
| 264 |   \item @{ML ProofContext.transfer}~@{text "thy ctxt"} promotes the
 | |
| 265 |   background theory of @{text "ctxt"} to the super theory @{text
 | |
| 266 | "thy"}. | |
| 267 | ||
| 268 |   \end{description}
 | |
| 269 | *} | |
| 270 | ||
| 20430 | 271 | |
| 20451 | 272 | subsection {* Generic contexts \label{sec:generic-context} *}
 | 
| 20429 | 273 | |
| 20449 | 274 | text {*
 | 
| 275 | A generic context is the disjoint sum of either a theory or proof | |
| 20451 | 276 | context. Occasionally, this enables uniform treatment of generic | 
| 20450 | 277 | context data, typically extra-logical information. Operations on | 
| 20449 | 278 | generic contexts include the usual injections, partial selections, | 
| 279 | and combinators for lifting operations on either component of the | |
| 280 | disjoint sum. | |
| 281 | ||
| 282 |   Moreover, there are total operations @{text "theory_of"} and @{text
 | |
| 283 | "proof_of"} to convert a generic context into either kind: a theory | |
| 20451 | 284 | can always be selected from the sum, while a proof context might | 
| 34921 | 285 |   have to be constructed by an ad-hoc @{text "init"} operation, which
 | 
| 286 | incurs a small runtime overhead. | |
| 20449 | 287 | *} | 
| 20430 | 288 | |
| 20449 | 289 | text %mlref {*
 | 
| 290 |   \begin{mldecls}
 | |
| 291 |   @{index_ML_type Context.generic} \\
 | |
| 292 |   @{index_ML Context.theory_of: "Context.generic -> theory"} \\
 | |
| 293 |   @{index_ML Context.proof_of: "Context.generic -> Proof.context"} \\
 | |
| 294 |   \end{mldecls}
 | |
| 295 | ||
| 296 |   \begin{description}
 | |
| 20430 | 297 | |
| 20449 | 298 |   \item @{ML_type Context.generic} is the direct sum of @{ML_type
 | 
| 20451 | 299 |   "theory"} and @{ML_type "Proof.context"}, with the datatype
 | 
| 300 |   constructors @{ML "Context.Theory"} and @{ML "Context.Proof"}.
 | |
| 20449 | 301 | |
| 302 |   \item @{ML Context.theory_of}~@{text "context"} always produces a
 | |
| 303 |   theory from the generic @{text "context"}, using @{ML
 | |
| 304 | "ProofContext.theory_of"} as required. | |
| 305 | ||
| 306 |   \item @{ML Context.proof_of}~@{text "context"} always produces a
 | |
| 307 |   proof context from the generic @{text "context"}, using @{ML
 | |
| 20451 | 308 | "ProofContext.init"} as required (note that this re-initializes the | 
| 309 | context data with each invocation). | |
| 20449 | 310 | |
| 311 |   \end{description}
 | |
| 312 | *} | |
| 20437 | 313 | |
| 20476 | 314 | |
| 315 | subsection {* Context data \label{sec:context-data} *}
 | |
| 20447 | 316 | |
| 33524 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 317 | 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 | 318 | arbitrary (pure) data. New data types can be declared incrementally | 
| 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 319 | at compile time. There are separate declaration mechanisms for any | 
| 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 320 | of the three kinds of contexts: theory, proof, generic. | 
| 20449 | 321 | |
| 33524 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 322 |   \paragraph{Theory data} declarations need to implement the following
 | 
| 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 323 | SML signature: | 
| 20449 | 324 | |
| 325 | \medskip | |
| 326 |   \begin{tabular}{ll}
 | |
| 22869 | 327 |   @{text "\<type> T"} & representing type \\
 | 
| 328 |   @{text "\<val> empty: T"} & empty default value \\
 | |
| 329 |   @{text "\<val> extend: T \<rightarrow> T"} & re-initialize on import \\
 | |
| 330 |   @{text "\<val> merge: T \<times> T \<rightarrow> T"} & join on import \\
 | |
| 20449 | 331 |   \end{tabular}
 | 
| 332 | \medskip | |
| 333 | ||
| 22869 | 334 |   \noindent The @{text "empty"} value acts as initial default for
 | 
| 335 |   \emph{any} theory that does not declare actual data content; @{text
 | |
| 33524 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 336 |   "extend"} is acts like a unitary version of @{text "merge"}.
 | 
| 20449 | 337 | |
| 34921 | 338 |   Implementing @{text "merge"} can be tricky.  The general idea is
 | 
| 339 |   that @{text "merge (data\<^sub>1, data\<^sub>2)"} inserts those parts of @{text
 | |
| 340 |   "data\<^sub>2"} into @{text "data\<^sub>1"} that are not yet present, while
 | |
| 341 |   keeping the general order of things.  The @{ML Library.merge}
 | |
| 342 | function on plain lists may serve as canonical template. | |
| 343 | ||
| 344 | Particularly note that shared parts of the data must not be | |
| 345 | duplicated by naive concatenation, or a theory graph that is like a | |
| 346 | chain of diamonds would cause an exponential blowup! | |
| 347 | ||
| 33524 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 348 |   \paragraph{Proof context data} declarations need to implement the
 | 
| 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 349 | following SML signature: | 
| 20449 | 350 | |
| 351 | \medskip | |
| 352 |   \begin{tabular}{ll}
 | |
| 22869 | 353 |   @{text "\<type> T"} & representing type \\
 | 
| 354 |   @{text "\<val> init: theory \<rightarrow> T"} & produce initial value \\
 | |
| 20449 | 355 |   \end{tabular}
 | 
| 356 | \medskip | |
| 357 | ||
| 358 |   \noindent The @{text "init"} operation is supposed to produce a pure
 | |
| 34921 | 359 | value from the given background theory and should be somehow | 
| 360 | ``immediate''. Whenever a proof context is initialized, which | |
| 361 |   happens frequently, the the system invokes the @{text "init"}
 | |
| 362 |   operation of \emph{all} theory data slots ever declared.
 | |
| 20449 | 363 | |
| 20451 | 364 |   \paragraph{Generic data} provides a hybrid interface for both theory
 | 
| 33524 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 365 |   and proof data.  The @{text "init"} operation for proof contexts is
 | 
| 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 366 | predefined to select the current data value from the background | 
| 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 367 | theory. | 
| 20449 | 368 | |
| 34921 | 369 |   \bigskip Any of these data declaration over type @{text "T"} result
 | 
| 370 | in an ML structure with the following signature: | |
| 20449 | 371 | |
| 372 | \medskip | |
| 373 |   \begin{tabular}{ll}
 | |
| 374 |   @{text "get: context \<rightarrow> T"} \\
 | |
| 375 |   @{text "put: T \<rightarrow> context \<rightarrow> context"} \\
 | |
| 376 |   @{text "map: (T \<rightarrow> T) \<rightarrow> context \<rightarrow> context"} \\
 | |
| 377 |   \end{tabular}
 | |
| 378 | \medskip | |
| 379 | ||
| 34921 | 380 | \noindent These other operations provide exclusive access for the | 
| 381 | particular kind of context (theory, proof, or generic context). | |
| 382 | This interface fully observes the ML discipline for types and | |
| 383 | scopes: there is no other way to access the corresponding data slot | |
| 384 | of a context. By keeping these operations private, an Isabelle/ML | |
| 385 | module may maintain abstract values authentically. | |
| 20447 | 386 | *} | 
| 387 | ||
| 20450 | 388 | text %mlref {*
 | 
| 389 |   \begin{mldecls}
 | |
| 33524 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 390 |   @{index_ML_functor Theory_Data} \\
 | 
| 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 391 |   @{index_ML_functor Proof_Data} \\
 | 
| 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 392 |   @{index_ML_functor Generic_Data} \\
 | 
| 20450 | 393 |   \end{mldecls}
 | 
| 394 | ||
| 395 |   \begin{description}
 | |
| 396 | ||
| 33524 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 397 |   \item @{ML_functor Theory_Data}@{text "(spec)"} declares data for
 | 
| 20450 | 398 |   type @{ML_type theory} according to the specification provided as
 | 
| 20451 | 399 | argument structure. The resulting structure provides data init and | 
| 400 | access operations as described above. | |
| 20450 | 401 | |
| 33524 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 402 |   \item @{ML_functor Proof_Data}@{text "(spec)"} is analogous to
 | 
| 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 403 |   @{ML_functor Theory_Data} for type @{ML_type Proof.context}.
 | 
| 20450 | 404 | |
| 33524 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 405 |   \item @{ML_functor Generic_Data}@{text "(spec)"} is analogous to
 | 
| 
a08e6c1cbc04
updated functor Theory_Data, Proof_Data, Generic_Data;
 wenzelm parents: 
33174diff
changeset | 406 |   @{ML_functor Theory_Data} for type @{ML_type Context.generic}.
 | 
| 20450 | 407 | |
| 408 |   \end{description}
 | |
| 409 | *} | |
| 410 | ||
| 34928 | 411 | text %mlex {*
 | 
| 412 | The following artificial example demonstrates theory | |
| 413 | data: we maintain a set of terms that are supposed to be wellformed | |
| 414 | wrt.\ the enclosing theory. The public interface is as follows: | |
| 415 | *} | |
| 416 | ||
| 417 | ML {*
 | |
| 418 | signature WELLFORMED_TERMS = | |
| 419 | sig | |
| 420 | val get: theory -> term list | |
| 421 | val add: term -> theory -> theory | |
| 422 | end; | |
| 423 | *} | |
| 424 | ||
| 425 | text {* \noindent The implementation uses private theory data
 | |
| 426 | internally, and only exposes an operation that involves explicit | |
| 427 | argument checking wrt.\ the given theory. *} | |
| 428 | ||
| 429 | ML {*
 | |
| 430 | structure Wellformed_Terms: WELLFORMED_TERMS = | |
| 431 | struct | |
| 432 | ||
| 433 | structure Terms = Theory_Data | |
| 434 | ( | |
| 435 | type T = term OrdList.T; | |
| 436 | val empty = []; | |
| 437 | val extend = I; | |
| 438 | fun merge (ts1, ts2) = | |
| 35408 | 439 | OrdList.union Term_Ord.fast_term_ord ts1 ts2; | 
| 34928 | 440 | ) | 
| 441 | ||
| 442 | val get = Terms.get; | |
| 443 | ||
| 444 | fun add raw_t thy = | |
| 445 | let val t = Sign.cert_term thy raw_t | |
| 35408 | 446 | in Terms.map (OrdList.insert Term_Ord.fast_term_ord t) thy end; | 
| 34928 | 447 | |
| 448 | end; | |
| 449 | *} | |
| 450 | ||
| 451 | text {* We use @{ML_type "term OrdList.T"} for reasonably efficient
 | |
| 452 | representation of a set of terms: all operations are linear in the | |
| 453 | number of stored elements. Here we assume that our users do not | |
| 454 | care about the declaration order, since that data structure forces | |
| 455 | its own arrangement of elements. | |
| 456 | ||
| 457 |   Observe how the @{verbatim merge} operation joins the data slots of
 | |
| 458 |   the two constituents: @{ML OrdList.union} prevents duplication of
 | |
| 459 | common data from different branches, thus avoiding the danger of | |
| 460 | exponential blowup. (Plain list append etc.\ must never be used for | |
| 461 | theory data merges.) | |
| 462 | ||
| 463 | \medskip Our intended invariant is achieved as follows: | |
| 464 |   \begin{enumerate}
 | |
| 465 | ||
| 466 |   \item @{ML Wellformed_Terms.add} only admits terms that have passed
 | |
| 467 |   the @{ML Sign.cert_term} check of the given theory at that point.
 | |
| 468 | ||
| 469 |   \item Wellformedness in the sense of @{ML Sign.cert_term} is
 | |
| 470 | monotonic wrt.\ the sub-theory relation. So our data can move | |
| 471 | upwards in the hierarchy (via extension or merges), and maintain | |
| 472 | wellformedness without further checks. | |
| 473 | ||
| 474 |   \end{enumerate}
 | |
| 475 | ||
| 476 | Note that all basic operations of the inference kernel (which | |
| 477 |   includes @{ML Sign.cert_term}) observe this monotonicity principle,
 | |
| 478 | but other user-space tools don't. For example, fully-featured | |
| 479 |   type-inference via @{ML Syntax.check_term} (cf.\
 | |
| 480 |   \secref{sec:term-check}) is not necessarily monotonic wrt.\ the
 | |
| 481 | background theory, since constraints of term constants can be | |
| 482 | strengthened by later declarations, for example. | |
| 483 | ||
| 484 | In most cases, user-space context data does not have to take such | |
| 485 | invariants too seriously. The situation is different in the | |
| 486 | implementation of the inference kernel itself, which uses the very | |
| 487 | same data mechanisms for types, constants, axioms etc. | |
| 488 | *} | |
| 489 | ||
| 20447 | 490 | |
| 26872 | 491 | section {* Names \label{sec:names} *}
 | 
| 20451 | 492 | |
| 34925 | 493 | text {* In principle, a name is just a string, but there are various
 | 
| 494 | conventions for representing additional structure. For example, | |
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 495 |   ``@{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 | 496 |   qualifier @{text "Foo.bar"} and base name @{text "baz"}.  The
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 497 | individual constituents of a name may have further substructure, | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 498 | 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 | 499 | symbol. | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 500 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 501 | \medskip Subsequently, we shall introduce specific categories of | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 502 | names. Roughly speaking these correspond to logical entities as | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 503 | follows: | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 504 |   \begin{itemize}
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 505 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 506 |   \item Basic names (\secref{sec:basic-name}): free and bound
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 507 | variables. | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 508 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 509 |   \item Indexed names (\secref{sec:indexname}): schematic variables.
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 510 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 511 |   \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 | 512 | (type constructors, term constants, other concepts defined in user | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 513 | space). Such entities are typically managed via name spaces | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 514 |   (\secref{sec:name-space}).
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 515 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 516 |   \end{itemize}
 | 
| 20451 | 517 | *} | 
| 20437 | 518 | |
| 519 | ||
| 520 | subsection {* Strings of symbols *}
 | |
| 521 | ||
| 34925 | 522 | text {* A \emph{symbol} constitutes the smallest textual unit in
 | 
| 523 | Isabelle --- raw ML characters are normally not encountered at all! | |
| 524 | Isabelle strings consist of a sequence of symbols, represented as a | |
| 525 | packed string or an exploded list of strings. Each symbol is in | |
| 526 | itself a small string, which has either one of the following forms: | |
| 20437 | 527 | |
| 20451 | 528 |   \begin{enumerate}
 | 
| 20437 | 529 | |
| 34925 | 530 |   \item a single ASCII character ``@{text "c"}'' or raw byte in the
 | 
| 531 | range of 128\dots 255, for example ``\verb,a,'', | |
| 20437 | 532 | |
| 20488 | 533 |   \item a regular symbol ``\verb,\,\verb,<,@{text "ident"}\verb,>,'',
 | 
| 20476 | 534 | for example ``\verb,\,\verb,<alpha>,'', | 
| 20437 | 535 | |
| 20488 | 536 |   \item a control symbol ``\verb,\,\verb,<^,@{text "ident"}\verb,>,'',
 | 
| 20476 | 537 | for example ``\verb,\,\verb,<^bold>,'', | 
| 20437 | 538 | |
| 20488 | 539 |   \item a raw symbol ``\verb,\,\verb,<^raw:,@{text text}\verb,>,''
 | 
| 34925 | 540 |   where @{text text} consists of printable characters excluding
 | 
| 20476 | 541 | ``\verb,.,'' and ``\verb,>,'', for example | 
| 542 |   ``\verb,\,\verb,<^raw:$\sum_{i = 1}^n$>,'',
 | |
| 20437 | 543 | |
| 20488 | 544 |   \item a numbered raw control symbol ``\verb,\,\verb,<^raw,@{text
 | 
| 20476 | 545 |   n}\verb,>, where @{text n} consists of digits, for example
 | 
| 20451 | 546 | ``\verb,\,\verb,<^raw42>,''. | 
| 20437 | 547 | |
| 20451 | 548 |   \end{enumerate}
 | 
| 20437 | 549 | |
| 20476 | 550 |   \noindent The @{text "ident"} syntax for symbol names is @{text
 | 
| 551 |   "letter (letter | digit)\<^sup>*"}, where @{text "letter =
 | |
| 552 |   A..Za..z"} and @{text "digit = 0..9"}.  There are infinitely many
 | |
| 553 | regular symbols and control symbols, but a fixed collection of | |
| 554 | standard symbols is treated specifically. For example, | |
| 20488 | 555 | ``\verb,\,\verb,<alpha>,'' is classified as a letter, which means it | 
| 556 | may occur within regular Isabelle identifiers. | |
| 20437 | 557 | |
| 20488 | 558 | Since the character set underlying Isabelle symbols is 7-bit ASCII | 
| 34925 | 559 | and 8-bit characters are passed through transparently, Isabelle can | 
| 560 |   also process Unicode/UCS data in UTF-8 encoding.\footnote{When
 | |
| 561 | counting precise source positions internally, bytes in the range of | |
| 562 | 128\dots 191 are ignored. In UTF-8 encoding, this interval covers | |
| 563 | the additional trailer bytes, so Isabelle happens to count Unicode | |
| 564 | characters here, not bytes in memory. In ISO-Latin encoding, the | |
| 565 | ignored range merely includes some extra punctuation characters that | |
| 566 | even have replacements within the standard collection of Isabelle | |
| 567 | symbols; the accented letters range is counted properly.} Unicode | |
| 568 | provides its own collection of mathematical symbols, but within the | |
| 569 | core Isabelle/ML world there is no link to the standard collection | |
| 570 | of Isabelle regular symbols. | |
| 20476 | 571 | |
| 572 | \medskip Output of Isabelle symbols depends on the print mode | |
| 29758 | 573 |   (\secref{print-mode}).  For example, the standard {\LaTeX} setup of
 | 
| 574 | the Isabelle document preparation system would present | |
| 20451 | 575 |   ``\verb,\,\verb,<alpha>,'' as @{text "\<alpha>"}, and
 | 
| 576 |   ``\verb,\,\verb,<^bold>,\verb,\,\verb,<alpha>,'' as @{text
 | |
| 34925 | 577 | "\<^bold>\<alpha>"}. On-screen rendering usually works by mapping a finite | 
| 578 | subset of Isabelle symbols to suitable Unicode characters. | |
| 20451 | 579 | *} | 
| 20437 | 580 | |
| 581 | text %mlref {*
 | |
| 582 |   \begin{mldecls}
 | |
| 34921 | 583 |   @{index_ML_type "Symbol.symbol": string} \\
 | 
| 20437 | 584 |   @{index_ML Symbol.explode: "string -> Symbol.symbol list"} \\
 | 
| 585 |   @{index_ML Symbol.is_letter: "Symbol.symbol -> bool"} \\
 | |
| 586 |   @{index_ML Symbol.is_digit: "Symbol.symbol -> bool"} \\
 | |
| 587 |   @{index_ML Symbol.is_quasi: "Symbol.symbol -> bool"} \\
 | |
| 20547 | 588 |   @{index_ML Symbol.is_blank: "Symbol.symbol -> bool"} \\
 | 
| 589 |   \end{mldecls}
 | |
| 590 |   \begin{mldecls}
 | |
| 20437 | 591 |   @{index_ML_type "Symbol.sym"} \\
 | 
| 592 |   @{index_ML Symbol.decode: "Symbol.symbol -> Symbol.sym"} \\
 | |
| 593 |   \end{mldecls}
 | |
| 594 | ||
| 595 |   \begin{description}
 | |
| 596 | ||
| 20488 | 597 |   \item @{ML_type "Symbol.symbol"} represents individual Isabelle
 | 
| 34921 | 598 | symbols. | 
| 20437 | 599 | |
| 20476 | 600 |   \item @{ML "Symbol.explode"}~@{text "str"} produces a symbol list
 | 
| 20488 | 601 |   from the packed form.  This function supercedes @{ML
 | 
| 20476 | 602 | "String.explode"} for virtually all purposes of manipulating text in | 
| 34925 | 603 |   Isabelle!\footnote{The runtime overhead for exploded strings is
 | 
| 604 | mainly that of the list structure: individual symbols that happen to | |
| 605 | be a singleton string --- which is the most common case --- do not | |
| 606 | require extra memory in Poly/ML.} | |
| 20437 | 607 | |
| 608 |   \item @{ML "Symbol.is_letter"}, @{ML "Symbol.is_digit"}, @{ML
 | |
| 20476 | 609 |   "Symbol.is_quasi"}, @{ML "Symbol.is_blank"} classify standard
 | 
| 610 | symbols according to fixed syntactic conventions of Isabelle, cf.\ | |
| 611 |   \cite{isabelle-isar-ref}.
 | |
| 20437 | 612 | |
| 613 |   \item @{ML_type "Symbol.sym"} is a concrete datatype that represents
 | |
| 20488 | 614 |   the different kinds of symbols explicitly, with constructors @{ML
 | 
| 615 |   "Symbol.Char"}, @{ML "Symbol.Sym"}, @{ML "Symbol.Ctrl"}, @{ML
 | |
| 20451 | 616 | "Symbol.Raw"}. | 
| 20437 | 617 | |
| 618 |   \item @{ML "Symbol.decode"} converts the string representation of a
 | |
| 20451 | 619 | symbol into the datatype version. | 
| 20437 | 620 | |
| 621 |   \end{description}
 | |
| 34925 | 622 | |
| 623 |   \paragraph{Historical note.} In the original SML90 standard the
 | |
| 624 |   primitive ML type @{ML_type char} did not exists, and the basic @{ML
 | |
| 625 | "explode: string -> string list"} operation would produce a list of | |
| 626 | singleton strings as in Isabelle/ML today. When SML97 came out, | |
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 627 | Isabelle did not adopt its slightly anachronistic 8-bit characters, | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 628 | but the idea of exploding a string into a list of small strings was | 
| 34925 | 629 | extended to ``symbols'' as explained above. Thus Isabelle sources | 
| 630 | can refer to an infinite store of user-defined symbols, without | |
| 631 | having to worry about the multitude of Unicode encodings. | |
| 20437 | 632 | *} | 
| 633 | ||
| 634 | ||
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 635 | subsection {* Basic names \label{sec:basic-name} *}
 | 
| 20476 | 636 | |
| 637 | text {*
 | |
| 638 |   A \emph{basic name} essentially consists of a single Isabelle
 | |
| 639 | identifier. There are conventions to mark separate classes of basic | |
| 29761 | 640 | names, by attaching a suffix of underscores: one underscore means | 
| 641 |   \emph{internal name}, two underscores means \emph{Skolem name},
 | |
| 642 |   three underscores means \emph{internal Skolem name}.
 | |
| 20476 | 643 | |
| 644 |   For example, the basic name @{text "foo"} has the internal version
 | |
| 645 |   @{text "foo_"}, with Skolem versions @{text "foo__"} and @{text
 | |
| 646 | "foo___"}, respectively. | |
| 647 | ||
| 20488 | 648 | These special versions provide copies of the basic name space, apart | 
| 649 | from anything that normally appears in the user text. For example, | |
| 650 | system generated variables in Isar proof contexts are usually marked | |
| 34926 | 651 |   as internal, which prevents mysterious names like @{text "xaa"} to
 | 
| 652 | appear in human-readable text. | |
| 20476 | 653 | |
| 20488 | 654 | \medskip Manipulating binding scopes often requires on-the-fly | 
| 655 |   renamings.  A \emph{name context} contains a collection of already
 | |
| 656 |   used names.  The @{text "declare"} operation adds names to the
 | |
| 657 | context. | |
| 20476 | 658 | |
| 20488 | 659 |   The @{text "invents"} operation derives a number of fresh names from
 | 
| 660 | a given starting point. For example, the first three names derived | |
| 661 |   from @{text "a"} are @{text "a"}, @{text "b"}, @{text "c"}.
 | |
| 20476 | 662 | |
| 663 |   The @{text "variants"} operation produces fresh names by
 | |
| 20488 | 664 |   incrementing tentative names as base-26 numbers (with digits @{text
 | 
| 665 |   "a..z"}) until all clashes are resolved.  For example, name @{text
 | |
| 666 |   "foo"} results in variants @{text "fooa"}, @{text "foob"}, @{text
 | |
| 667 |   "fooc"}, \dots, @{text "fooaa"}, @{text "fooab"} etc.; each renaming
 | |
| 668 | step picks the next unused variant from this sequence. | |
| 20476 | 669 | *} | 
| 670 | ||
| 671 | text %mlref {*
 | |
| 672 |   \begin{mldecls}
 | |
| 673 |   @{index_ML Name.internal: "string -> string"} \\
 | |
| 20547 | 674 |   @{index_ML Name.skolem: "string -> string"} \\
 | 
| 675 |   \end{mldecls}
 | |
| 676 |   \begin{mldecls}
 | |
| 20476 | 677 |   @{index_ML_type Name.context} \\
 | 
| 678 |   @{index_ML Name.context: Name.context} \\
 | |
| 679 |   @{index_ML Name.declare: "string -> Name.context -> Name.context"} \\
 | |
| 680 |   @{index_ML Name.invents: "Name.context -> string -> int -> string list"} \\
 | |
| 681 |   @{index_ML Name.variants: "string list -> Name.context -> string list * Name.context"} \\
 | |
| 682 |   \end{mldecls}
 | |
| 34926 | 683 |   \begin{mldecls}
 | 
| 684 |   @{index_ML Variable.names_of: "Proof.context -> Name.context"} \\
 | |
| 685 |   \end{mldecls}
 | |
| 20476 | 686 | |
| 687 |   \begin{description}
 | |
| 688 | ||
| 689 |   \item @{ML Name.internal}~@{text "name"} produces an internal name
 | |
| 690 | by adding one underscore. | |
| 691 | ||
| 692 |   \item @{ML Name.skolem}~@{text "name"} produces a Skolem name by
 | |
| 693 | adding two underscores. | |
| 694 | ||
| 695 |   \item @{ML_type Name.context} represents the context of already used
 | |
| 696 |   names; the initial value is @{ML "Name.context"}.
 | |
| 697 | ||
| 20488 | 698 |   \item @{ML Name.declare}~@{text "name"} enters a used name into the
 | 
| 699 | context. | |
| 20437 | 700 | |
| 20488 | 701 |   \item @{ML Name.invents}~@{text "context name n"} produces @{text
 | 
| 702 |   "n"} fresh names derived from @{text "name"}.
 | |
| 703 | ||
| 704 |   \item @{ML Name.variants}~@{text "names context"} produces fresh
 | |
| 29761 | 705 |   variants of @{text "names"}; the result is entered into the context.
 | 
| 20476 | 706 | |
| 34926 | 707 |   \item @{ML Variable.names_of}~@{text "ctxt"} retrieves the context
 | 
| 708 | of declared type and term variable names. Projecting a proof | |
| 709 | context down to a primitive name context is occasionally useful when | |
| 710 | invoking lower-level operations. Regular management of ``fresh | |
| 711 |   variables'' is done by suitable operations of structure @{ML_struct
 | |
| 712 | Variable}, which is also able to provide an official status of | |
| 713 | ``locally fixed variable'' within the logical environment (cf.\ | |
| 714 |   \secref{sec:variables}).
 | |
| 715 | ||
| 20476 | 716 |   \end{description}
 | 
| 717 | *} | |
| 718 | ||
| 719 | ||
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 720 | subsection {* Indexed names \label{sec:indexname} *}
 | 
| 20476 | 721 | |
| 722 | text {*
 | |
| 723 |   An \emph{indexed name} (or @{text "indexname"}) is a pair of a basic
 | |
| 20488 | 724 | name and a natural number. This representation allows efficient | 
| 725 | renaming by incrementing the second component only. The canonical | |
| 726 | way to rename two collections of indexnames apart from each other is | |
| 727 |   this: determine the maximum index @{text "maxidx"} of the first
 | |
| 728 | collection, then increment all indexes of the second collection by | |
| 729 |   @{text "maxidx + 1"}; the maximum index of an empty collection is
 | |
| 730 |   @{text "-1"}.
 | |
| 20476 | 731 | |
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 732 | 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 | 733 |   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 | 734 |   name @{text "x"}.
 | 
| 20488 | 735 | |
| 736 | \medskip Isabelle syntax observes the following rules for | |
| 737 |   representing an indexname @{text "(x, i)"} as a packed string:
 | |
| 20476 | 738 | |
| 739 |   \begin{itemize}
 | |
| 740 | ||
| 20479 | 741 |   \item @{text "?x"} if @{text "x"} does not end with a digit and @{text "i = 0"},
 | 
| 20476 | 742 | |
| 743 |   \item @{text "?xi"} if @{text "x"} does not end with a digit,
 | |
| 744 | ||
| 20488 | 745 |   \item @{text "?x.i"} otherwise.
 | 
| 20476 | 746 | |
| 747 |   \end{itemize}
 | |
| 20470 | 748 | |
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 749 | Indexnames may acquire large index numbers after several maxidx | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 750 | shifts have been applied. Results are usually normalized towards | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 751 |   @{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 | 752 | This works by producing variants of the corresponding basic name | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 753 |   components.  For example, the collection @{text "?x1, ?x7, ?x42"}
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 754 |   becomes @{text "?x, ?xa, ?xb"}.
 | 
| 20476 | 755 | *} | 
| 756 | ||
| 757 | text %mlref {*
 | |
| 758 |   \begin{mldecls}
 | |
| 759 |   @{index_ML_type indexname} \\
 | |
| 760 |   \end{mldecls}
 | |
| 761 | ||
| 762 |   \begin{description}
 | |
| 763 | ||
| 764 |   \item @{ML_type indexname} represents indexed names.  This is an
 | |
| 765 |   abbreviation for @{ML_type "string * int"}.  The second component is
 | |
| 766 |   usually non-negative, except for situations where @{text "(x, -1)"}
 | |
| 34926 | 767 | is used to inject basic names into this type. Other negative | 
| 768 | indexes should not be used. | |
| 20476 | 769 | |
| 770 |   \end{description}
 | |
| 771 | *} | |
| 772 | ||
| 773 | ||
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 774 | subsection {* Long names \label{sec:long-name} *}
 | 
| 20476 | 775 | |
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 776 | 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 | 777 | components. The packed representation uses a dot as separator, as | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 778 |   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 | 779 |   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 | 780 | 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 | 781 | named entity while passing through some nested block-structure, | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 782 | 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 | 783 | discipline. | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 784 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 785 |   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 | 786 |   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 | 787 |   within a global structure @{text "A"}.  In practice, long names
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 788 | 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 | 789 | not make any assumptions about the particular structure of long | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 790 | names! | 
| 20437 | 791 | |
| 20476 | 792 | 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 | 793 | entities, or entities that are not entered into the corresponding | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 794 | 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 | 795 | long names map empty names again to empty names. | 
| 20437 | 796 | *} | 
| 797 | ||
| 20476 | 798 | text %mlref {*
 | 
| 799 |   \begin{mldecls}
 | |
| 30365 | 800 |   @{index_ML Long_Name.base_name: "string -> string"} \\
 | 
| 801 |   @{index_ML Long_Name.qualifier: "string -> string"} \\
 | |
| 802 |   @{index_ML Long_Name.append: "string -> string -> string"} \\
 | |
| 803 |   @{index_ML Long_Name.implode: "string list -> string"} \\
 | |
| 804 |   @{index_ML Long_Name.explode: "string -> string list"} \\
 | |
| 20547 | 805 |   \end{mldecls}
 | 
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 806 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 807 |   \begin{description}
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 808 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 809 |   \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 | 810 | of a long name. | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 811 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 812 |   \item @{ML Long_Name.qualifier}~@{text "name"} returns the qualifier
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 813 | of a long name. | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 814 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 815 |   \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 | 816 | names. | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 817 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 818 |   \item @{ML Long_Name.implode}~@{text "names"} and @{ML
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 819 |   Long_Name.explode}~@{text "name"} convert between the packed string
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 820 | representation and the explicit list form of long names. | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 821 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 822 |   \end{description}
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 823 | *} | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 824 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 825 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 826 | subsection {* Name spaces \label{sec:name-space} *}
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 827 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 828 | 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 | 829 | together with a mapping between partially qualified external names | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 830 | and fully qualified internal names (in both directions). Note that | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 831 |   the corresponding @{text "intern"} and @{text "extern"} operations
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 832 |   are mostly used for parsing and printing only!  The @{text
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 833 | "declare"} operation augments a name space according to the accesses | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 834 | 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 | 835 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 836 |   \medskip A @{text "binding"} specifies details about the prospective
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 837 | 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 | 838 | base name, prefixes for qualification (separate ones for system | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 839 | infrastructure and user-space mechanisms), a slot for the original | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 840 | source position, and some additional flags. | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 841 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 842 |   \medskip A @{text "naming"} provides some additional details for
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 843 | 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 | 844 |   implicit in the theory or proof context.  The @{text "full"}
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 845 | operation (and its variants for different context types) produces a | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 846 | 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 | 847 | main equation of this ``chemical reaction'' when binding new | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 848 | entities in a context is as follows: | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 849 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 850 | \smallskip | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 851 |   \begin{tabular}{l}
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 852 |   @{text "binding + naming \<longrightarrow> long name + name space accesses"}
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 853 |   \end{tabular}
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 854 | \smallskip | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 855 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 856 | \medskip As a general principle, there is a separate name space for | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 857 | 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 | 858 | 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 | 859 | 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 | 860 |   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 | 861 | uniformly for a constant, type constructor, and type class. | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 862 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 863 | There are common schemes to name derived entities systematically | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 864 | 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 | 865 |   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 | 866 |   constant @{text "c"}.  This technique of mapping names from one
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 867 | 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 | 868 | In particular, theorem names derived from a type constructor or type | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 869 | class are better suffixed in addition to the usual qualification, | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 870 |   e.g.\ @{text "c_type.intro"} and @{text "c_class.intro"} for
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 871 |   theorems related to type @{text "c"} and class @{text "c"},
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 872 | respectively. | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 873 | *} | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 874 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 875 | text %mlref {*
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 876 |   \begin{mldecls}
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 877 |   @{index_ML_type binding} \\
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 878 |   @{index_ML Binding.empty: binding} \\
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 879 |   @{index_ML Binding.name: "string -> binding"} \\
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 880 |   @{index_ML Binding.qualify: "bool -> string -> binding -> binding"} \\
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 881 |   @{index_ML Binding.prefix: "bool -> string -> binding -> binding"} \\
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 882 |   @{index_ML Binding.conceal: "binding -> binding"} \\
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 883 |   @{index_ML Binding.str_of: "binding -> string"} \\
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 884 |   \end{mldecls}
 | 
| 20547 | 885 |   \begin{mldecls}
 | 
| 33174 | 886 |   @{index_ML_type Name_Space.naming} \\
 | 
| 887 |   @{index_ML Name_Space.default_naming: Name_Space.naming} \\
 | |
| 888 |   @{index_ML Name_Space.add_path: "string -> Name_Space.naming -> Name_Space.naming"} \\
 | |
| 889 |   @{index_ML Name_Space.full_name: "Name_Space.naming -> binding -> string"} \\
 | |
| 20547 | 890 |   \end{mldecls}
 | 
| 891 |   \begin{mldecls}
 | |
| 33174 | 892 |   @{index_ML_type Name_Space.T} \\
 | 
| 893 |   @{index_ML Name_Space.empty: "string -> Name_Space.T"} \\
 | |
| 894 |   @{index_ML Name_Space.merge: "Name_Space.T * Name_Space.T -> Name_Space.T"} \\
 | |
| 895 |   @{index_ML Name_Space.declare: "bool -> Name_Space.naming -> binding -> Name_Space.T ->
 | |
| 896 | string * Name_Space.T"} \\ | |
| 897 |   @{index_ML Name_Space.intern: "Name_Space.T -> string -> string"} \\
 | |
| 898 |   @{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 | 899 |   @{index_ML Name_Space.is_concealed: "Name_Space.T -> string -> bool"}
 | 
| 20476 | 900 |   \end{mldecls}
 | 
| 20437 | 901 | |
| 20476 | 902 |   \begin{description}
 | 
| 903 | ||
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 904 |   \item @{ML_type binding} represents the abstract concept of name
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 905 | bindings. | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 906 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 907 |   \item @{ML Binding.empty} is the empty binding.
 | 
| 20476 | 908 | |
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 909 |   \item @{ML Binding.name}~@{text "name"} produces a binding with base
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 910 |   name @{text "name"}.
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 911 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 912 |   \item @{ML Binding.qualify}~@{text "mandatory name binding"}
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 913 |   prefixes qualifier @{text "name"} to @{text "binding"}.  The @{text
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 914 | "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 | 915 |   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 | 916 | 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 | 917 | derived specification mechanisms. | 
| 20437 | 918 | |
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 919 |   \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 | 920 | affects the system prefix. This part of extra qualification is | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 921 | typically used in the infrastructure for modular specifications, | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 922 |   notably ``local theory targets'' (see also \chref{ch:local-theory}).
 | 
| 20437 | 923 | |
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 924 |   \item @{ML Binding.conceal}~@{text "binding"} indicates that the
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 925 | binding shall refer to an entity that serves foundational purposes | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 926 | only. This flag helps to mark implementation details of | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 927 | specification mechanism etc. Other tools should not depend on the | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 928 |   particulars of concealed entities (cf.\ @{ML
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 929 | Name_Space.is_concealed}). | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 930 | |
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 931 |   \item @{ML Binding.str_of}~@{text "binding"} produces a string
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 932 | representation for human-readable output, together with some formal | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 933 | markup that might get used in GUI front-ends, for example. | 
| 20476 | 934 | |
| 33174 | 935 |   \item @{ML_type Name_Space.naming} represents the abstract concept of
 | 
| 20476 | 936 | a naming policy. | 
| 20437 | 937 | |
| 33174 | 938 |   \item @{ML Name_Space.default_naming} is the default naming policy.
 | 
| 20476 | 939 | In a theory context, this is usually augmented by a path prefix | 
| 940 | consisting of the theory name. | |
| 941 | ||
| 33174 | 942 |   \item @{ML Name_Space.add_path}~@{text "path naming"} augments the
 | 
| 20488 | 943 | naming policy by extending its path component. | 
| 20437 | 944 | |
| 33174 | 945 |   \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 | 946 | name binding (usually a basic name) into the fully qualified | 
| 29008 | 947 | internal name, according to the given naming policy. | 
| 20476 | 948 | |
| 33174 | 949 |   \item @{ML_type Name_Space.T} represents name spaces.
 | 
| 20476 | 950 | |
| 33174 | 951 |   \item @{ML Name_Space.empty}~@{text "kind"} and @{ML Name_Space.merge}~@{text
 | 
| 20488 | 952 | "(space\<^isub>1, space\<^isub>2)"} are the canonical operations for | 
| 953 | maintaining name spaces according to theory data management | |
| 33174 | 954 |   (\secref{sec:context-data}); @{text "kind"} is a formal comment
 | 
| 955 | to characterize the purpose of a name space. | |
| 20437 | 956 | |
| 33174 | 957 |   \item @{ML Name_Space.declare}~@{text "strict naming bindings
 | 
| 958 | space"} enters a name binding as fully qualified internal name into | |
| 959 | the name space, with external accesses determined by the naming | |
| 960 | policy. | |
| 20476 | 961 | |
| 33174 | 962 |   \item @{ML Name_Space.intern}~@{text "space name"} internalizes a
 | 
| 20476 | 963 | (partially qualified) external name. | 
| 20437 | 964 | |
| 20488 | 965 | This operation is mostly for parsing! Note that fully qualified | 
| 20476 | 966 |   names stemming from declarations are produced via @{ML
 | 
| 33174 | 967 |   "Name_Space.full_name"} and @{ML "Name_Space.declare"}
 | 
| 29008 | 968 |   (or their derivatives for @{ML_type theory} and
 | 
| 20488 | 969 |   @{ML_type Proof.context}).
 | 
| 20437 | 970 | |
| 33174 | 971 |   \item @{ML Name_Space.extern}~@{text "space name"} externalizes a
 | 
| 20476 | 972 | (fully qualified) internal name. | 
| 973 | ||
| 30281 
9ad15d8ed311
renamed NameSpace.base to NameSpace.base_name (in accordance with "full_name");
 wenzelm parents: 
30272diff
changeset | 974 | 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 | 975 | the precise result too much. | 
| 20476 | 976 | |
| 34927 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 977 |   \item @{ML Name_Space.is_concealed}~@{text "space name"} indicates
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 978 |   whether @{text "name"} refers to a strictly private entity that
 | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 979 | other tools are supposed to ignore! | 
| 
c4c02ac736a6
more details on long names, binding/naming, name space;
 wenzelm parents: 
34926diff
changeset | 980 | |
| 20476 | 981 |   \end{description}
 | 
| 982 | *} | |
| 30272 | 983 | |
| 18537 | 984 | end |