Documentation

PfsProgs25.Unit10.BasePoint

#Typeclasses

Typeclasses are (parametrized) types that can be used as implicit arguments. Terms of such types are called instances.

What is special about these are:

Formally, a class is a type defined with the same syntax as a structure, but with the class keyword. The instances are defined with the instance keyword.

class Alone :
Instances
    instance instAlone :
    Equations

    At its simplest, typeclass synthesis is just search.

    instance extra :
    Equations
    def myAlone {alone : Alone} :
    Equations
    • myAlone = Alone.alone
    Instances For

      Parameters with type typeclasses can be inferred. This is stronger than implicit arguments. Implicit arguments are inferred from the type.

      The class syntax is just a shorthand for defining a structure with one field and annotating it. Annotations modify the environment, but do not affect the elaboration process. More precisely, they modify environmental extensions.

      class Alone' :
      Instances
        instance instAlone' :
        Equations

        We can also have inductive typeclasses.

        class inductive Alone'' :
        Instances

          BasePoint class #

          This associates a basepoint to a type.

          class BasePoint (α : Type u) :
          • basePoint : α
          Instances
            Equations
            def basePoint (α : Type u) [BasePoint α] :
            α

            Gives the basepoint of a type with a BasePoint instance.

            Equations
            Instances For
              instance instBasePointList {α : Type u} :
              Equations
              • instBasePointList = { basePoint := [] }
              instance prodBasePoint {α β : Type u} [BasePoint α] [BasePoint β] :
              BasePoint (α × β)
              Equations
              instance basePointZero {α : Type u} [Zero α] :
              Equations
              • basePointZero = { basePoint := Zero.zero }
              instance idBasePoint {α : Type u} :
              BasePoint (αα)
              Equations
              • idBasePoint = { basePoint := id }
              @[instance 100]
              instance codomainBasePoint {α β : Type u} [BasePoint β] :
              BasePoint (αβ)
              Equations
              • codomainBasePoint = { basePoint := fun (x : α) => basePoint β }

              Useful typeclasses #

              Equations
              def instHAddOfAdd_pfsProgs25 {α : Type} [Add α] :
              HAdd α α α
              Equations
              • instHAddOfAdd_pfsProgs25 = { hAdd := Add.add }
              Instances For