To play this document inside your browser use ALT-N and ALT-P.
You can save your edits inside your browser and load them back (edits are also saved when you close the window). Finally you can download the file for offline editing.
Polymorphism != overloading.
Example: the == computable equality
We call eqType an interface. With some approximation
eqType is defined as follows:
Module Equality. Structure type : Type := Pack { sort : Type; op : sort -> sort -> bool; axiom : ∀x y, reflect (x = y) (op x y) }. End Equality
Mathematical Components defines a hierarchy of interfaces. They group notations and theorems.
Let's use the theory of eqType
Interfaces do apply to registered, concrete examples
such as bool or nat. They can also apply to variables,
as long as their type is rich
(eqType is richer than Type).
Interfaces can be used to parametrize an entire theory
The BigOp library is the canonical example of a generic theory. It it about the fold iterator we studied in lesson 1, and the many uses it can have.
Most of the lemmas require the operation to be a monoid, some others to be a commutative monoid.
A sub type extends another type by adding a property. The new type has a richer theory. The new type inherits the original theory.
Let's define the type of homogeneous tuples
We instrument Coq to automatically promote sequences to tuples.
Now we the tuple type to form an eqType, exactly as seq does.
Which is the expected comparison for tuples?
Given that propositions are expressed (whenever possible) as booleans we can systematically prove that proofs of these properties are irrelevant.
As a consequence we can form subtypes and systematically prove that the projection to the supertype is injective, that means we can craft an eqType.
Tuples is not the only subtype part of the library. Another one is 'I_n, the finite type of natural numbers smaller than n.