Zulip Chat Archive
Stream: lean4
Topic: Typeclass is given by implicit arguments
Bhavik Mehta (Jan 16 2025 at 20:18):
Here's my example:
import Mathlib.Data.Set.Defs
class FooOfLE (α : Type) [LE α] where
exists_add_of_le {a b : α} (h : a ≤ b) : True
instance : FooOfLE Nat where
exists_add_of_le _ := trivial
example {a b : Nat} (h : a ∈ {x | x ≤ b}) : True := by
let x := FooOfLE.exists_add_of_le h
sorry
I believe this worked on Lean 4.14, although I'm not completely certain. The surprising part to me, on current Lean, is that the type of FooOfLE.exists_add_of_le
is
FooOfLE.exists_add_of_le {α : Type} {inst✝ : LE α} [self : FooOfLE α] {a b : α} (h : a ≤ b) : True
with the LE typeclass argument given with implicit brackets. Is this a recent change?
Kyle Miller (Jan 16 2025 at 20:38):
Yes, this was a recent change for performance and also to make projections be able to apply more generally. lean4#5376
Kyle Miller (Jan 16 2025 at 20:39):
Your example depends on some definition unfolding — maybe this is defeq abuse?
Kyle Miller (Jan 16 2025 at 20:40):
This is a workaround:
example {a b : Nat} (h : a ∈ {x | x ≤ b}) : True := by
let x := FooOfLE.exists_add_of_le (show a ≤ b from h)
sorry
Bhavik Mehta (Jan 16 2025 at 20:45):
Okay, thanks!
Last updated: May 02 2025 at 03:31 UTC