ITree.Basics.Function

The Category of Functions

Definitions to work with Coq functions A B categorically.


The name of the category.
Definition Fun (A B : Type) : Type := A B.

The identity function, but can sometimes help type inference.
Definition apply_Fun {A B : Type} (f : Fun A B) : A B := f.

Extensional function equality
#[global] Instance eeq : Eq2 Fun :=
  fun A B f g a : A, f a = g a.

Identity function
#[global] Instance Id_Fun : Id_ Fun :=
  fun Afun aa.

Function composition
#[global] Instance Cat_Fun : Cat Fun :=
  fun A B C f gfun ag (f a).

void as an initial object.
#[global] Instance Initial_void : Initial Fun void :=
  fun _ vmatch v : void with end.

unit as a final object.
#[global] Instance Terminal_unit : Terminal Fun unit :=
  fun _ xtt.

The sum coproduct.

Coproduct elimination
#[global] Instance case_sum : Case Fun sum :=
  fun {A B C} (f : A C) (g : B C) (x : A + B) ⇒
    match x with
    | inl af a
    | inr bg b
    end.

Injections
#[global] Instance sum_inl : Inl Fun sum := @inl.
#[global] Instance sum_inr : Inr Fun sum := @inr.

The pair product.

#[global] Instance Pair_Fun : Pair Fun prod :=
  fun {A B C} l r c(l c, r c).

#[global] Instance Fst_Fun : Fst Fun prod := @fst.
#[global] Instance Snd_Fun : Snd Fun prod := @snd.

Cartesian closure.

The exponential is just _ _, which is a just another name for Fun
#[global] Instance Apply_Fun : Apply Fun prod Fun :=
    fun {A B} '(f, b)f b.

#[global] Instance Curry_Fun : Curry Fun prod Fun :=
  fun {A B C} ffun c af (c, a).