
# Section mechanism¶

Sections create local contexts which can be shared across multiple definitions.

Example

Sections are opened by the Section command, and closed by End.

Section s1.

Inside a section, local parameters can be introduced using Variable, Hypothesis, or Context (there are also plural variants for the first two).

Variables x y : nat.
x is declared y is declared

The command Let introduces section-wide Let-in definitions. These definitions won't persist when the section is closed, and all persistent definitions which depend on y' will be prefixed with let y' := y in.

Let y' := y.
y' is defined
Definition x' := S x.
x' is defined
Definition x'' := x' + y'.
x'' is defined
Print x'.
x' = S x : nat
Print x''.
x'' = x' + y' : nat
End s1.
Print x'.
x' = fun x : nat => S x : nat -> nat Arguments x' _%nat_scope
Print x''.
x'' = fun x y : nat => let y' := y in x' x + y' : nat -> nat -> nat Arguments x'' (_ _)%nat_scope

Notice the difference between the value of x' and x'' inside section s1 and outside.

Command Section ident

This command is used to open a section named ident. Section names do not need to be unique.

Command End ident

This command closes the section or module named ident. See Terminating an interactive module or module type definition for a description of its use with modules.

After closing the section, the local declarations (variables and local definitions, see Variable) are discharged, meaning that they stop being visible and that all global objects defined in the section are generalized with respect to the variables and local definitions they each depended on in the section.

Error There is nothing to end.
Error Last block to end has name ident.

Note

Most commands, like Hint, Notation, option management, … which appear inside a section are canceled when the section is closed.

Command Let ident_decl def_body
Command Let Fixpoint fix_definition with fix_definition*
Command Let CoFixpoint cofix_definition with cofix_definition*

These commands behave like Definition, Fixpoint and CoFixpoint, except that the declared constant is local to the current section. When the section is closed, all persistent definitions and theorems within it that depend on the constant will be wrapped with a term_let with the same declaration.

As for Definition, Fixpoint and CoFixpoint, if term is omitted, type is required and Coq enters proof editing mode. This can be used to define a term incrementally, in particular by relying on the refine tactic. In this case, the proof should be terminated with Defined in order to define a constant for which the computational behavior is relevant. See Entering and leaving proof editing mode.

Command Context binder+

Declare variables in the context of the current section, like Variable, but also allowing implicit variables, Implicit generalization, and let-binders.

Context {A : Type} (a b : A). Context `{EqDec A}. Context (b' := b).