aboutsummaryrefslogtreecommitdiff
path: root/doc/sphinx/language
diff options
context:
space:
mode:
Diffstat (limited to 'doc/sphinx/language')
-rw-r--r--doc/sphinx/language/cic.rst4
-rw-r--r--doc/sphinx/language/core/basic.rst520
-rw-r--r--doc/sphinx/language/core/index.rst30
-rw-r--r--doc/sphinx/language/core/records.rst11
-rw-r--r--doc/sphinx/language/core/sections.rst2
-rw-r--r--doc/sphinx/language/extensions/arguments-command.rst440
-rw-r--r--doc/sphinx/language/extensions/implicit-arguments.rst330
-rw-r--r--doc/sphinx/language/extensions/index.rst1
-rw-r--r--doc/sphinx/language/gallina-extensions.rst130
-rw-r--r--doc/sphinx/language/gallina-specification-language.rst325
10 files changed, 1171 insertions, 622 deletions
diff --git a/doc/sphinx/language/cic.rst b/doc/sphinx/language/cic.rst
index 09a3897a06..e5af39c8fb 100644
--- a/doc/sphinx/language/cic.rst
+++ b/doc/sphinx/language/cic.rst
@@ -24,9 +24,9 @@ to a type and takes the form “*for all x of type* :math:`T`, :math:`P`”. The
“:math:`x` *of type* :math:`T`” is written “:math:`x:T`”. Informally, “:math:`x:T`” can be thought as
“:math:`x` *belongs to* :math:`T`”.
-The types of types are *sorts*. Types and sorts are themselves terms
+The types of types are called :gdef:`sort`\s. Types and sorts are themselves terms
so that terms, types and sorts are all components of a common
-syntactic language of terms which is described in Section :ref:`terms` but,
+syntactic language of terms which is described in Section :ref:`terms`. But
first, we describe sorts.
diff --git a/doc/sphinx/language/core/basic.rst b/doc/sphinx/language/core/basic.rst
new file mode 100644
index 0000000000..9473cc5a15
--- /dev/null
+++ b/doc/sphinx/language/core/basic.rst
@@ -0,0 +1,520 @@
+=============================
+Basic notions and conventions
+=============================
+
+This section provides some essential notions and conventions for reading
+the manual.
+
+We start by explaining the syntax and lexical conventions used in the
+manual. Then, we present the essential vocabulary necessary to read
+the rest of the manual. Other terms are defined throughout the manual.
+The reader may refer to the :ref:`glossary index <glossary_index>`
+for a complete list of defined terms. Finally, we describe the various types of
+settings that |Coq| provides.
+
+Syntax and lexical conventions
+------------------------------
+
+Syntax conventions
+~~~~~~~~~~~~~~~~~~
+
+The syntax described in this documentation is equivalent to that
+accepted by the |Coq| parser, but the grammar has been edited
+to improve readability and presentation.
+
+In the grammar presented in this manual, the terminal symbols are
+black (e.g. :n:`forall`), whereas the nonterminals are green, italic
+and hyperlinked (e.g. :n:`@term`). Some syntax is represented
+graphically using the following kinds of blocks:
+
+:n:`{? item }`
+ An optional item.
+
+:n:`{+ item }`
+ A list of one or more items.
+
+:n:`{* item }`
+ An optional list of items.
+
+:n:`{+s item}`
+ A list of one or more items separated by "s" (e.g. :n:`item__1 s item__2 s item__3`).
+
+:n:`{*s item}`
+ An optional list of items separated by "s".
+
+:n:`{| item__1 | item__2 | ... }`
+ Alternatives (either :n:`item__1` or :n:`item__2` or ...).
+
+`Precedence levels
+<https://en.wikipedia.org/wiki/Order_of_operations>`_ that are
+implemented in the |Coq| parser are shown in the documentation by
+appending the level to the nonterminal name (as in :n:`@term100` or
+:n:`@ltac_expr3`).
+
+.. note::
+
+ |Coq| uses an extensible parser. Plugins and the :ref:`notation
+ system <syntax-extensions-and-notation-scopes>` can extend the
+ syntax at run time. Some notations are defined in the prelude,
+ which is loaded by default. The documented grammar doesn't include
+ these notations. Precedence levels not used by the base grammar
+ are omitted from the documentation, even though they could still be
+ populated by notations or plugins.
+
+ Furthermore, some parsing rules are only activated in certain
+ contexts (:ref:`interactive proof mode <proofhandling>`,
+ :ref:`custom entries <custom-entries>`...).
+
+.. warning::
+
+ Given the complexity of these parsing rules, it would be extremely
+ difficult to create an external program that can properly parse a
+ |Coq| document. Therefore, tool writers are advised to delegate
+ parsing to |Coq|, by communicating with it, for instance through
+ `SerAPI <https://github.com/ejgallego/coq-serapi>`_.
+
+.. seealso:: :cmd:`Print Grammar`
+
+.. _lexical-conventions:
+
+Lexical conventions
+~~~~~~~~~~~~~~~~~~~
+
+Blanks
+ Space, newline and horizontal tab are considered blanks.
+ Blanks are ignored but they separate tokens.
+
+Comments
+ Comments are enclosed between ``(*`` and ``*)``. They can be nested.
+ They can contain any character. However, embedded :n:`@string` literals must be
+ correctly closed. Comments are treated as blanks.
+
+Identifiers
+ Identifiers, written :n:`@ident`, are sequences of letters, digits, ``_`` and
+ ``'``, that do not start with a digit or ``'``. That is, they are
+ recognized by the following grammar (except that the string ``_`` is reserved;
+ it is not a valid identifier):
+
+ .. insertprodn ident subsequent_letter
+
+ .. prodn::
+ ident ::= @first_letter {* @subsequent_letter }
+ first_letter ::= {| a .. z | A .. Z | _ | @unicode_letter }
+ subsequent_letter ::= {| @first_letter | @digit | ' | @unicode_id_part }
+
+ All characters are meaningful. In particular, identifiers are case-sensitive.
+ :production:`unicode_letter` non-exhaustively includes Latin,
+ Greek, Gothic, Cyrillic, Arabic, Hebrew, Georgian, Hangul, Hiragana
+ and Katakana characters, CJK ideographs, mathematical letter-like
+ symbols and non-breaking space. :production:`unicode_id_part`
+ non-exhaustively includes symbols for prime letters and subscripts.
+
+Numerals
+ Numerals are sequences of digits with an optional fractional part
+ and exponent, optionally preceded by a minus sign. :n:`@int` is an integer;
+ a numeral without fractional or exponent parts. :n:`@num` is a non-negative
+ integer. Underscores embedded in the digits are ignored, for example
+ ``1_000_000`` is the same as ``1000000``.
+
+ .. insertprodn numeral digit
+
+ .. prodn::
+ numeral ::= {+ @digit } {? . {+ @digit } } {? {| e | E } {? {| + | - } } {+ @digit } }
+ int ::= {? - } {+ @digit }
+ num ::= {+ @digit }
+ digit ::= 0 .. 9
+
+Strings
+ Strings begin and end with ``"`` (double quote). Use ``""`` to represent
+ a double quote character within a string. In the grammar, strings are
+ identified with :production:`string`.
+
+Keywords
+ The following character sequences are reserved keywords that cannot be
+ used as identifiers::
+
+ _ Axiom CoFixpoint Definition Fixpoint Hypothesis Parameter Prop
+ SProp Set Theorem Type Variable as at cofix discriminated else end
+ fix for forall fun if in let match return then where with
+
+ Note that notations and plugins may define additional keywords.
+
+Other tokens
+ The set of
+ tokens defined at any given time can vary because the :cmd:`Notation`
+ command can define new tokens. A :cmd:`Require` command may load more notation definitions,
+ while the end of a :cmd:`Section` may remove notations. Some notations
+ are defined in the standard library (see :ref:`thecoqlibrary`) and are generally
+ loaded automatically at startup time.
+
+ Here are the character sequences that |Coq| directly defines as tokens
+ without using :cmd:`Notation`::
+
+ ! #[ % & ' ( () (bfs) (dfs) ) * ** + , - ->
+ . .( .. ... / : ::= := :> :>> ; < <+ <- <:
+ <<: <= = => > >-> >= ? @ @{ [ [= ] _
+ `( `{ { {| | |- || }
+
+ When multiple tokens match the beginning of a sequence of characters,
+ the longest matching token is used.
+ Occasionally you may need to insert spaces to separate tokens. For example,
+ if ``~`` and ``~~`` are both defined as tokens, the inputs ``~ ~`` and
+ ``~~`` generate different tokens, whereas if `~~` is not defined, then the
+ two inputs are equivalent.
+
+Essential vocabulary
+--------------------
+
+This section presents the most essential notions to understand the
+rest of the |Coq| manual: :term:`terms <term>` and :term:`types
+<type>` on the one hand, :term:`commands <command>` and :term:`tactics
+<tactic>` on the other hand.
+
+.. glossary::
+
+ term
+
+ Terms are the basic expressions of |Coq|. Terms can represent
+ mathematical expressions, propositions and proofs, but also
+ executable programs and program types.
+
+ Here is the top-level syntax of terms. Each of the listed
+ constructs is presented in a dedicated section. Some of these
+ constructs (like :n:`@term_forall_or_fun`) are part of the core
+ language that the kernel of |Coq| understands and are therefore
+ described in :ref:`this chapter <core-language>`, while
+ others (like :n:`@term_if`) are language extensions that are
+ presented in :ref:`the next chapter <extensions>`.
+
+ .. insertprodn term qualid_annotated
+
+ .. prodn::
+ term ::= @term_forall_or_fun
+ | @term_let
+ | @term_if
+ | @term_fix
+ | @term_cofix
+ | @term100
+ term100 ::= @term_cast
+ | @term10
+ term10 ::= @term_application
+ | @one_term
+ one_term ::= @term_explicit
+ | @term1
+ term1 ::= @term_projection
+ | @term_scope
+ | @term0
+ term0 ::= @qualid_annotated
+ | @sort
+ | @primitive_notations
+ | @term_evar
+ | @term_match
+ | @term_record
+ | @term_generalizing
+ | @term_ltac
+ | ( @term )
+ qualid_annotated ::= @qualid {? @univ_annot }
+
+ .. note::
+
+ Many :term:`commands <command>` and :term:`tactics <tactic>`
+ use :n:`@one_term` (in the syntax of their arguments) rather
+ than :n:`@term`. The former need to be enclosed in
+ parentheses unless they're very simple, such as a single
+ identifier. This avoids confusing a space-separated list of
+ terms or identifiers with a :n:`@term_application`.
+
+ type
+
+ To be valid and accepted by the |Coq| kernel, a term needs an
+ associated type. We express this relationship by “:math:`x` *of
+ type* :math:`T`”, which we write as “:math:`x:T`”. Informally,
+ “:math:`x:T`” can be thought as “:math:`x` *belongs to*
+ :math:`T`”.
+
+ The |Coq| kernel is a type checker: it verifies that a term has
+ the expected type by applying a set of typing rules (see
+ :ref:`Typing-rules`). If that's indeed the case, we say that the
+ term is :gdef:`well-typed`.
+
+ A special feature of the |Coq| language is that types can depend
+ on terms (we say that the language is `dependently-typed
+ <https://en.wikipedia.org/wiki/Dependent_type>`_). Because of
+ this, types and terms share a common syntax. All types are terms,
+ but not all terms are types:
+
+ .. insertprodn type type
+
+ .. prodn::
+ type ::= @term
+
+ Intuitively, types may be viewed as sets containing terms. We
+ say that a type is :gdef:`inhabited` if it contains at least one
+ term (i.e. if we can find a term which is associated with this
+ type). We call such terms :gdef:`witness`\es. Note that deciding
+ whether a type is inhabited is `undecidable
+ <https://en.wikipedia.org/wiki/Undecidable_problem>`_.
+
+ Formally, types can be used to construct logical foundations for
+ mathematics alternative to the standard `"set theory"
+ <https://en.wikipedia.org/wiki/Set_theory>`_: we call such
+ logical foundations `"type theories"
+ <https://en.wikipedia.org/wiki/Type_theory>`_. |Coq| is based on
+ the Calculus of Inductive Constructions, which is a particular
+ instance of type theory.
+
+ sentence
+
+ |Coq| documents are made of a series of sentences that contain
+ :term:`commands <command>` or :term:`tactics <tactic>`, generally
+ terminated with a period and optionally decorated with
+ :term:`attributes <attribute>`.
+
+ .. insertprodn document sentence
+
+ .. prodn::
+ document ::= {* @sentence }
+ sentence ::= {? @attributes } @command .
+ | {? @attributes } {? @num : } @query_command .
+ | {? @attributes } {? @toplevel_selector } @ltac_expr {| . | ... }
+ | @control_command
+
+ :n:`@ltac_expr` syntax supports both simple and compound
+ :term:`tactics <tactic>`. For example: ``split`` is a simple
+ tactic while ``split; auto`` combines two simple tactics.
+
+ command
+
+ A :production:`command` can be used to modify the state of a |Coq|
+ document, for instance by declaring a new object, or to get
+ information about the current state.
+
+ By convention, command names begin with uppercase letters.
+ Commands appear in the HTML documentation in blue or gray boxes
+ after the label "Command". In the pdf, they appear after the
+ boldface label "Command:". Commands are listed in the
+ :ref:`command_index`. Example:
+
+ .. cmd:: Comments {* @string }
+
+ This command prints "Comments ok" and does not change anything
+ to the state of the document.
+
+ tactic
+
+ Tactics specify how to transform the current proof state as a
+ step in creating a proof. They are syntactically valid only when
+ |Coq| is in proof mode, such as after a :cmd:`Theorem` command
+ and before any subsequent proof-terminating command such as
+ :cmd:`Qed`. See :ref:`proofhandling` for more on proof mode.
+
+ By convention, tactic names begin with lowercase letters. Tactic
+ appear in the HTML documentation in blue or gray boxes after the
+ label "Tactic". In the pdf, they appear after the boldface label
+ "Tactic:". Tactics are listed in the :ref:`tactic_index`.
+
+Settings
+--------
+
+There are several mechanisms for changing the behavior of |Coq|. The
+:term:`attribute` mechanism is used to modify the behavior of a single
+:term:`sentence`. The :term:`flag`, :term:`option` and :term:`table`
+mechanisms are used to modify the behavior of |Coq| more globally in a
+document or project.
+
+.. _attributes:
+
+Attributes
+~~~~~~~~~~
+
+An :gdef:`attribute` modifies the behavior of a single sentence.
+Syntactically, most commands and tactics can be decorated with
+attributes (cf. :n:`@sentence`), but attributes not supported by the
+command or tactic will trigger :warn:`This command does not support
+this attribute`.
+
+.. insertprodn attributes legacy_attr
+
+.. prodn::
+ attributes ::= {* #[ {*, @attribute } ] } {* @legacy_attr }
+ attribute ::= @ident {? @attr_value }
+ attr_value ::= = @string
+ | ( {*, @attribute } )
+ legacy_attr ::= {| Local | Global }
+ | {| Polymorphic | Monomorphic }
+ | {| Cumulative | NonCumulative }
+ | Private
+ | Program
+
+The order of top-level attributes doesn't affect their meaning. ``#[foo,bar]``, ``#[bar,foo]``,
+``#[foo]#[bar]`` and ``#[bar]#[foo]`` are equivalent.
+
+The legacy attributes (:n:`@legacy_attr`) provide an older, alternate syntax
+for certain attributes. They are equivalent to new attributes as follows:
+
+================ ================================
+Legacy attribute New attribute
+================ ================================
+`Local` :attr:`local`
+`Global` :attr:`global`
+`Polymorphic` :attr:`universes(polymorphic)`
+`Monomorphic` :attr:`universes(monomorphic)`
+`Cumulative` :attr:`universes(cumulative)`
+`NonCumulative` :attr:`universes(noncumulative)`
+`Private` :attr:`private(matching)`
+`Program` :attr:`program`
+================ ================================
+
+Attributes appear in the HTML documentation in blue or gray boxes
+after the label "Attribute". In the pdf, they appear after the
+boldface label "Attribute:". Attributes are listed in the
+:ref:`attribute_index`.
+
+.. warn:: This command does not support this attribute: @ident.
+ :name: This command does not support this attribute
+
+ This warning is configured to behave as an error by default. You
+ may turn it into a normal warning by using the :opt:`Warnings` option:
+
+ .. coqtop:: none
+
+ Set Silent.
+
+ .. coqtop:: all warn
+
+ Set Warnings "unsupported-attributes".
+ #[ foo ] Comments.
+
+.. _flags-options-tables:
+
+Flags, Options and Tables
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The following types of settings can be used to change the behavior of |Coq| in
+subsequent commands and tactics (see :ref:`set_unset_scope_qualifiers` for a
+more precise description of the scope of these settings):
+
+* A :gdef:`flag` has a boolean value, such as :flag:`Universe Polymorphism`.
+* An :gdef:`option` generally has a numeric or string value, such as :opt:`Firstorder Depth`.
+* A :gdef:`table` contains a set of :token:`string`\s or :token:`qualid`\s.
+* In addition, some commands provide settings, such as :cmd:`Extraction Language`.
+
+.. FIXME Convert "Extraction Language" to an option.
+
+Flags, options and tables are identified by a series of identifiers, each with an initial
+capital letter.
+
+Flags, options and tables appear in the HTML documentation in blue or
+gray boxes after the labels "Flag", "Option" and "Table". In the pdf,
+they appear after a boldface label. They are listed in the
+:ref:`options_index`.
+
+.. cmd:: Set @setting_name {? {| @int | @string } }
+ :name: Set
+
+ .. insertprodn setting_name setting_name
+
+ .. prodn::
+ setting_name ::= {+ @ident }
+
+ If :n:`@setting_name` is a flag, no value may be provided; the flag
+ is set to on.
+ If :n:`@setting_name` is an option, a value of the appropriate type
+ must be provided; the option is set to the specified value.
+
+ This command supports the :attr:`local`, :attr:`global` and :attr:`export` attributes.
+ They are described :ref:`here <set_unset_scope_qualifiers>`.
+
+ .. warn:: There is no flag or option with this name: "@setting_name".
+
+ This warning message can be raised by :cmd:`Set` and
+ :cmd:`Unset` when :n:`@setting_name` is unknown. It is a
+ warning rather than an error because this helps library authors
+ produce |Coq| code that is compatible with several |Coq| versions.
+ To preserve the same behavior, they may need to set some
+ compatibility flags or options that did not exist in previous
+ |Coq| versions.
+
+.. cmd:: Unset @setting_name
+ :name: Unset
+
+ If :n:`@setting_name` is a flag, it is set to off. If :n:`@setting_name` is an option, it is
+ set to its default value.
+
+ This command supports the :attr:`local`, :attr:`global` and :attr:`export` attributes.
+ They are described :ref:`here <set_unset_scope_qualifiers>`.
+
+.. cmd:: Add @setting_name {+ {| @qualid | @string } }
+
+ Adds the specified values to the table :n:`@setting_name`.
+
+.. cmd:: Remove @setting_name {+ {| @qualid | @string } }
+
+ Removes the specified value from the table :n:`@setting_name`.
+
+.. cmd:: Test @setting_name {? for {+ {| @qualid | @string } } }
+
+ If :n:`@setting_name` is a flag or option, prints its current value.
+ If :n:`@setting_name` is a table: if the `for` clause is specified, reports
+ whether the table contains each specified value, otherwise this is equivalent to
+ :cmd:`Print Table`. The `for` clause is not valid for flags and options.
+
+ .. exn:: There is no flag, option or table with this name: "@setting_name".
+
+ This error message is raised when calling the :cmd:`Test`
+ command (without the `for` clause), or the :cmd:`Print Table`
+ command, for an unknown :n:`@setting_name`.
+
+ .. exn:: There is no qualid-valued table with this name: "@setting_name".
+ There is no string-valued table with this name: "@setting_name".
+
+ These error messages are raised when calling the :cmd:`Add` or
+ :cmd:`Remove` commands, or the :cmd:`Test` command with the
+ `for` clause, if :n:`@setting_name` is unknown or does not have
+ the right type.
+
+.. cmd:: Print Options
+
+ Prints the current value of all flags and options, and the names of all tables.
+
+.. cmd:: Print Table @setting_name
+
+ Prints the values in the table :n:`@setting_name`.
+
+.. cmd:: Print Tables
+
+ A synonym for :cmd:`Print Options`.
+
+.. _set_unset_scope_qualifiers:
+
+Locality attributes supported by :cmd:`Set` and :cmd:`Unset`
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The :cmd:`Set` and :cmd:`Unset` commands support the :attr:`local`,
+:attr:`global` and :attr:`export` locality attributes:
+
+* no attribute: the original setting is *not* restored at the end of
+ the current module or section.
+* :attr:`local` (or alternatively, the ``Local`` prefix): the setting
+ is applied within the current module or section. The original value
+ of the setting is restored at the end of the current module or
+ section.
+* :attr:`export` (or alternatively, the ``Export`` prefix): similar to
+ :attr:`local`, the original value of the setting is restored at the
+ end of the current module or section. In addition, if the value is
+ set in a module, then :cmd:`Import`\-ing the module sets the option
+ or flag.
+* :attr:`global` (or alternatively, the ``Global`` prefix): the
+ original setting is *not* restored at the end of the current module
+ or section. In addition, if the value is set in a file, then
+ :cmd:`Require`\-ing the file sets the option.
+
+Newly opened modules and sections inherit the current settings.
+
+.. note::
+
+ We discourage using the :attr:`global` attribute with the :cmd:`Set` and
+ :cmd:`Unset` commands. If your goal is to define
+ project-wide settings, you should rather use the command-line
+ arguments ``-set`` and ``-unset`` for setting flags and options
+ (cf. :ref:`command-line-options`).
diff --git a/doc/sphinx/language/core/index.rst b/doc/sphinx/language/core/index.rst
index 5ee960d99b..5e83672463 100644
--- a/doc/sphinx/language/core/index.rst
+++ b/doc/sphinx/language/core/index.rst
@@ -6,23 +6,26 @@ Core language
At the heart of the Coq proof assistant is the Coq kernel. While
users have access to a language with many convenient features such as
-notations, implicit arguments, etc. (that are presented in the
-:ref:`next chapter <extensions>`), such complex terms get translated
-down to a core language (the Calculus of Inductive Constructions) that
-the kernel understands, and which we present here. Furthermore, while
-users can build proofs interactively using tactics (see Chapter
+:ref:`notations <syntax-extensions-and-notation-scopes>`,
+:ref:`implicit arguments <ImplicitArguments>`, etc. (presented in the
+:ref:`next chapter <extensions>`), those features are translated into
+the core language (the Calculus of Inductive Constructions) that the
+kernel understands, which we present here. Furthermore, while users
+can build proofs interactively using tactics (see Chapter
:ref:`writing-proofs`), the role of these tactics is to incrementally
build a "proof term" which the kernel will verify. More precisely, a
-proof term is a term of the Calculus of Inductive Constructions whose
-type corresponds to a theorem statement. The kernel is a type checker
-which verifies that terms have their expected type.
+proof term is a :term:`term` of the Calculus of Inductive
+Constructions whose :term:`type` corresponds to a theorem statement.
+The kernel is a type checker which verifies that terms have their
+expected types.
-This separation between the kernel on the one hand and the elaboration
-engine and tactics on the other hand follows what is known as the "de
-Bruijn criterion" (keeping a small and well delimited trusted code
+This separation between the kernel on one hand and the
+:ref:`elaboration engine <extensions>` and :ref:`tactics
+<writing-proofs>` on the other follows what is known as the :gdef:`de
+Bruijn criterion` (keeping a small and well delimited trusted code
base within a proof assistant which can be much more complex). This
-separation makes it possible to reduce the trust in the whole system
-to trusting a smaller, critical component: the kernel. In particular,
+separation makes it necessary to trust only a smaller, critical
+component (the kernel) instead of the entire system. In particular,
users may rely on external plugins that provide advanced and complex
tactics without fear of these tactics being buggy, because the kernel
will have to check their output.
@@ -30,6 +33,7 @@ will have to check their output.
.. toctree::
:maxdepth: 1
+ basic
../gallina-specification-language
../cic
records
diff --git a/doc/sphinx/language/core/records.rst b/doc/sphinx/language/core/records.rst
index d380d83d6c..0080f1d052 100644
--- a/doc/sphinx/language/core/records.rst
+++ b/doc/sphinx/language/core/records.rst
@@ -15,14 +15,17 @@ expressions. In this sense, the :cmd:`Record` construction allows defining
.. cmd:: {| Record | Structure } @record_definition {* with @record_definition }
:name: Record; Structure
- .. insertprodn record_definition field_body
+ .. insertprodn record_definition field_def
.. prodn::
record_definition ::= {? > } @ident_decl {* @binder } {? : @type } {? @ident } %{ {*; @record_field } %} {? @decl_notations }
- record_field ::= {* #[ {*, @attr } ] } @name {? @field_body } {? %| @num } {? @decl_notations }
+ record_field ::= {* #[ {*, @attribute } ] } @name {? @field_body } {? %| @num } {? @decl_notations }
field_body ::= {* @binder } @of_type
| {* @binder } @of_type := @term
| {* @binder } := @term
+ term_record ::= %{%| {* @field_def } %|%}
+ field_def ::= @qualid {* @binder } := @term
+
Each :n:`@record_definition` defines a record named by :n:`@ident_decl`.
The constructor name is given by :n:`@ident`.
@@ -112,13 +115,13 @@ You can override the display format for specified types by adding entries to the
:name: Printing Record
Specifies a set of qualids which are displayed as records. Use the
- :cmd:`Add @table` and :cmd:`Remove @table` commands to update the set of qualids.
+ :cmd:`Add` and :cmd:`Remove` commands to update the set of qualids.
.. table:: Printing Constructor @qualid
:name: Printing Constructor
Specifies a set of qualids which are displayed as constructors. Use the
- :cmd:`Add @table` and :cmd:`Remove @table` commands to update the set of qualids.
+ :cmd:`Add` and :cmd:`Remove` commands to update the set of qualids.
This syntax can also be used for pattern matching.
diff --git a/doc/sphinx/language/core/sections.rst b/doc/sphinx/language/core/sections.rst
index 9ad8df2b1b..df50dbafe3 100644
--- a/doc/sphinx/language/core/sections.rst
+++ b/doc/sphinx/language/core/sections.rst
@@ -72,7 +72,7 @@ Sections create local contexts which can be shared across multiple definitions.
Most commands, like :cmd:`Hint`, :cmd:`Notation`, option management, … which
appear inside a section are canceled when the section is closed.
-.. cmd:: Let @ident @def_body
+.. cmd:: Let @ident_decl @def_body
Let Fixpoint @fix_definition {* with @fix_definition }
Let CoFixpoint @cofix_definition {* with @cofix_definition }
:name: Let; Let Fixpoint; Let CoFixpoint
diff --git a/doc/sphinx/language/extensions/arguments-command.rst b/doc/sphinx/language/extensions/arguments-command.rst
new file mode 100644
index 0000000000..34a48b368b
--- /dev/null
+++ b/doc/sphinx/language/extensions/arguments-command.rst
@@ -0,0 +1,440 @@
+.. _ArgumentsCommand:
+
+Setting properties of a function's arguments
+++++++++++++++++++++++++++++++++++++++++++++
+
+.. cmd:: Arguments @smart_qualid {* @arg_specs } {* , {* @implicits_alt } } {? : {+, @args_modifier } }
+ :name: Arguments
+
+ .. insertprodn smart_qualid args_modifier
+
+ .. prodn::
+ smart_qualid ::= @qualid
+ | @by_notation
+ by_notation ::= @string {? % @scope_key }
+ argument_spec ::= {? ! } @name {? % @scope_key }
+ arg_specs ::= @argument_spec
+ | /
+ | &
+ | ( {+ @argument_spec } ) {? % @scope_key }
+ | [ {+ @argument_spec } ] {? % @scope_key }
+ | %{ {+ @argument_spec } %} {? % @scope_key }
+ implicits_alt ::= @name
+ | [ {+ @name } ]
+ | %{ {+ @name } %}
+ args_modifier ::= simpl nomatch
+ | simpl never
+ | default implicits
+ | clear implicits
+ | clear scopes
+ | clear bidirectionality hint
+ | rename
+ | assert
+ | extra scopes
+ | clear scopes and implicits
+ | clear implicits and scopes
+
+ Specifies properties of the arguments of a function after the function has already
+ been defined. It gives fine-grained
+ control over the elaboration process (i.e. the translation of Gallina language
+ extensions into the core language used by the kernel). The command's effects include:
+
+ * Making arguments implicit. Afterward, implicit arguments
+ must be omitted in any expression that applies :token:`smart_qualid`.
+ * Declaring that some arguments of a given function should
+ be interpreted in a given scope.
+ * Affecting when the :tacn:`simpl` and :tacn:`cbn` tactics unfold the function.
+ See :ref:`Args_effect_on_unfolding`.
+ * Providing bidirectionality hints. See :ref:`bidirectionality_hints`.
+
+ This command supports the :attr:`local` and :attr:`global` attributes.
+ Default behavior is to limit the effect to the current section but also to
+ extend their effect outside the current module or library file.
+ Applying :attr:`local` limits the effect of the command to the current module if
+ it's not in a section. Applying :attr:`global` within a section extends the
+ effect outside the current sections and current module in which the command appears.
+
+ `/`
+ the function will be unfolded only if it's applied to at least the
+ arguments appearing before the `/`. See :ref:`Args_effect_on_unfolding`.
+
+ .. exn:: The / modifier may only occur once.
+ :undocumented:
+
+ `&`
+ tells the type checking algorithm to first type check the arguments
+ before the `&` and then to propagate information from that typing context
+ to type check the remaining arguments. See :ref:`bidirectionality_hints`.
+
+ .. exn:: The & modifier may only occur once.
+ :undocumented:
+
+ :n:`( ... ) {? % @scope }`
+ :n:`(@name__1 @name__2 ...)%@scope` is shorthand for :n:`@name__1%@scope @name__2%@scope ...`
+
+ :n:`[ ... ] {? % @scope }`
+ declares the enclosed names as implicit, non-maximally inserted.
+ :n:`[@name__1 @name__2 ... ]%@scope` is equivalent to :n:`[@name__1]%@scope [@name__2]%@scope ...`
+
+ :n:`%{ ... %} {? % @scope }`
+ declares the enclosed names as implicit, maximally inserted.
+ :n:`%{@name__1 @name__2 ... %}%@scope` is equivalent to :n:`%{@name__1%}%@scope %{@name__2%}%@scope ...`
+
+ `!`
+ the function will be unfolded only if all the arguments marked with `!`
+ evaulate to constructors. See :ref:`Args_effect_on_unfolding`.
+
+ :n:`@name {? % @scope }`
+ a *formal parameter* of the function :n:`@smart_qualid` (i.e.
+ the parameter name used in the function definition). Unless `rename` is specified,
+ the list of :n:`@name`\s must be a prefix of the formal parameters, including all implicit
+ arguments. `_` can be used to skip over a formal parameter.
+ :token:`scope` can be either a scope name or its delimiting key. See :ref:`binding_to_scope`.
+
+ `clear implicits`
+ makes all implicit arguments into explicit arguments
+ `default implicits`
+ automatically determine the implicit arguments of the object.
+ See :ref:`auto_decl_implicit_args`.
+ `rename`
+ rename implicit arguments for the object. See the example :ref:`here <renaming_implicit_arguments>`.
+ `assert`
+ assert that the object has the expected number of arguments with the
+ expected names. See the example here: :ref:`renaming_implicit_arguments`.
+
+ .. warn:: This command is just asserting the names of arguments of @qualid. If this is what you want, add ': assert' to silence the warning. If you want to clear implicit arguments, add ': clear implicits'. If you want to clear notation scopes, add ': clear scopes'
+ :undocumented:
+
+ `clear scopes`
+ clears argument scopes of :n:`@smart_qualid`
+ `extra scopes`
+ defines extra argument scopes, to be used in case of coercion to ``Funclass``
+ (see the :ref:`implicitcoercions` chapter) or with a computed type.
+ `simpl nomatch`
+ prevents performing a simplification step for :n:`@smart_qualid`
+ that would expose a match construct in the head position. See :ref:`Args_effect_on_unfolding`.
+ `simpl never`
+ prevents performing a simplification step for :n:`@smart_qualid`. See :ref:`Args_effect_on_unfolding`.
+
+ `clear bidirectionality hint`
+ removes the bidirectionality hint, the `&`
+
+ :n:`@implicits_alt`
+ use to specify alternative implicit argument declarations
+ for functions that can only be
+ applied to a fixed number of arguments (excluding, for instance,
+ functions whose type is polymorphic).
+ For parsing, the longest list of implicit arguments matching the function application
+ is used to select which implicit arguments are inserted.
+ For printing, the alternative with the most implicit arguments is used; the
+ implict arguments will be omitted if :flag:`Printing Implicit` is not set.
+ See the example :ref:`here<example_more_implicits>`.
+
+ .. todo the above feature seems a bit unnatural and doesn't play well with partial
+ application. See https://github.com/coq/coq/pull/11718#discussion_r408841762
+
+ Use :cmd:`About` to view the current implicit arguments setting for a :token:`smart_qualid`.
+
+ Or use the :cmd:`Print Implicit` command to see the implicit arguments
+ of an object (see :ref:`displaying-implicit-args`).
+
+Manual declaration of implicit arguments
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. example::
+
+ .. coqtop:: reset all
+
+ Inductive list (A : Type) : Type :=
+ | nil : list A
+ | cons : A -> list A -> list A.
+
+ Check (cons nat 3 (nil nat)).
+
+ Arguments cons [A] _ _.
+
+ Arguments nil {A}.
+
+ Check (cons 3 nil).
+
+ Fixpoint map (A B : Type) (f : A -> B) (l : list A) : list B :=
+ match l with nil => nil | cons a t => cons (f a) (map A B f t) end.
+
+ Fixpoint length (A : Type) (l : list A) : nat :=
+ match l with nil => 0 | cons _ m => S (length A m) end.
+
+ Arguments map [A B] f l.
+
+ Arguments length {A} l. (* A has to be maximally inserted *)
+
+ Check (fun l:list (list nat) => map length l).
+
+.. _example_more_implicits:
+
+.. example:: Multiple alternatives with :n:`@implicits_alt`
+
+ .. coqtop:: all
+
+ Arguments map [A B] f l, [A] B f l, A B f l.
+
+ Check (fun l => map length l = map (list nat) nat length l).
+
+.. _auto_decl_implicit_args:
+
+Automatic declaration of implicit arguments
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ The ":n:`default implicits`" :token:`args_modifier` clause tells |Coq| to automatically determine the
+ implicit arguments of the object.
+
+ Auto-detection is governed by flags specifying whether strict,
+ contextual, or reversible-pattern implicit arguments must be
+ considered or not (see :ref:`controlling-strict-implicit-args`, :ref:`controlling-contextual-implicit-args`,
+ :ref:`controlling-rev-pattern-implicit-args` and also :ref:`controlling-insertion-implicit-args`).
+
+.. example:: Default implicits
+
+ .. coqtop:: reset all
+
+ Inductive list (A:Set) : Set :=
+ | nil : list A
+ | cons : A -> list A -> list A.
+
+ Arguments cons : default implicits.
+
+ Print Implicit cons.
+
+ Arguments nil : default implicits.
+
+ Print Implicit nil.
+
+ Set Contextual Implicit.
+
+ Arguments nil : default implicits.
+
+ Print Implicit nil.
+
+The computation of implicit arguments takes account of the unfolding
+of constants. For instance, the variable ``p`` below has type
+``(Transitivity R)`` which is reducible to
+``forall x,y:U, R x y -> forall z:U, R y z -> R x z``. As the variables ``x``, ``y`` and ``z``
+appear strictly in the body of the type, they are implicit.
+
+.. coqtop:: all
+
+ Parameter X : Type.
+
+ Definition Relation := X -> X -> Prop.
+
+ Definition Transitivity (R:Relation) := forall x y:X, R x y -> forall z:X, R y z -> R x z.
+
+ Parameters (R : Relation) (p : Transitivity R).
+
+ Arguments p : default implicits.
+
+ Print p.
+
+ Print Implicit p.
+
+ Parameters (a b c : X) (r1 : R a b) (r2 : R b c).
+
+ Check (p r1 r2).
+
+
+.. _renaming_implicit_arguments:
+
+Renaming implicit arguments
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. example:: (continued) Renaming implicit arguments
+
+ .. coqtop:: all
+
+ Arguments p [s t] _ [u] _: rename.
+
+ Check (p r1 (u:=c)).
+
+ Check (p (s:=a) (t:=b) r1 (u:=c) r2).
+
+ Fail Arguments p [s t] _ [w] _ : assert.
+
+.. _binding_to_scope:
+
+Binding arguments to a scope
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ The following command declares that the first two arguments of :g:`plus_fct`
+ are in the :token:`scope` delimited by the key ``F`` (``Rfun_scope``) and the third
+ argument is in the scope delimited by the key ``R`` (``R_scope``).
+
+ .. coqdoc::
+
+ Arguments plus_fct (f1 f2)%F x%R.
+
+ When interpreting a term, if some of the arguments of :token:`smart_qualid` are built
+ from a notation, then this notation is interpreted in the scope stack
+ extended by the scope bound (if any) to this argument. The effect of
+ the scope is limited to the argument itself. It does not propagate to
+ subterms but the subterms that, after interpretation of the notation,
+ turn to be themselves arguments of a reference are interpreted
+ accordingly to the argument scopes bound to this reference.
+
+.. note::
+
+ In notations, the subterms matching the identifiers of the
+ notations are interpreted in the scope in which the identifiers
+ occurred at the time of the declaration of the notation. Here is an
+ example:
+
+ .. coqtop:: all
+
+ Parameter g : bool -> bool.
+ Declare Scope mybool_scope.
+
+ Notation "@@" := true (only parsing) : bool_scope.
+ Notation "@@" := false (only parsing): mybool_scope.
+
+ Bind Scope bool_scope with bool.
+ Notation "# x #" := (g x) (at level 40).
+ Check # @@ #.
+ Arguments g _%mybool_scope.
+ Check # @@ #.
+ Delimit Scope mybool_scope with mybool.
+ Check # @@%mybool #.
+
+.. _Args_effect_on_unfolding:
+
+Effects of :cmd:`Arguments` on unfolding
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
++ `simpl never` indicates that a constant should never be unfolded by :tacn:`cbn`,
+ :tacn:`simpl` or :tacn:`hnf`:
+
+ .. example::
+
+ .. coqtop:: all
+
+ Arguments minus n m : simpl never.
+
+ After that command an expression like :g:`(minus (S x) y)` is left
+ untouched by the tactics :tacn:`cbn` and :tacn:`simpl`.
+
++ A constant can be marked to be unfolded only if it's applied to at least
+ the arguments appearing before the `/` in a :cmd:`Arguments` command.
+
+ .. example::
+
+ .. coqtop:: all
+
+ Definition fcomp A B C f (g : A -> B) (x : A) : C := f (g x).
+ Arguments fcomp {A B C} f g x /.
+ Notation "f \o g" := (fcomp f g) (at level 50).
+
+ After that command the expression :g:`(f \o g)` is left untouched by
+ :tacn:`simpl` while :g:`((f \o g) t)` is reduced to :g:`(f (g t))`.
+ The same mechanism can be used to make a constant volatile, i.e.
+ always unfolded.
+
+ .. example::
+
+ .. coqtop:: all
+
+ Definition volatile := fun x : nat => x.
+ Arguments volatile / x.
+
++ A constant can be marked to be unfolded only if an entire set of
+ arguments evaluates to a constructor. The ``!`` symbol can be used to mark
+ such arguments.
+
+ .. example::
+
+ .. coqtop:: all
+
+ Arguments minus !n !m.
+
+ After that command, the expression :g:`(minus (S x) y)` is left untouched
+ by :tacn:`simpl`, while :g:`(minus (S x) (S y))` is reduced to :g:`(minus x y)`.
+
++ `simpl nomatch` indicates that a constant should not be unfolded if it would expose
+ a `match` construct in the head position. This affects the :tacn:`cbn`,
+ :tacn:`simpl` and :tacn:`hnf` tactics.
+
+ .. example::
+
+ .. coqtop:: all
+
+ Arguments minus n m : simpl nomatch.
+
+ In this case, :g:`(minus (S (S x)) (S y))` is simplified to :g:`(minus (S x) y)`
+ even if an extra simplification is possible.
+
+ In detail: the tactic :tacn:`simpl` first applies :math:`\beta`:math:`\iota`-reduction. Then, it
+ expands transparent constants and tries to reduce further using :math:`\beta`:math:`\iota`-reduction.
+ But, when no :math:`\iota` rule is applied after unfolding then
+ :math:`\delta`-reductions are not applied. For instance trying to use :tacn:`simpl` on
+ :g:`(plus n O) = n` changes nothing.
+
+
+.. _bidirectionality_hints:
+
+Bidirectionality hints
+~~~~~~~~~~~~~~~~~~~~~~
+
+When type-checking an application, Coq normally does not use information from
+the context to infer the types of the arguments. It only checks after the fact
+that the type inferred for the application is coherent with the expected type.
+Bidirectionality hints make it possible to specify that after type-checking the
+first arguments of an application, typing information should be propagated from
+the context to help inferring the types of the remaining arguments.
+
+.. todo the following text is a start on better wording but not quite complete.
+ See https://github.com/coq/coq/pull/11718#discussion_r410219992
+
+ ..
+ Two common methods to determine the type of a construct are:
+
+ * *type checking*, which is verifying that a construct matches a known type, and
+ * *type inference*, with is inferring the type of a construct by analyzing the construct.
+
+ Methods that combine these approaches are known as *bidirectional typing*.
+ Coq normally uses only the first approach to infer the types of arguments,
+ then later verifies that the inferred type is consistent with the expected type.
+ *Bidirectionality hints* specify to use both methods: after type checking the
+ first arguments of an application (appearing before the `&` in :cmd:`Arguments`),
+ typing information from them is propagated to the remaining arguments to help infer their types.
+
+An :cmd:`Arguments` command containing :n:`@arg_specs__1 & @arg_specs__2`
+provides bidirectionality hints.
+It tells the typechecking algorithm, when type checking
+applications of :n:`@qualid`, to first type check the arguments in
+:n:`@arg_specs__1` and then propagate information from the typing context to
+type check the remaining arguments (in :n:`@arg_specs__2`).
+
+.. example:: Bidirectionality hints
+
+ In a context where a coercion was declared from ``bool`` to ``nat``:
+
+ .. coqtop:: in reset
+
+ Definition b2n (b : bool) := if b then 1 else 0.
+ Coercion b2n : bool >-> nat.
+
+ Coq cannot automatically coerce existential statements over ``bool`` to
+ statements over ``nat``, because the need for inserting a coercion is known
+ only from the expected type of a subterm:
+
+ .. coqtop:: all
+
+ Fail Check (ex_intro _ true _ : exists n : nat, n > 0).
+
+ However, a suitable bidirectionality hint makes the example work:
+
+ .. coqtop:: all
+
+ Arguments ex_intro _ _ & _ _.
+ Check (ex_intro _ true _ : exists n : nat, n > 0).
+
+Coq will attempt to produce a term which uses the arguments you
+provided, but in some cases involving Program mode the arguments after
+the bidirectionality starts may be replaced by convertible but
+syntactically different terms.
diff --git a/doc/sphinx/language/extensions/implicit-arguments.rst b/doc/sphinx/language/extensions/implicit-arguments.rst
index fb762a00f1..73b1b65097 100644
--- a/doc/sphinx/language/extensions/implicit-arguments.rst
+++ b/doc/sphinx/language/extensions/implicit-arguments.rst
@@ -105,28 +105,26 @@ This corresponds to a class of non-dependent implicit arguments that
are solved based on the structure of their type only.
-Maximal or non maximal insertion of implicit arguments
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Maximal and non-maximal insertion of implicit arguments
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-In case a function is partially applied, and the next argument to be
-applied is an implicit argument, two disciplines are applicable. In
-the first case, the function is considered to have no arguments
-furtherly: one says that the implicit argument is not maximally
-inserted. In the second case, the function is considered to be
-implicitly applied to the implicit arguments it is waiting for: one
-says that the implicit argument is maximally inserted.
+When a function is partially applied and the next argument to
+apply is an implicit argument, the application can be interpreted in two ways.
+If the next argument is declared as *maximally inserted*, the partial
+application will include that argument. Otherwise, the argument is
+*non-maximally inserted* and the partial application will not include that argument.
Each implicit argument can be declared to be inserted maximally or non
-maximally. In Coq, maximally-inserted implicit arguments are written between curly braces
-"{ }" and non-maximally-inserted implicit arguments are written in square brackets "[ ]".
+maximally. In Coq, maximally inserted implicit arguments are written between curly braces
+"{ }" and non-maximally inserted implicit arguments are written in square brackets "[ ]".
.. seealso:: :flag:`Maximal Implicit Insertion`
Trailing Implicit Arguments
+++++++++++++++++++++++++++
-An implicit argument is considered trailing when all following arguments are declared
-implicit. Trailing implicit arguments cannot be declared non maximally inserted,
+An implicit argument is considered *trailing* when all following arguments are
+implicit. Trailing implicit arguments must be declared as maximally inserted;
otherwise they would never be inserted.
.. exn:: Argument @name is a trailing implicit, so it can't be declared non maximal. Please use %{ %} instead of [ ].
@@ -141,10 +139,9 @@ otherwise they would never be inserted.
Casual use of implicit arguments
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-In a given expression, if it is clear that some argument of a function
-can be inferred from the type of the other arguments, the user can
-force the given argument to be guessed by replacing it by “_”. If
-possible, the correct argument will be automatically generated.
+If an argument of a function application can be inferred from the type
+of the other arguments, the user can force inference of the argument
+by replacing it with `_`.
.. exn:: Cannot infer a term for this placeholder.
:name: Cannot infer a term for this placeholder. (Casual use of implicit arguments)
@@ -156,12 +153,8 @@ possible, the correct argument will be automatically generated.
Declaration of implicit arguments
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-In case one wants that some arguments of a given object (constant,
-inductive types, constructors, assumptions, local or not) are always
-inferred by |Coq|, one may declare once and for all which are the
-expected implicit arguments of this object. There are two ways to do
-this, *a priori* and *a posteriori*.
-
+Implicit arguments can be declared when a function is declared or
+afterwards, using the :cmd:`Arguments` command.
Implicit Argument Binders
+++++++++++++++++++++++++
@@ -172,18 +165,20 @@ Implicit Argument Binders
implicit_binders ::= %{ {+ @name } {? : @type } %}
| [ {+ @name } {? : @type } ]
-In the first setting, one wants to explicitly give the implicit
-arguments of a declared object as part of its definition. To do this,
-one has to surround the bindings of implicit arguments by curly
-braces or square braces:
+In the context of a function definition, these forms specify that
+:token:`name` is an implicit argument. The first form, with curly
+braces, makes :token:`name` a maximally inserted implicit argument. The second
+form, with square brackets, makes :token:`name` a non-maximally inserted implicit argument.
+
+For example:
.. coqtop:: all
Definition id {A : Type} (x : A) : A := x.
-This automatically declares the argument A of id as a maximally
-inserted implicit argument. One can then do as-if the argument was
-absent in every situation but still be able to specify it if needed:
+declares the argument `A` of `id` as a maximally
+inserted implicit argument. `A` may be omitted
+in applications of `id` but may be specified if needed:
.. coqtop:: all
@@ -191,7 +186,7 @@ absent in every situation but still be able to specify it if needed:
Goal forall A, compose id id = id (A:=A).
-For non maximally inserted implicit arguments, use square brackets:
+For non-maximally inserted implicit arguments, use square brackets:
.. coqtop:: all
@@ -203,8 +198,7 @@ For non maximally inserted implicit arguments, use square brackets:
Print Implicit map.
-The syntax is supported in all top-level definitions:
-:cmd:`Definition`, :cmd:`Fixpoint`, :cmd:`Lemma` and so on. For (co-)inductive datatype
+For (co-)inductive datatype
declarations, the semantics are the following: an inductive parameter
declared as an implicit argument need not be repeated in the inductive
definition and will become implicit for the inductive type and the constructors.
@@ -225,11 +219,12 @@ The syntax is also supported in internal binders. For instance, in the
following kinds of expressions, the type of each declaration present
in :token:`binders` can be bracketed to mark the declaration as
implicit:
-:n:`fun (@ident:forall {* @binder }, @type) => @term`,
-:n:`forall (@ident:forall {* @binder }, @type), @type`,
-:n:`let @ident {* @binder } := @term in @term`,
-:n:`fix @ident {* @binder } := @term in @term` and
-:n:`cofix @ident {* @binder } := @term in @term`.
+* :n:`fun (@ident:forall {* @binder }, @type) => @term`,
+* :n:`forall (@ident:forall {* @binder }, @type), @type`,
+* :n:`let @ident {* @binder } := @term in @term`,
+* :n:`fix @ident {* @binder } := @term in @term` and
+* :n:`cofix @ident {* @binder } := @term in @term`.
+
Here is an example:
.. coqtop:: all
@@ -259,190 +254,6 @@ Here is an example:
Check let g {x:nat} (H:x=x) {x} (H:x=x) := x in 0.
-
-Declaring Implicit Arguments
-++++++++++++++++++++++++++++
-
-
-
-.. cmd:: Arguments @smart_qualid {* @argument_spec_block } {* , {* @more_implicits_block } } {? : {+, @arguments_modifier } }
- :name: Arguments
-
- .. insertprodn smart_qualid arguments_modifier
-
- .. prodn::
- smart_qualid ::= @qualid
- | @by_notation
- by_notation ::= @string {? % @ident }
- argument_spec_block ::= @argument_spec
- | /
- | &
- | ( {+ @argument_spec } ) {? % @ident }
- | [ {+ @argument_spec } ] {? % @ident }
- | %{ {+ @argument_spec } %} {? % @ident }
- argument_spec ::= {? ! } @name {? % @ident }
- more_implicits_block ::= @name
- | [ {+ @name } ]
- | %{ {+ @name } %}
- arguments_modifier ::= simpl nomatch
- | simpl never
- | default implicits
- | clear bidirectionality hint
- | clear implicits
- | clear scopes
- | clear scopes and implicits
- | clear implicits and scopes
- | rename
- | assert
- | extra scopes
-
- This command sets implicit arguments *a posteriori*,
- where the list of :n:`@name`\s is a prefix of the list of
- arguments of :n:`@smart_qualid`. Arguments in square
- brackets are declared as implicit and arguments in curly brackets are declared as
- maximally inserted.
-
- After the command is issued, implicit arguments can and must be
- omitted in any expression that applies :token:`qualid`.
-
- This command supports the :attr:`local` and :attr:`global` attributes.
- Default behavior is to limit the effect to the current section but also to
- extend their effect outside the current module or library file.
- Applying :attr:`local` limits the effect of the command to the current module if
- it's not in a section. Applying :attr:`global` within a section extends the
- effect outside the current sections and current module if the command occurs.
-
- A command containing :n:`@argument_spec_block & @argument_spec_block`
- provides :ref:`bidirectionality_hints`.
-
- Use the :n:`@more_implicits_block` to specify multiple implicit arguments declarations
- for names of constants, inductive types, constructors and lemmas that can only be
- applied to a fixed number of arguments (excluding, for instance,
- constants whose type is polymorphic).
- The longest applicable list of implicit arguments will be used to select which
- implicit arguments are inserted.
- For printing, the omitted arguments are the ones of the longest list of implicit
- arguments of the sequence. See the example :ref:`here<example_more_implicits>`.
-
- The :n:`@arguments_modifier` values have various effects:
-
- * :n:`clear implicits` - clears implicit arguments
- * :n:`default implicits` - automatically determine the implicit arguments of the object.
- See :ref:`auto_decl_implicit_args`.
- * :n:`rename` - rename implicit arguments for the object
- * :n:`assert` - assert that the object has the expected number of arguments with the
- expected names. See the example here: :ref:`renaming_implicit_arguments`.
-
-.. exn:: The / modifier may only occur once.
- :undocumented:
-
-.. exn:: The & modifier may only occur once.
- :undocumented:
-
-.. example::
-
- .. coqtop:: reset all
-
- Inductive list (A : Type) : Type :=
- | nil : list A
- | cons : A -> list A -> list A.
-
- Check (cons nat 3 (nil nat)).
-
- Arguments cons [A] _ _.
-
- Arguments nil {A}.
-
- Check (cons 3 nil).
-
- Fixpoint map (A B : Type) (f : A -> B) (l : list A) : list B :=
- match l with nil => nil | cons a t => cons (f a) (map A B f t) end.
-
- Fixpoint length (A : Type) (l : list A) : nat :=
- match l with nil => 0 | cons _ m => S (length A m) end.
-
- Arguments map [A B] f l.
-
- Arguments length {A} l. (* A has to be maximally inserted *)
-
- Check (fun l:list (list nat) => map length l).
-
-.. _example_more_implicits:
-
-.. example:: Multiple implicit arguments with :n:`@more_implicits_block`
-
- .. coqtop:: all
-
- Arguments map [A B] f l, [A] B f l, A B f l.
-
- Check (fun l => map length l = map (list nat) nat length l).
-
-.. note::
- Use the :cmd:`Print Implicit` command to see the implicit arguments
- of an object (see :ref:`displaying-implicit-args`).
-
-.. _auto_decl_implicit_args:
-
-Automatic declaration of implicit arguments
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- The :n:`default implicits @arguments_modifier` clause tells |Coq| to automatically determine the
- implicit arguments of the object.
-
- Auto-detection is governed by flags specifying whether strict,
- contextual, or reversible-pattern implicit arguments must be
- considered or not (see :ref:`controlling-strict-implicit-args`, :ref:`controlling-contextual-implicit-args`,
- :ref:`controlling-rev-pattern-implicit-args` and also :ref:`controlling-insertion-implicit-args`).
-
-.. example:: Default implicits
-
- .. coqtop:: reset all
-
- Inductive list (A:Set) : Set :=
- | nil : list A
- | cons : A -> list A -> list A.
-
- Arguments cons : default implicits.
-
- Print Implicit cons.
-
- Arguments nil : default implicits.
-
- Print Implicit nil.
-
- Set Contextual Implicit.
-
- Arguments nil : default implicits.
-
- Print Implicit nil.
-
-The computation of implicit arguments takes account of the unfolding
-of constants. For instance, the variable ``p`` below has type
-``(Transitivity R)`` which is reducible to
-``forall x,y:U, R x y -> forall z:U, R y z -> R x z``. As the variables ``x``, ``y`` and ``z``
-appear strictly in the body of the type, they are implicit.
-
-.. coqtop:: all
-
- Parameter X : Type.
-
- Definition Relation := X -> X -> Prop.
-
- Definition Transitivity (R:Relation) := forall x y:X, R x y -> forall z:X, R y z -> R x z.
-
- Parameters (R : Relation) (p : Transitivity R).
-
- Arguments p : default implicits.
-
- Print p.
-
- Print Implicit p.
-
- Parameters (a b c : X) (r1 : R a b) (r2 : R b c).
-
- Check (p r1 r2).
-
-
Mode for automatic declaration of implicit arguments
++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -514,7 +325,7 @@ and the automatic declaration mode in on, the manual implicit arguments are adde
automatically declared ones.
In that case, and when the flag :flag:`Maximal Implicit Insertion` is set to off,
-some trailing implicit arguments can be inferred to be non maximally inserted. In
+some trailing implicit arguments can be inferred to be non-maximally inserted. In
this case, they are converted to maximally inserted ones.
.. example::
@@ -540,34 +351,23 @@ application. Use the :n:`(@ident := @term)` form of :token:`arg` to do so,
where :token:`ident` is the name of the implicit argument and :token:`term`
is its corresponding explicit term. Alternatively, one can deactivate
the hiding of implicit arguments for a single function application using the
-:n:`@ @qualid {? @univ_annot } {* @term1 }` form of :token:`term10`.
+:n:`@@qualid_annotated {+ @term1 }` form of :token:`term_application`.
.. example:: Syntax for explicitly giving implicit arguments (continued)
.. coqtop:: all
+ Parameter X : Type.
+ Definition Relation := X -> X -> Prop.
+ Definition Transitivity (R:Relation) := forall x y:X, R x y -> forall z:X, R y z -> R x z.
+ Parameters (R : Relation) (p : Transitivity R).
+ Arguments p : default implicits.
+ Print Implicit p.
+ Parameters (a b c : X) (r1 : R a b) (r2 : R b c).
Check (p r1 (z:=c)).
Check (p (x:=a) (y:=b) r1 (z:=c) r2).
-
-.. _renaming_implicit_arguments:
-
-Renaming implicit arguments
-~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-.. example:: (continued) Renaming implicit arguments
-
- .. coqtop:: all
-
- Arguments p [s t] _ [u] _: rename.
-
- Check (p r1 (u:=c)).
-
- Check (p (s:=a) (t:=b) r1 (u:=c) r2).
-
- Fail Arguments p [s t] _ [w] _ : assert.
-
.. _displaying-implicit-args:
Displaying implicit arguments
@@ -620,6 +420,30 @@ but succeeds in
Deactivation of implicit arguments for parsing
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.. insertprodn term_explicit term_explicit
+
+.. prodn::
+ term_explicit ::= @ @qualid_annotated
+
+This syntax can be used to disable implicit arguments for a single
+function.
+
+.. example::
+
+ The function `id` has one implicit argument and one explicit
+ argument.
+
+ .. coqtop:: all reset
+
+ Check (id 0).
+ Definition id' := @id.
+
+ The function `id'` has no implicit argument.
+
+ .. coqtop:: all
+
+ Check (id' nat 0).
+
.. flag:: Parsing Explicit
Turning this flag on (it is off by default) deactivates the use of implicit arguments.
@@ -629,6 +453,19 @@ Deactivation of implicit arguments for parsing
to be given as if no arguments were implicit. By symmetry, this also
affects printing.
+.. example::
+
+ We can reproduce the example above using the :flag:`Parsing
+ Explicit` flag:
+
+ .. coqtop:: all reset
+
+ Set Parsing Explicit.
+ Definition id' := id.
+ Unset Parsing Explicit.
+ Check (id 1).
+ Check (id' nat 1).
+
.. _canonical-structure-declaration:
Canonical structures
@@ -668,7 +505,7 @@ in :ref:`canonicalstructures`; here only a simple example is given.
Here is an example.
- .. coqtop:: all
+ .. coqtop:: all reset
Require Import Relations.
@@ -806,7 +643,7 @@ Implicit generalization
.. index:: `[! ]
.. index:: `(! )
-.. insertprodn generalizing_binder typeclass_constraint
+.. insertprodn generalizing_binder term_generalizing
.. prodn::
generalizing_binder ::= `( {+, @typeclass_constraint } )
@@ -815,7 +652,8 @@ Implicit generalization
typeclass_constraint ::= {? ! } @term
| %{ @name %} : {? ! } @term
| @name : {? ! } @term
-
+ term_generalizing ::= `%{ @term %}
+ | `( @term )
Implicit generalization is an automatic elaboration of a statement
with free variables into a closed statement where these variables are
@@ -827,7 +665,7 @@ surrounding it with \`{ }, or \`[ ] or \`( ).
Terms surrounded by \`{ } introduce their free variables as maximally
inserted implicit arguments, terms surrounded by \`[ ] introduce them as
-non maximally inserted implicit arguments and terms surrounded by \`( )
+non-maximally inserted implicit arguments and terms surrounded by \`( )
introduce them as explicit arguments.
Generalizing binders always introduce their free variables as
diff --git a/doc/sphinx/language/extensions/index.rst b/doc/sphinx/language/extensions/index.rst
index 627e7f0acb..fc2ce03093 100644
--- a/doc/sphinx/language/extensions/index.rst
+++ b/doc/sphinx/language/extensions/index.rst
@@ -20,6 +20,7 @@ language presented in the :ref:`previous chapter <core-language>`.
implicit-arguments
../../addendum/extended-pattern-matching
../../user-extensions/syntax-extensions
+ arguments-command
../../addendum/implicit-coercions
../../addendum/type-classes
../../addendum/canonical-structures
diff --git a/doc/sphinx/language/gallina-extensions.rst b/doc/sphinx/language/gallina-extensions.rst
index a859aa46eb..5b78280edc 100644
--- a/doc/sphinx/language/gallina-extensions.rst
+++ b/doc/sphinx/language/gallina-extensions.rst
@@ -30,6 +30,11 @@ under its expanded form (see :flag:`Printing Matching`).
Pattern-matching on boolean values: the if expression
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.. insertprodn term_if term_if
+
+.. prodn::
+ term_if ::= if @term {? {? as @name } return @term100 } then @term else @term
+
For inductive types with exactly two constructors and for pattern matching
expressions that do not depend on the arguments of the constructors, it is possible
to use a ``if … then … else`` notation. For instance, the definition
@@ -238,7 +243,7 @@ written using the first destructuring let syntax.
Note that this only applies to pattern matching instances entered with :g:`match`.
It doesn't affect pattern matching explicitly entered with a destructuring
:g:`let`.
- Use the :cmd:`Add @table` and :cmd:`Remove @table` commands to update this set.
+ Use the :cmd:`Add` and :cmd:`Remove` commands to update this set.
Printing matching on booleans
@@ -252,7 +257,7 @@ which types are written this way:
:name: Printing If
Specifies a set of qualids for which pattern matching is displayed using
- ``if`` … ``then`` … ``else`` …. Use the :cmd:`Add @table` and :cmd:`Remove @table`
+ ``if`` … ``then`` … ``else`` …. Use the :cmd:`Add` and :cmd:`Remove`
commands to update this set.
This example emphasizes what the printing settings offer.
@@ -316,11 +321,11 @@ together, as well as a means of massive abstraction.
parameters given by the :n:`@module_binder`\s. (A *functor* is a function
from modules to modules.)
- .. todo: would like to find a better term than "interactive", not very descriptive
-
:n:`@of_module_type` specifies the module type. :n:`{+ <: @module_type_inl }`
starts a module that satisfies each :n:`@module_type_inl`.
+ .. todo: would like to find a better term than "interactive", not very descriptive
+
:n:`:= {+<+ @module_expr_inl }` specifies the body of a module or functor
definition. If it's not specified, then the module is defined *interactively*,
meaning that the module is defined as a series of commands terminated with :cmd:`End`
@@ -422,7 +427,12 @@ are now available through the dot notation.
If :n:`@module_binder`\s are specified, declares a functor with parameters given by the list of
:token:`module_binder`\s.
-.. cmd:: Import {+ @qualid }
+.. cmd:: Import {+ @filtered_import }
+
+ .. insertprodn filtered_import filtered_import
+
+ .. prodn::
+ filtered_import ::= @qualid {? ( {+, @qualid {? ( .. ) } } ) }
If :token:`qualid` denotes a valid basic module (i.e. its module type is a
signature), makes its components available by their short names.
@@ -465,12 +475,50 @@ are now available through the dot notation.
Check B.T.
-.. cmd:: Export {+ @qualid }
+ Appending a module name with a parenthesized list of names will
+ make only those names available with short names, not other names
+ defined in the module nor will it activate other features.
+
+ The names to import may be constants, inductive types and
+ constructors, and notation aliases (for instance, Ltac definitions
+ cannot be selectively imported). If they are from an inner module
+ to the one being imported, they must be prefixed by the inner path.
+
+ The name of an inductive type may also be followed by ``(..)`` to
+ import it, its constructors and its eliminators if they exist. For
+ this purpose "eliminator" means a constant in the same module whose
+ name is the inductive type's name suffixed by one of ``_sind``,
+ ``_ind``, ``_rec`` or ``_rect``.
+
+ .. example::
+
+ .. coqtop:: reset in
+
+ Module A.
+ Module B.
+ Inductive T := C.
+ Definition U := nat.
+ End B.
+ Definition Z := Prop.
+ End A.
+ Import A(B.T(..), Z).
+
+ .. coqtop:: all
+
+ Check B.T.
+ Check B.C.
+ Check Z.
+ Fail Check B.U.
+ Check A.B.U.
+
+.. cmd:: Export {+ @filtered_import }
:name: Export
Similar to :cmd:`Import`, except that when the module containing this command
is imported, the :n:`{+ @qualid }` are imported as well.
+ The selective import syntax also works with Export.
+
.. exn:: @qualid is not a module.
:undocumented:
@@ -563,12 +611,9 @@ module can be accessed using the dot notation:
Parameter x : T.
End SIG.
-The following definition of :g:`N` using the module type expression :g:`SIG` with
+The definition of :g:`N` using the module type expression :g:`SIG` with
:g:`Definition T := nat` is equivalent to the following one:
-.. todo: what is other definition referred to above?
- "Module N' : SIG with Definition T := nat. End N`." is not it.
-
.. coqtop:: in
Module Type SIG'.
@@ -719,7 +764,7 @@ accessible, absolute names can never be hidden.
Locate nat.
-.. seealso:: Commands :cmd:`Locate` and :cmd:`Locate Library`.
+.. seealso:: Commands :cmd:`Locate`.
.. _libraries-and-filesystem:
@@ -812,7 +857,7 @@ Printing constructions in full
.. flag:: Printing All
Coercions, implicit arguments, the type of pattern matching, but also
- notations (see :ref:`syntaxextensionsandinterpretationscopes`) can obfuscate the behavior of some
+ notations (see :ref:`syntax-extensions-and-notation-scopes`) can obfuscate the behavior of some
tactics (typically the tactics applying to occurrences of subterms are
sensitive to the implicit arguments). Turning this flag on
deactivates all high-level printing features such as coercions,
@@ -823,6 +868,16 @@ Printing constructions in full
:flag:`Printing Projections`, and :flag:`Printing Notations`. To reactivate
the high-level printing features, use the command ``Unset Printing All``.
+ .. note:: In some cases, setting :flag:`Printing All` may display terms
+ that are so big they become very hard to read. One technique to work around
+ this is use :cmd:`Undelimit Scope` and/or :cmd:`Close Scope` to turn off the
+ printing of notations bound to particular scope(s). This can be useful when
+ notations in a given scope are getting in the way of understanding
+ a goal, but turning off all notations with :flag:`Printing All` would make
+ the goal unreadable.
+
+ .. see a contrived example here: https://github.com/coq/coq/pull/11718#discussion_r415481854
+
.. _printing-universes:
Printing universes
@@ -863,7 +918,8 @@ Existential variables
.. insertprodn term_evar term_evar
.. prodn::
- term_evar ::= ?[ @ident ]
+ term_evar ::= _
+ | ?[ @ident ]
| ?[ ?@ident ]
| ?@ident {? @%{ {+; @ident := @term } %} }
@@ -1056,51 +1112,3 @@ Literal values (of type :g:`Float64.t`) are extracted to literal OCaml
values (of type :g:`float`) written in hexadecimal notation and
wrapped into the :g:`Float64.of_float` constructor, e.g.:
:g:`Float64.of_float (0x1p+0)`.
-
-.. _bidirectionality_hints:
-
-Bidirectionality hints
-----------------------
-
-When type-checking an application, Coq normally does not use information from
-the context to infer the types of the arguments. It only checks after the fact
-that the type inferred for the application is coherent with the expected type.
-Bidirectionality hints make it possible to specify that after type-checking the
-first arguments of an application, typing information should be propagated from
-the context to help inferring the types of the remaining arguments.
-
-An :cmd:`Arguments` command containing :n:`@argument_spec_block__1 & @argument_spec_block__2`
-provides :ref:`bidirectionality_hints`.
-It tells the typechecking algorithm, when type-checking
-applications of :n:`@qualid`, to first type-check the arguments in
-:n:`@argument_spec_block__1` and then propagate information from the typing context to
-type-check the remaining arguments (in :n:`@argument_spec_block__2`).
-
-.. example:: Bidirectionality hints
-
- In a context where a coercion was declared from ``bool`` to ``nat``:
-
- .. coqtop:: in reset
-
- Definition b2n (b : bool) := if b then 1 else 0.
- Coercion b2n : bool >-> nat.
-
- Coq cannot automatically coerce existential statements over ``bool`` to
- statements over ``nat``, because the need for inserting a coercion is known
- only from the expected type of a subterm:
-
- .. coqtop:: all
-
- Fail Check (ex_intro _ true _ : exists n : nat, n > 0).
-
- However, a suitable bidirectionality hint makes the example work:
-
- .. coqtop:: all
-
- Arguments ex_intro _ _ & _ _.
- Check (ex_intro _ true _ : exists n : nat, n > 0).
-
-Coq will attempt to produce a term which uses the arguments you
-provided, but in some cases involving Program mode the arguments after
-the bidirectionality starts may be replaced by convertible but
-syntactically different terms.
diff --git a/doc/sphinx/language/gallina-specification-language.rst b/doc/sphinx/language/gallina-specification-language.rst
index f4592f8f37..353bed1b3d 100644
--- a/doc/sphinx/language/gallina-specification-language.rst
+++ b/doc/sphinx/language/gallina-specification-language.rst
@@ -7,197 +7,13 @@
This chapter describes Gallina, the specification language of Coq. It allows
developing mathematical theories and to prove specifications of programs. The
theories are built from axioms, hypotheses, parameters, lemmas, theorems and
-definitions of constants, functions, predicates and sets. The syntax of logical
-objects involved in theories is described in Section :ref:`term`. The
-language of commands, called *The Vernacular* is described in Section
-:ref:`vernacular`.
-
-In Coq, logical objects are typed to ensure their logical correctness. The
-rules implemented by the typing algorithm are described in Chapter :ref:`calculusofinductiveconstructions`.
-
-
-.. About the grammars in the manual
- ================================
-
- Grammars are presented in Backus-Naur form (BNF). Terminal symbols are
- set in black ``typewriter font``. In addition, there are special notations for
- regular expressions.
-
- An expression enclosed in square brackets ``[…]`` means at most one
- occurrence of this expression (this corresponds to an optional
- component).
-
- The notation “``entry sep … sep entry``” stands for a non empty sequence
- of expressions parsed by entry and separated by the literal “``sep``” [1]_.
-
- Similarly, the notation “``entry … entry``” stands for a non empty
- sequence of expressions parsed by the “``entry``” entry, without any
- separator between.
-
- At the end, the notation “``[entry sep … sep entry]``” stands for a
- possibly empty sequence of expressions parsed by the “``entry``” entry,
- separated by the literal “``sep``”.
-
-.. _lexical-conventions:
-
-Lexical conventions
-===================
-
-Blanks
- Space, newline and horizontal tab are considered blanks.
- Blanks are ignored but they separate tokens.
-
-Comments
- Comments are enclosed between ``(*`` and ``*)``. They can be nested.
- They can contain any character. However, embedded :n:`@string` literals must be
- correctly closed. Comments are treated as blanks.
-
-Identifiers
- Identifiers, written :n:`@ident`, are sequences of letters, digits, ``_`` and
- ``'``, that do not start with a digit or ``'``. That is, they are
- recognized by the following grammar (except that the string ``_`` is reserved;
- it is not a valid identifier):
-
- .. insertprodn ident subsequent_letter
-
- .. prodn::
- ident ::= @first_letter {* @subsequent_letter }
- first_letter ::= {| a .. z | A .. Z | _ | @unicode_letter }
- subsequent_letter ::= {| @first_letter | @digit | ' | @unicode_id_part }
-
- All characters are meaningful. In particular, identifiers are case-sensitive.
- :production:`unicode_letter` non-exhaustively includes Latin,
- Greek, Gothic, Cyrillic, Arabic, Hebrew, Georgian, Hangul, Hiragana
- and Katakana characters, CJK ideographs, mathematical letter-like
- symbols and non-breaking space. :production:`unicode_id_part`
- non-exhaustively includes symbols for prime letters and subscripts.
-
-Numerals
- Numerals are sequences of digits with an optional fractional part
- and exponent, optionally preceded by a minus sign. :n:`@int` is an integer;
- a numeral without fractional or exponent parts. :n:`@num` is a non-negative
- integer. Underscores embedded in the digits are ignored, for example
- ``1_000_000`` is the same as ``1000000``.
-
- .. insertprodn numeral digit
-
- .. prodn::
- numeral ::= {+ @digit } {? . {+ @digit } } {? {| e | E } {? {| + | - } } {+ @digit } }
- int ::= {? - } {+ @digit }
- num ::= {+ @digit }
- digit ::= 0 .. 9
-
-Strings
- Strings begin and end with ``"`` (double quote). Use ``""`` to represent
- a double quote character within a string. In the grammar, strings are
- identified with :production:`string`.
-
-Keywords
- The following character sequences are reserved keywords that cannot be
- used as identifiers::
-
- _ Axiom CoFixpoint Definition Fixpoint Hypothesis IF Parameter Prop
- SProp Set Theorem Type Variable as at by cofix discriminated else
- end exists exists2 fix for forall fun if in lazymatch let match
- multimatch return then using where with
-
- Note that plugins may define additional keywords when they are loaded.
-
-Other tokens
- The set of
- tokens defined at any given time can vary because the :cmd:`Notation`
- command can define new tokens. A :cmd:`Require` command may load more notation definitions,
- while the end of a :cmd:`Section` may remove notations. Some notations
- are defined in the basic library (see :ref:`thecoqlibrary`) and are normally
- loaded automatically at startup time.
-
- Here are the character sequences that Coq directly defines as tokens
- without using :cmd:`Notation` (omitting 25 specialized tokens that begin with
- ``#int63_``)::
-
- ! #[ % & ' ( () (bfs) (dfs) ) * ** + , - ->
- . .( .. ... / : ::= := :> :>> ; < <+ <- <:
- <<: <= = => > >-> >= ? @ @{ [ [= ] _
- `( `{ { {| | |- || }
-
- When multiple tokens match the beginning of a sequence of characters,
- the longest matching token is used.
- Occasionally you may need to insert spaces to separate tokens. For example,
- if ``~`` and ``~~`` are both defined as tokens, the inputs ``~ ~`` and
- ``~~`` generate different tokens, whereas if `~~` is not defined, then the
- two inputs are equivalent.
+definitions of constants, functions, predicates and sets.
.. _term:
Terms
=====
-Syntax of terms
----------------
-
-The following grammars describe the basic syntax of the terms of the
-*Calculus of Inductive Constructions* (also called Cic). The formal
-presentation of Cic is given in Chapter :ref:`calculusofinductiveconstructions`. Extensions of this syntax
-are given in Chapter :ref:`extensionsofgallina`. How to customize the syntax
-is described in Chapter :ref:`syntaxextensionsandinterpretationscopes`.
-
-.. insertprodn term field_def
-
-.. prodn::
- term ::= forall @open_binders , @term
- | fun @open_binders => @term
- | @term_let
- | if @term {? {? as @name } return @term100 } then @term else @term
- | @term_fix
- | @term_cofix
- | @term100
- term100 ::= @term_cast
- | @term10
- term10 ::= @term1 {+ @arg }
- | @ @qualid {? @univ_annot } {* @term1 }
- | @term1
- arg ::= ( @ident := @term )
- | @term1
- one_term ::= @term1
- | @ @qualid {? @univ_annot }
- term1 ::= @term_projection
- | @term0 % @ident
- | @term0
- term0 ::= @qualid {? @univ_annot }
- | @sort
- | @numeral
- | @string
- | _
- | @term_evar
- | @term_match
- | ( @term )
- | %{%| {* @field_def } %|%}
- | `%{ @term %}
- | `( @term )
- | ltac : ( @ltac_expr )
- field_def ::= @qualid {* @binder } := @term
-
-.. note::
-
- Many commands and tactics use :n:`@one_term` rather than :n:`@term`.
- The former need to be enclosed in parentheses unless they're very
- simple, such as a single identifier. This avoids confusing a space-separated
- list of terms with a :n:`@term1` applied to a list of arguments.
-
-.. _types:
-
-Types
------
-
-.. prodn::
- type ::= @term
-
-:n:`@type`\s are a subset of :n:`@term`\s; not every :n:`@term` is a :n:`@type`.
-Every term has an associated type, which
-can be determined by applying the :ref:`typing-rules`. Distinct terms
-may share the same type, for example 0 and 1 are both of type `nat`, the
-natural numbers.
-
.. _gallina-identifiers:
Qualified identifiers and simple identifiers
@@ -223,9 +39,15 @@ Field identifiers, written :n:`@field_ident`, are identifiers prefixed by
Numerals and strings
--------------------
+.. insertprodn primitive_notations primitive_notations
+
+.. prodn::
+ primitive_notations ::= @numeral
+ | @string
+
Numerals and strings have no predefined semantics in the calculus. They are
merely notations that can be bound to objects through the notation mechanism
-(see Chapter :ref:`syntaxextensionsandinterpretationscopes` for details).
+(see Chapter :ref:`syntax-extensions-and-notation-scopes` for details).
Initially, numerals are bound to Peano’s representation of natural
numbers (see :ref:`datatypes`).
@@ -352,6 +174,12 @@ Section :ref:`let-in`).
Products: forall
----------------
+.. insertprodn term_forall_or_fun term_forall_or_fun
+
+.. prodn::
+ term_forall_or_fun ::= forall @open_binders , @term
+ | fun @open_binders => @term
+
The expression :n:`forall @ident : @type, @term` denotes the
*product* of the variable :n:`@ident` of type :n:`@type`, over the term :n:`@term`.
As for abstractions, :g:`forall` is followed by a binder list, and products
@@ -373,12 +201,18 @@ the propositional implication and function types.
Applications
------------
-The expression :n:`@term__fun @term` denotes the application of
-:n:`@term__fun` (which is expected to have a function type) to
-:token:`term`.
+.. insertprodn term_application arg
+
+.. prodn::
+ term_application ::= @term1 {+ @arg }
+ | @ @qualid_annotated {+ @term1 }
+ arg ::= ( @ident := @term )
+ | @term1
+
+:n:`@term__fun @term` denotes applying the function :n:`@term__fun` to :token:`term`.
-The expression :n:`@term__fun {+ @term__i }` denotes the application
-of the term :n:`@term__fun` to the arguments :n:`@term__i`. It is
+:n:`@term__fun {+ @term__i }` denotes applying
+:n:`@term__fun` to the arguments :n:`@term__i`. It is
equivalent to :n:`( … ( @term__fun @term__1 ) … ) @term__n`:
associativity is to the left.
@@ -458,7 +292,7 @@ Definition by cases: match
pattern10 ::= @pattern1 as @name
| @pattern1 {* @pattern1 }
| @ @qualid {* @pattern1 }
- pattern1 ::= @pattern0 % @ident
+ pattern1 ::= @pattern0 % @scope_key
| @pattern0
pattern0 ::= @qualid
| %{%| {* @qualid := @pattern } %|%}
@@ -636,29 +470,6 @@ co-recursion. It is the local counterpart of the :cmd:`CoFixpoint` command. When
The Vernacular
==============
-.. insertprodn vernacular vernacular
-
-.. prodn::
- vernacular ::= {* {? @all_attrs } {| @command | @ltac_expr } . }
-
-The top-level input to |Coq| is a series of :production:`command`\s and :production:`tactic`\s,
-each terminated with a period
-and optionally decorated with :ref:`gallina-attributes`. :n:`@ltac_expr` syntax supports both simple
-and compound tactics. For example: ``split`` is a simple tactic while ``split; auto`` combines two
-simple tactics.
-
-Tactics specify how to transform the current proof state as a step in creating a proof. They
-are syntactically valid only when |Coq| is in proof mode, such as after a :cmd:`Theorem` command
-and before any subsequent proof-terminating command such as :cmd:`Qed`. See :ref:`proofhandling` for more
-on proof mode.
-
-By convention, command names begin with uppercase letters, while
-tactic names begin with lowercase letters. Commands appear in the
-HTML documentation in blue boxes after the label "Command". In the pdf, they appear
-after the boldface label "Command:". Commands are listed in the :ref:`command_index`.
-
-Similarly, tactics appear after the label "Tactic". Tactics are listed in the :ref:`tactic_index`.
-
.. _gallina-assumptions:
Assumptions
@@ -694,7 +505,7 @@ has type :n:`@type`.
of an object of this type) is accepted as a postulate.
:cmd:`Axiom`, :cmd:`Conjecture`, :cmd:`Parameter` and their plural forms
- are equivalent. They can take the :attr:`local` attribute (see :ref:`gallina-attributes`),
+ are equivalent. They can take the :attr:`local` :term:`attribute`,
which makes the defined :n:`@ident`\s accessible by :cmd:`Import` and its variants
only through their fully qualified names.
@@ -718,7 +529,7 @@ has type :n:`@type`.
:name: @ident already exists. (Axiom)
:undocumented:
-.. warn:: @ident is declared as a local axiom [local-declaration,scope]
+.. warn:: @ident is declared as a local axiom
Warning generated when using :cmd:`Variable` or its equivalent
instead of :n:`Local Parameter` or its equivalent.
@@ -761,7 +572,7 @@ Section :ref:`typing-rules`.
| {* @binder } : @type
These commands bind :n:`@term` to the name :n:`@ident` in the environment,
- provided that :n:`@term` is well-typed. They can take the :attr:`local` attribute (see :ref:`gallina-attributes`),
+ provided that :n:`@term` is well-typed. They can take the :attr:`local` :term:`attribute`,
which makes the defined :n:`@ident` accessible by :cmd:`Import` and its variants
only through their fully qualified names.
If :n:`@reduce` is present then :n:`@ident` is bound to the result of the specified
@@ -1243,7 +1054,7 @@ The ability to define co-inductive types by constructors, hereafter called
a bit long: this is due to dependent pattern-matching which implies
propositional η-equality, which itself would require full η-conversion for
subject reduction to hold, but full η-conversion is not acceptable as it would
-make type-checking undecidable.
+make type checking undecidable.
Since the introduction of primitive records in Coq 8.5, an alternative
presentation is available, called *negative co-inductive types*. This consists
@@ -1636,82 +1447,6 @@ the proof and adds it to the environment.
#. One can also use :cmd:`Admitted` in place of :cmd:`Qed` to turn the
current asserted statement into an axiom and exit the proof editing mode.
-.. _gallina-attributes:
-
-Attributes
------------
-
-.. insertprodn all_attrs legacy_attr
-
-.. prodn::
- all_attrs ::= {* #[ {*, @attr } ] } {* @legacy_attr }
- attr ::= @ident {? @attr_value }
- attr_value ::= = @string
- | ( {*, @attr } )
- legacy_attr ::= {| Local | Global }
- | {| Polymorphic | Monomorphic }
- | {| Cumulative | NonCumulative }
- | Private
- | Program
-
-Attributes modify the behavior of a command or tactic.
-Syntactically, most commands and tactics can be decorated with attributes, but
-attributes not supported by the command or tactic will be flagged as errors.
-
-The order of top-level attributes doesn't affect their meaning. ``#[foo,bar]``, ``#[bar,foo]``,
-``#[foo]#[bar]`` and ``#[bar]#[foo]`` are equivalent.
-
-The legacy attributes (:n:`@legacy_attr`) provide an older, alternate syntax
-for certain attributes. They are equivalent to new attributes as follows:
-
-================ ================================
-Legacy attribute New attribute
-================ ================================
-`Local` :attr:`local`
-`Global` :attr:`global`
-`Polymorphic` :attr:`universes(polymorphic)`
-`Monomorphic` :attr:`universes(monomorphic)`
-`Cumulative` :attr:`universes(cumulative)`
-`NonCumulative` :attr:`universes(noncumulative)`
-`Private` :attr:`private(matching)`
-`Program` :attr:`program`
-================ ================================
-
-.. attr:: deprecated ( {? since = @string , } {? note = @string } )
- :name: deprecated
-
- At least one of :n:`since` or :n:`note` must be present. If both are present,
- either one may appear first and they must be separated by a comma.
-
- This attribute is supported by the following commands: :cmd:`Ltac`,
- :cmd:`Tactic Notation`, :cmd:`Notation`, :cmd:`Infix`.
-
- It can trigger the following warnings:
-
- .. warn:: Tactic @qualid is deprecated since @string__since. @string__note.
- Tactic Notation @qualid is deprecated since @string__since. @string__note.
- Notation @string is deprecated since @string__since. @string__note.
-
- :n:`@qualid` or :n:`@string` is the notation, :n:`@string__since` is the version number,
- :n:`@string__note` is the note (usually explains the replacement).
-
- .. example::
-
- .. coqtop:: all reset warn
-
- #[deprecated(since="8.9.0", note="Use idtac instead.")]
- Ltac foo := idtac.
-
- Goal True.
- Proof.
- now foo.
- Abort.
-
-.. warn:: Unsupported attribute
-
- This warning is an error by default. It is caused by using a
- command with some attribute it does not understand.
-
.. [1]
Except if the inductive type is empty in which case there is no
equation that can be used to infer the return type.