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.



Lesson 4: summary

  • generic notations and theories
  • interfaces and hierarchies
  • parametrizing theories
  • the BigOp library (the theories of fold)
  • subtypes
Let's start with a lie and then make it true:

Coq is an object oriented programming language.


Generic notations and theories

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

(notes)
This slide corresponds to section 5.4 of the Mathematical Components book



Interfaces and hierarchies

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).

(notes)
This slide corresponds to section 5.5 and 7 of the Mathematical Components book



Theories over an interface

Interfaces can be used to parametrize an entire theory

(notes)
This slide corresponds to section 5.6 of the Mathematical Components book



Generic theories: the BigOp library

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.

(notes)
This slide corresponds to section 5.7 of the Mathematical Components book



Sub types

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.

(notes)
This slide corresponds to section 6.1 and 6.2 of the Mathematical Components book



Sum up

  • Coq is an object oriented language ;-)

  • in the Mathematical Components library xxType is an interface (eg eqType for types with an equality test). Notations and theorems are linked to interfaces. Interfaces are organized in hierarchies (we just saw a picture, how it works can be found in the book).

  • subtypes add properties and inherit the theory of the supertype thanks to boolean predicates (UIP). In some cases the property can be inferred by Coq, letting one apply a lemma about the subtype on terms of the supertype.