无法使类型 类 在精益中工作

Can't make type classes work in Lean

我无法理解如何触发 Lean 对类型 类 的使用。这是一个小例子的尝试:

section the_section
structure toto [class] (A : Type) := (rel : A → A → Prop) (Hall : ∀ a, rel a a)

definition P A := exists (a : A), forall x, x = a
parameter A : Type
variable HA : P A

lemma T [instance] {B : Type} [HPB : P B] : toto B := toto.mk (λ x y, x = y) (λ x, rfl)

include HA
example : toto A := _
-- this gives the error: don't know how to infer placeholder toto A

end the_section

关键是我希望 Lean 看到它可以使用 HA 从引理 T 推导出 toto A。我错过了什么?

再一次,我不得不 post 这个问题才能找到答案。希望这对其他人有帮助。

P需要是一个class,所以我们实际上需要改变

definition P A := exists (a : A), forall x, x = a

definition P [class] A := exists (a : A), forall x, x = a