HowToContributeToTheStandardLibrary - coq/coq GitHub Wiki
How to contribute to the Coq standard library
Updates or fixes to existing Coq library are welcome. Please follow the guidelines below as much as possible. Contributions can be submitted to the coqdev mailing list (coqdev at inria dot fr) or to the bug tracker. Please take into consideration that developers are generally researchers working only part time on Coq and that response delays may vary from hours to weeks. If delays exceed months, feel free to contact the developers again.
Contributors should accept to have their contribution licensed with the same licence as Coq standard library, i.e. LGLP 2.0.
Contributions of stand-alone libraries should be done at the Coq user contributions repository.
The Coq library guidelines
Warning: this at the current stage only a proposal, comments are welcome (this is a wiki)
Unfortunately, the Coq library is far from being homogeneously written. Also, the language of Coq itself, especially regarding tactics, often presents some idiosynchrasies that do not help in designing clean libraries. Nevertheless, the following guidelines seem to be generally accepted. Don't hesitate to add examples or remarks on this page (it is a wiki whoever can contribute to!). If the remarks lead to a discussion thread, some synthesis will be done after a while by the administrators.
General guidelines
-
Follow the style of the modified/extended library as much as possible
Coq libraries have been developed by several different persons and it is not always clear what the style of a given library is. In this case, follow what seems to you the most consensual or best style and shortly explain your choice while sending your code
-
For standard mathematical properties (such as commutativity, associativity, ...), follow the recommendations from the file dev/doc/naming-conventions.tex of the distribution for naming lemmas and for canonically ordering the arguments and hypotheses of the lemmas.
-
For properties that do no have standard name, follows the style of the modified library. Typical conventions that several libraries follow (but not all) are:
- Use of glued words with capital initial letters for predicates and module names; use lowercase words separated by underscore for functions (e.g., in library
List
,In
,NoDup
andExists
are predicates, whilelast
andrev
are functions.
- Use of glued words with capital initial letters for predicates and module names; use lowercase words separated by underscore for functions (e.g., in library
-
Start every proof by the keyword
Proof
, end them withQed
orDefined
depending on whether the lemma has to be used in computation or not. AlignProof
,Qed}} and {{{Defined
with the line stating the lemma. Starts the proof after an extra indentation of 2 characters. -
Formatting: Coq's terms and statements should be formatted as the Coq pretty-printer formats them. For instance, cases of an inductive type declaration and of pattern-matching constructs should be aligned vertically unless the whole definition is less than 80 characters long. Also, all symbols, to the exception of delimiters, should be separated from other expressions by spaces. Even though English typography recommends no space before a colon, one has to put one in Coq files. In short, the submitted contribution should look like if it has been formatted by the option
--beautify
ofcoqc
. Contributions to the standard library that do not follow the standard formatting will not be considered.
Tactics guidelines
The following recommendations apply even if the library being extended do not follow them.
- Give a name to all hypotheses that are referred to later on in the script whenever the tactics used permit do to so.
- Do not use deprecated tactics:
elimtype
: most usages of it can be replacedexfalso
legacy ring
: usering
legacy field
: usefield
- Specific tactics
- Case analysis, induction and inversion
- There is an overlapping between what
case
,destruct
,dependent destruction
andinversion
do and all them should eventually merge into a unique tactic. There are several tastes: the in-place style supported bydestruct
and the push-on-goal style supported bycase
. The in-place style recommends to usedestruct
,dependent destruction
,inversion
andcase
, in this preference order (in particularinversion
is not considered to be robust and predictable enough). - There is an overlapping between what
elim
,induction
anddependent induction
do and they should eventually merge into a unique tactic. In the meantime, the in-place style recommends to useinduction
,dependent induction
andelim
in this order. - Indent the different cases of an induction step at the same level. If most of the cases need several lines, separate cases by a blank line and use comments to make explicit which case it is.
- There is an overlapping between what
- Automation
auto
/eauto
: use theusing
clause as much as possible whenever it underlines the use of an important lemma for the proof.- Linear arithmetic: there is an overlapping between what
omega
,romega
andlia
do. In any cases, avoidromega
;lia}} is complete and generally faster but {{{omega
is better able to deal with non primitive symbols (max
,min
, natural numbers, ...).
- The
now
tactical, similar to theby
tactical of the ssreflect language, allows to ensure that the tactic coming next solves the goal up to the use of some simple automation tactic calledeasy
(similar todone
in ssreflect). The exact strenght to give toeasy
is still under discussion. Nevertheless, in long proofs, usingnow
improves the robustness of the script and is thus good practice. double induction
is most often better replaced byinduction ...; destruct ...
- Prefer
revert
togeneralize
. - Chaining: chain successive applications of
apply
,rewrite
as much as possible using the comma.
- Case analysis, induction and inversion
To be continued
Documentation
New lemmas or definitions should be accompanied with a coqdoc-compliant header, even though most of the current library fails to follow this recommendation.
Use of notations and unicode symbols
- For all notations, do as much as possible notations which when printed can be parsed (for instance, avoid
Notation "!" := (f _).
); so that copying/pasting from a result coq buffer to a coq input buffer will be parsable.- For Utf-8 notations, consider putting them in a separate module and providing Ascii notations by default, so that the user who doesn't support displaying Utf-8 characters should simply not open your utf8 module, and the user who can output them but not input them, can use ascii notations for input and utf8 notations for output (and of course the user who fully support utf8 can use it for both input and output). If your module is called,
Foo
, then your UTF-8 module should be calledFooUtf8
and its content should beRequire Export Foo.
followed by a sequence of (utf8) notations.
- For Utf-8 notations, consider putting them in a separate module and providing Ascii notations by default, so that the user who doesn't support displaying Utf-8 characters should simply not open your utf8 module, and the user who can output them but not input them, can use ascii notations for input and utf8 notations for output (and of course the user who fully support utf8 can use it for both input and output). If your module is called,
Section to be expanded