Library Coq.Init.Datatypes
Set Implicit Arguments.
Require Import Notations.
Require Import Logic.
Datatypes with zero and one element
Empty_set is a datatype with no inhabitant
unit is a singleton datatype with sole inhabitant tt
The boolean datatype
bool is the datatype of the boolean values
true and
false
Inductive bool :
Set :=
|
true :
bool
|
false :
bool.
Add Printing If bool.
Delimit Scope bool_scope with bool.
Basic boolean operators
Basic properties of andb
Interpretation of booleans as propositions
Another way of interpreting booleans as propositions
is_true can be activated as a coercion by
(
Local)
Coercion is_true : bool >-> Sortclass.
Additional rewriting lemmas about
eq_true
The BoolSpec inductive will be used to relate a boolean value
and two propositions corresponding respectively to the true
case and the false case.
Interest: BoolSpec behave nicely with case and destruct.
See also Bool.reflect when Q = ~P.
Peano natural numbers
nat is the datatype of natural numbers built from
O and successor
S;
note that the constructor name is the letter O.
Numbers in
nat can be denoted using a decimal notation;
e.g.
3%nat abbreviates
S (S (S O))
Inductive nat :
Set :=
|
O :
nat
|
S :
nat -> nat.
Delimit Scope nat_scope with nat.
option A is the extension of A with an extra element None
sum A B, written A + B, is the disjoint sum of A and B
prod A B, written A * B, is the product of A and B;
the pair pair A B a b of a and b is abbreviated (a,b)
Polymorphic lists and some operations
Inductive list (
A :
Type) :
Type :=
|
nil :
list A
|
cons :
A -> list A -> list A.
Infix "::" :=
cons (
at level 60,
right associativity) :
list_scope.
Delimit Scope list_scope with list.
Local Open Scope list_scope.
Definition length (
A :
Type) :
list A -> nat :=
fix length l :=
match l with
|
nil =>
O
|
_ :: l' =>
S (
length l')
end.
Concatenation of two lists
Definition app (
A :
Type) :
list A -> list A -> list A :=
fix app l m :=
match l with
|
nil =>
m
|
a :: l1 =>
a :: app l1 m
end.
Infix "++" :=
app (
right associativity,
at level 60) :
list_scope.
The CompareSpec inductive relates a comparison value with three
propositions, one for each possible case. Typically, it can be used to
specify a comparison function via some equality and order predicates.
Interest: CompareSpec behave nicely with case and destruct.
For having clean interfaces after extraction, CompareSpec is declared
in Prop. For some situations, it is nonetheless useful to have a
version in Type. Interestingly, these two versions are equivalent.
As an alternate formulation, one may also directly refer to predicates
eq and lt for specifying a comparison, rather that fully-applied
propositions. This CompSpec is now a particular case of CompareSpec.
Misc Other Datatypes
identity A a is the family of datatypes on
A whose sole non-empty
member is the singleton datatype
identity A a a whose
sole inhabitant is denoted
identity_refl A a
Identity type