# HG changeset patch # User wenzelm # Date 1452716123 -3600 # Node ID 7eaeae127955d9e584f7c14a17b61cd7d111cc09 # Parent 46f0dfedf9ef6c358ad2376002195cb625724ef9 updated section on "Overloaded constant definitions"; diff -r 46f0dfedf9ef -r 7eaeae127955 src/Doc/Isar_Ref/Outer_Syntax.thy --- a/src/Doc/Isar_Ref/Outer_Syntax.thy Wed Jan 13 20:19:49 2016 +0100 +++ b/src/Doc/Isar_Ref/Outer_Syntax.thy Wed Jan 13 21:15:23 2016 +0100 @@ -487,8 +487,9 @@ \<^descr> @{command "print_definitions"} prints dependencies of definitional specifications within the background theory, which may be constants - \secref{sec:consts} or types (\secref{sec:types-pure}, - \secref{sec:hol-typedef}); the ``\!\'' option indicates extra verbosity. + (\secref{sec:term-definitions}, \secref{sec:overloading}) or types + (\secref{sec:types-pure}, \secref{sec:hol-typedef}); the ``\!\'' option + indicates extra verbosity. \<^descr> @{command "print_methods"} prints all proof methods available in the current theory context; the ``\!\'' option indicates extra verbosity. diff -r 46f0dfedf9ef -r 7eaeae127955 src/Doc/Isar_Ref/Spec.thy --- a/src/Doc/Isar_Ref/Spec.thy Wed Jan 13 20:19:49 2016 +0100 +++ b/src/Doc/Isar_Ref/Spec.thy Wed Jan 13 21:15:23 2016 +0100 @@ -280,7 +280,7 @@ \end{matharray} Term definitions may either happen within the logic (as equational axioms of - a certain form, see also see \secref{sec:consts}), or outside of it as + a certain form (see also \secref{sec:overloading}), or outside of it as rewrite system on abstract syntax. The second form is called ``abbreviation''. @@ -686,7 +686,7 @@ proof block. Note that for \<^theory_text>\interpret\ the \eqns\ should be explicitly universally quantified. - \<^descr> \<^theory_text>\global_interpretation defines "defs" rewrites eqns\ interprets \expr\ + \<^descr> \<^theory_text>\global_interpretation defines defs rewrites eqns\ interprets \expr\ into a global theory. When adding declarations to locales, interpreted versions of these @@ -699,7 +699,7 @@ free variable whose name is already bound in the context --- for example, because a constant of that name exists --- add it to the \<^theory_text>\for\ clause. - \<^descr> \<^theory_text>\sublocale name \ defines "defs" expr rewrites eqns\ interprets \expr\ + \<^descr> \<^theory_text>\sublocale name \ defines defs expr rewrites eqns\ interprets \expr\ into the locale \name\. A proof that the specification of \name\ implies the specification of \expr\ is required. As in the localized version of the theorem command, the proof is in the context of \name\. After the proof @@ -936,41 +936,85 @@ \ -section \Unrestricted overloading\ +section \Overloaded constant definitions \label{sec:overloading}\ text \ + Definitions essentially express abbreviations within the logic. The simplest + form of a definition is \c :: \ \ t\, where \c\ is a new constant and \t\ is + a closed term that does not mention \c\. Moreover, so-called \<^emph>\hidden + polymorphism\ is excluded: all type variables in \t\ need to occur in its + type \\\. + + \<^emph>\Overloading\ means that a constant being declared as \c :: \ decl\ may be + defined separately on type instances \c :: (\\<^sub>1, \, \\<^sub>n)\ decl\ for each + type constructor \\\. At most occasions overloading will be used in a + Haskell-like fashion together with type classes by means of \<^theory_text>\instantiation\ + (see \secref{sec:class}). Sometimes low-level overloading is desirable; this + is supported by \<^theory_text>\consts\ and \<^theory_text>\overloading\ explained below. + + The right-hand side of overloaded definitions may mention overloaded + constants recursively at type instances corresponding to the immediate + argument types \\\<^sub>1, \, \\<^sub>n\. Incomplete specification patterns impose + global constraints on all occurrences. E.g.\ \d :: \ \ \\ on the left-hand + side means that all corresponding occurrences on some right-hand side need + to be an instance of this, and general \d :: \ \ \\ will be disallowed. Full + details are given by Kun\v{c}ar @{cite "Kuncar:2015"}. + + \<^medskip> + The \<^theory_text>\consts\ command and the \<^theory_text>\overloading\ target provide a convenient + interface for end-users. Regular specification elements such as @{command + definition}, @{command inductive}, @{command function} may be used in the + body. It is also possible to use \<^theory_text>\consts c :: \\ with later \<^theory_text>\overloading c + \ c :: \\ to keep the declaration and definition of a constant separate. + \begin{matharray}{rcl} + @{command_def "consts"} & : & \theory \ theory\ \\ @{command_def "overloading"} & : & \theory \ local_theory\ \\ \end{matharray} - Isabelle/Pure's definitional schemes support certain forms of overloading - (see \secref{sec:consts}). Overloading means that a constant being declared - as \c :: \ decl\ may be defined separately on type instances \c :: (\\<^sub>1, \, - \\<^sub>n) t decl\ for each type constructor \t\. At most occasions overloading - will be used in a Haskell-like fashion together with type classes by means - of \<^theory_text>\instantiation\ (see \secref{sec:class}). Sometimes low-level - overloading is desirable. The \<^theory_text>\overloading\ target provides a convenient - view for end-users. - @{rail \ + @@{command consts} ((@{syntax name} '::' @{syntax type} @{syntax mixfix}?) +) + ; @@{command overloading} ( spec + ) @'begin' ; - spec: @{syntax name} ( '==' | '\' ) @{syntax term} ( '(' @'unchecked' ')' )? + spec: @{syntax name} ( '\' | '==' ) @{syntax term} ( '(' @'unchecked' ')' )? \} - \<^descr> \<^theory_text>\overloading x\<^sub>1 \ c\<^sub>1 :: \\<^sub>1 and \ x\<^sub>n \ c\<^sub>n :: \\<^sub>n begin\ opens a - theory target (cf.\ \secref{sec:target}) which allows to specify constants - with overloaded definitions. These are identified by an explicitly given - mapping from variable names \x\<^sub>i\ to constants \c\<^sub>i\ at particular type - instances. The definitions themselves are established using common - specification tools, using the names \x\<^sub>i\ as reference to the corresponding - constants. The target is concluded by @{command (local) "end"}. + \<^descr> \<^theory_text>\consts c :: \\ declares constant \c\ to have any instance of type scheme + \\\. The optional mixfix annotations may attach concrete syntax to the + constants declared. + + \<^descr> \<^theory_text>\overloading x\<^sub>1 \ c\<^sub>1 :: \\<^sub>1 \ x\<^sub>n \ c\<^sub>n :: \\<^sub>n begin \ end\ defines + a theory target (cf.\ \secref{sec:target}) which allows to specify already + declared constants via definitions in the body. These are identified by an + explicitly given mapping from variable names \x\<^sub>i\ to constants \c\<^sub>i\ at + particular type instances. The definitions themselves are established using + common specification tools, using the names \x\<^sub>i\ as reference to the + corresponding constants. + + Option \<^theory_text>\(unchecked)\ disables global dependency checks for the + corresponding definition, which is occasionally useful for exotic + overloading; this is a form of axiomatic specification. It is at the + discretion of the user to avoid malformed theory specifications! +\ - A \<^theory_text>\(unchecked)\ option disables global dependency checks for the - corresponding definition, which is occasionally useful for exotic - overloading (see \secref{sec:consts} for a precise description). It is at - the discretion of the user to avoid malformed theory specifications! -\ + +subsubsection \Example\ + +consts null :: 'a + +overloading + null_nat \ "null :: nat" + null_pair \ "null :: 'a \ 'b" +begin + +definition null_nat :: nat + where "null_nat = 0" + +definition null_pair :: "'a \ 'b" + where "null_pair = (null :: 'a, null :: 'b)" + +end section \Incorporating ML code \label{sec:ML}\ @@ -1150,69 +1194,6 @@ \ -subsection \Constants and definitions \label{sec:consts}\ - -text \ - \begin{matharray}{rcl} - @{command_def "consts"} & : & \theory \ theory\ \\ - @{command_def "defs"} & : & \theory \ theory\ \\ - \end{matharray} - - Definitions essentially express abbreviations within the logic. The simplest - form of a definition is \c :: \ \ t\, where \c\ is a newly declared - constant. Isabelle also allows derived forms where the arguments of \c\ - appear on the left, abbreviating a prefix of \\\-abstractions, e.g.\ \c \ \x - y. t\ may be written more conveniently as \c x y \ t\. Moreover, definitions - may be weakened by adding arbitrary pre-conditions: \A \ c x y \ t\. - - \<^medskip> - The built-in well-formedness conditions for definitional specifications are: - - \<^item> Arguments (on the left-hand side) must be distinct variables. - - \<^item> All variables on the right-hand side must also appear on the left-hand - side. - - \<^item> All type variables on the right-hand side must also appear on the - left-hand side; this prohibits \0 :: nat \ length ([] :: \ list)\ for - example. - - \<^item> The definition must not be recursive. Most object-logics provide - definitional principles that can be used to express recursion safely. - - The right-hand side of overloaded definitions may mention overloaded - constants recursively at type instances corresponding to the immediate - argument types \\\<^sub>1, \, \\<^sub>n\. Incomplete specification patterns impose - global constraints on all occurrences, e.g.\ \d :: \ \ \\ on the left-hand - side means that all corresponding occurrences on some right-hand side need - to be an instance of this, general \d :: \ \ \\ will be disallowed. - - @{rail \ - @@{command consts} ((@{syntax name} '::' @{syntax type} @{syntax mixfix}?) +) - ; - @@{command defs} opt? (@{syntax axmdecl} @{syntax prop} +) - ; - opt: '(' @'unchecked'? @'overloaded'? ')' - \} - - \<^descr> \<^theory_text>\consts c :: \\ declares constant \c\ to have any instance of type scheme - \\\. The optional mixfix annotations may attach concrete syntax to the - constants declared. - - \<^descr> \<^theory_text>\defs name: eqn\ introduces \eqn\ as a definitional axiom for some - existing constant. - - The \<^theory_text>\(unchecked)\ option disables global dependency checks for this - definition, which is occasionally useful for exotic overloading. It is at - the discretion of the user to avoid malformed theory specifications! - - The \<^theory_text>\(overloaded)\ option declares definitions to be potentially - overloaded. Unless this option is given, a warning message would be issued - for any definitional equation with a more special type than that of the - corresponding constant declaration. -\ - - section \Naming existing theorems \label{sec:theorems}\ text \ diff -r 46f0dfedf9ef -r 7eaeae127955 src/Doc/manual.bib --- a/src/Doc/manual.bib Wed Jan 13 20:19:49 2016 +0100 +++ b/src/Doc/manual.bib Wed Jan 13 21:15:23 2016 +0100 @@ -1012,6 +1012,17 @@ note = {\url{http://isabelle.in.tum.de/doc/functions.pdf}} } +@inproceedings{Kuncar:2015, + author = {Ondrej Kuncar}, + title = {Correctness of {Isabelle's} Cyclicity Checker: Implementability of Overloading + in Proof Assistants}, + booktitle = {Proceedings of the 2015 Conference on Certified Programs and Proofs, + {CPP} 2015, Mumbai, India, January 15-17, 2015}, + year = {2015}, + url = {http://doi.acm.org/10.1145/2676724.2693175}, + doi = {10.1145/2676724.2693175}, +} + @inproceedings{Kuncar-Popescu:2015, author = {Ondrej Kuncar and Andrei Popescu}, title = {A Consistent Foundation for {Isabelle/HOL}}, diff -r 46f0dfedf9ef -r 7eaeae127955 src/Pure/Isar/isar_syn.ML --- a/src/Pure/Isar/isar_syn.ML Wed Jan 13 20:19:49 2016 +0100 +++ b/src/Pure/Isar/isar_syn.ML Wed Jan 13 21:15:23 2016 +0100 @@ -463,7 +463,7 @@ val _ = Outer_Syntax.command @{command_keyword overloading} "overloaded definitions" - (Scan.repeat1 (Parse.name --| (@{keyword "\"} || @{keyword "=="}) -- Parse.term -- + (Scan.repeat1 (Parse.name --| (@{keyword "=="} || @{keyword "\"}) -- Parse.term -- Scan.optional (@{keyword "("} |-- (@{keyword "unchecked"} >> K false) --| @{keyword ")"}) true >> Scan.triple1) --| Parse.begin >> (fn operations => Toplevel.begin_local_theory true (Overloading.overloading_cmd operations)));