Zulip Chat Archive
Stream: general
Topic: automatic coercion?
Kenny Lau (May 20 2020 at 11:01):
import data.finset
#check λ s : finset ℕ, (s : set ℕ) -- invalid type ascription, term has type
#check λ s : finset ℕ, (↑s : set ℕ) -- λ (s : finset ℕ), ↑s : finset ℕ → set ℕ
#check λ x : ℕ, (x : ℤ) -- λ (x : ℕ), ↑x : ℕ → ℤ
Kenny Lau (May 20 2020 at 11:01):
why does N auto. coerce to Z but not finset to set?
Shing Tak Lam (May 20 2020 at 11:20):
(nevermind)
Shing Tak Lam (May 20 2020 at 11:28):
If I understand coe correctly, Lean will coerce the first one if it has_coe, the second one if it has_lift. There is
@[priority 10] instance cast_coe : has_coe ℕ α := ⟨nat.cast⟩
So the Nat to Int coercion works. But in data.finset, there's has_lift (finset α) (set α) but not has_coe (finset α) (set α), so the first one doesn't work.
Gabriel Ebner (May 20 2020 at 12:00):
Note that cast_coe has changed recently, it is now has_coe_t. But that doesn't have an effect on the finset coercion, which is exactly how @Shing Tak Lam described it.
@[priority 900] instance cast_coe : has_coe_t ℕ α := ⟨nat.cast⟩
Shing Tak Lam (May 20 2020 at 12:01):
(The folder I'm working in is on Lean 3.8.0, which is why I still have the old cast_coe)
Kenny Lau (May 20 2020 at 13:06):
why do we have such a distinction?
Last updated: May 02 2025 at 03:31 UTC