Use and abuse of instance parameters in the Lean mathematical library
Lean's mathematical library mathlib makes extensive use of the typeclass pattern (instance parameters) for organizing mathematical structures. At the scale of mathlib, complications arise that are not evident in smaller projects.
The paper analyzes representative examples of design patterns involving instance parameters in the Lean 3 version of mathlib. It focuses on complications arising at scale, including diamond inheritance, default instances, and performance issues with instance search, and documents how the mathlib community addresses them.
The analysis identifies recurring patterns and pitfalls: diamonds in algebraic hierarchies, forgetful inheritance, out-parameters for synthesis, and bundled vs. unbundled structures. The paper documents community solutions and trade-offs, serving as a reference for other projects using typeclasses at scale.
