Chapter 18  Type Classes

Matthieu Sozeau

The status of Type Classes is (extremelly) experimental.

This chapter presents a quick reference of the commands related to type classes. For an actual introduction to type classes, there is a description of the system [126] and the literature on type classes in Haskell which also applies.

18.1  Class and Instance declarations

The syntax for class and instance declarations is the same as record syntax of Coq:

Class Id (α1 : τ1) ⋯ (αn : τn)  [: sort] := {
 f1:type1 ; 
   
 fm:typem }.
Instance ident : Id term1 ⋯ termn := {
 f1:=termf1 ; 
   
 fm:=termfm }.

The αi : τi variables are called the parameters of the class and the fk : typek are called the methods. Each class definition gives rise to a corresponding record declaration and each instance is a regular definition whose name is given by ident and type is an instantiation of the record type.

We’ll use the following example class in the rest of the chapter:

Coq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq < Class EqDec (A : Type) := {
Coq <   eqb : A -> A -> bool ;
Coq <   eqb_leibniz : forall x y, eqb x y = true -> x = y }.

This class implements a boolean equality test which is compatible with leibniz equality on some type. An example implementation is:

Coq < Instance unit_EqDec :T> oq </