Zulip Chat Archive

Stream: general

Topic: typeclass inferences


Kenny Lau (Apr 05 2018 at 23:23):

https://github.com/kckennylau/Lean/blob/master/enough_injectives.lean#L72
In L72 of this, I needed to type @linear_map R M (Hom_R_Q_div_Z R) _ _ (Hom_R_Q_div_Z.module R), i.e. I needed to manually provide the proof term Hom_R_Q_div_Z.module R that Hom_R_Q_div_Z R is a module, despite it being attributed as instance. Why is this the case?

Scott Morrison (Apr 05 2018 at 23:27):

When faced with this problem, I often try to write an example beforehand, which hopefully should summon the instance via by apply_instance, and see if I can get that working.

Scott Morrison (Apr 05 2018 at 23:27):

If I can't I start worrying about universe levels, which in my experience is a very common cause of typeclass inference failing.

Scott Morrison (Apr 05 2018 at 23:28):

(I haven't actually looked at your example.)

Scott Morrison (Apr 05 2018 at 23:37):

Having quickly looked at your example, I'd suggest trying to restrict to the case where the ring and the module live in the same universe.

Kenny Lau (Apr 05 2018 at 23:37):

hmm, would that break generality?

Kenny Lau (Apr 05 2018 at 23:38):

linear_map accepts three universes

Scott Morrison (Apr 05 2018 at 23:38):

Yeah... but that's maybe dangerous as well.

Kenny Lau (Apr 05 2018 at 23:38):

so other universes don't have enough injectives lol

Scott Morrison (Apr 05 2018 at 23:39):

at least check if this solves the inference problem

Scott Morrison (Apr 05 2018 at 23:39):

If it doesn't then it's irrelevant. If it does, it's probably time to consult Mario for advice.

Scott Morrison (Apr 05 2018 at 23:39):

(One can always ulift when you don't have enough universe polymorphism, and sometimes this is the better option.)

Kenny Lau (Apr 05 2018 at 23:39):

it doesn't

Scott Morrison (Apr 05 2018 at 23:40):

Oh well!

Scott Morrison (Apr 05 2018 at 23:40):

try replacing the points where you explicitly provide the instances with by apply_instance, and then set pp.all

Kenny Lau (Apr 05 2018 at 23:43):

wait what

Kenny Lau (Apr 05 2018 at 23:46):

@Scott Morrison once I removed L67-69, everything worked

Kenny Lau (Apr 05 2018 at 23:46):

except the fact that i of course need those lines

Kenny Lau (Apr 06 2018 at 00:45):

@Mario Carneiro any idea? In here, I need Hom_R_Q_div_Z.module R to tell Lean that Hom_R_Q_div_Z R is a module, but once I remove L67-69, it is no longer necessary

Kenny Lau (Apr 06 2018 at 00:46):

I suspect it is because of the injective.to_module

Kenny Lau (Apr 06 2018 at 00:46):

interfering with the typeclass resolutions


Last updated: Dec 20 2023 at 11:08 UTC