Zulip Chat Archive
Stream: lean4
Topic: What does the syntax [className x] mean
Jafar Tanoukhi (Aug 17 2025 at 20:34):
While reading through Mathlib I noticed this syntax in Mathlib/Data/Fintype/Defs.lean.
variable {α β γ : Type*}
-- code here
variable [Fintype α]
-- other code here
What does this do exactly? I'm not very sure I understand classes other than the basics that you can make instances of it; to support ad-hoc polymorphism. Isn't α already declared too ?
Jafar Tanoukhi (Aug 17 2025 at 20:34):
"I asked this here and not in the mathlib channel, as it is more related to the syntax of lean4 than the fact that this was found in mathlib."
Aaron Liu (Aug 17 2025 at 20:36):
It means to synthesize the instance of Fintype α automatically by typeclass
Aaron Liu (Aug 17 2025 at 20:36):
when using theorems
Aaron Liu (Aug 17 2025 at 20:37):
so if you have
theorem exists_const {b : Prop} (α) [i : Nonempty α] : (∃ _ : α, b) ↔ b :=
⟨fun ⟨_, h⟩ => h, i.elim Exists.intro⟩
then you can use it as exists_const Nat and it will fill in [i : Nonempty Nat] automatically
Kenny Lau (Aug 17 2025 at 20:49):
@Jafar Tanoukhi you might want to refer to TPIL Ch. 10
Jafar Tanoukhi (Aug 17 2025 at 20:52):
Sorry I disappeared, was trying to understand the answer. But i'm not sure I do.
Jafar Tanoukhi (Aug 17 2025 at 20:53):
Wouldn't lean know to replace α with Nat without the whole Fintype α variable syntax ?
Jafar Tanoukhi (Aug 17 2025 at 20:53):
Kenny Lau said:
Jafar Tanoukhi you might want to refer to TPIL Ch. 10
Alright I will, thanks.
Last updated: Dec 20 2025 at 21:32 UTC