#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:
- Instances can be synthesized by Lean.
- It is expected that an instance, if it exists, is unique for a given type.
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.
At its simplest, typeclass synthesis is just search.
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.
We can also have inductive typeclasses.
BasePoint class #
This associates a basepoint to a type.
Equations
- instBasePointString = { basePoint := "hello" }
Equations
- idBasePoint = { basePoint := id }