Zulip Chat Archive
Stream: general
Topic: type class inference fail
Johan Commelin (Jun 08 2018 at 07:52):
don't know how to synthesize placeholder context: R : Type, _inst_1 : comm_ring.{0} R, _inst_2 : topological_space.{0} R, _inst_3 : @topological_ring.{0} R _inst_2 (@comm_ring.to_ring.{0} R _inst_1), R₀ : set.{0} R, _inst_4 : @is_subring R (@comm_ring.to_ring.{0} R _inst_1) R₀, I : set.{0} (@coe_sort.{1 2} (set.{0} R) (@set.has_coe_to_sort.{0} R) R₀), _inst_5 : @is_ideal.{0} (@coe_sort.{1 2} (set.{0} R) (@set.has_coe_to_sort.{0} R) R₀) (@subtype.comm_ring R (@comm_ring.to_ring.{0} R _inst_1) _inst_1 R₀ _inst_4) I ⊢ topological_space.{0} R
Why can this even fail?
Kevin Buzzard (Jun 08 2018 at 07:54):
Because type class inference is not looking at your context, maybe?
Johan Commelin (Jun 08 2018 at 07:56):
Right... so how is it ever supposed to figure things out if it doesn't look at my context?
Kevin Buzzard (Jun 08 2018 at 07:56):
example (G : Type) : comm_group G → ∀ a b : G, a * b = b * a := begin admit end
Kevin Buzzard (Jun 08 2018 at 07:56):
failed to synthesize type class instance for G : Type, a : comm_group G, a b : G ⊢ has_mul G
Kevin Buzzard (Jun 08 2018 at 07:56):
The system doesn't look there
Johan Commelin (Jun 08 2018 at 07:57):
Shouldn't it?
Kevin Buzzard (Jun 08 2018 at 07:57):
That's not a question I'm qualified to answer
Kevin Buzzard (Jun 08 2018 at 07:57):
example (G : Type) [comm_group G] : ∀ a b : G, a * b = b * a := begin admit end
Kevin Buzzard (Jun 08 2018 at 07:57):
That works
Kevin Buzzard (Jun 08 2018 at 07:57):
the square brackets mean "add me to the type class inference system"
Johan Commelin (Jun 08 2018 at 07:58):
This feels extremely counterintuitive to me... after all, we go through pains to make sure there is only one instance of a class... so if there is one instance in my context there won't be any others. (I promise!)
Kevin Buzzard (Jun 08 2018 at 07:58):
However there are commands which explicitly add stuff to the type class inference system
Sean Leather (Jun 08 2018 at 07:58):
@Johan Commelin What does set_option pp.all true
before that tell you?
Kevin Buzzard (Jun 08 2018 at 07:58):
Do you know about letI
?
Kevin Buzzard (Jun 08 2018 at 07:58):
Maybe search for that in the type class inference thread
Johan Commelin (Jun 08 2018 at 07:58):
Aha, I don't know about letI
.
Kevin Buzzard (Jun 08 2018 at 07:59):
I half-understand it
Kevin Buzzard (Jun 08 2018 at 07:59):
the main gotcha is that this is defined in mathlib
Johan Commelin (Jun 08 2018 at 07:59):
@Sean Leather I already have that set to true. You see it in the output.
Kevin Buzzard (Jun 08 2018 at 07:59):
so you have to import _some_ mathlib file before it works
Johan Commelin (Jun 08 2018 at 07:59):
Is this one of our mathematical promises playing up again?
Kevin Buzzard (Jun 08 2018 at 08:00):
stream:general topic:more+type+class+inference+issues leti
Kevin Buzzard (Jun 08 2018 at 08:03):
Kevin Buzzard (Jun 08 2018 at 08:03):
Kenny teaching me about letI in pretty much the same situation
Johan Commelin (Jun 08 2018 at 08:03):
Right, so I insert
by haveI := topological_space R; exact
in the middle of my definition, and it works. Ugly!
Kevin Buzzard (Jun 08 2018 at 08:04):
I totally agree that it is ugly
Kevin Buzzard (Jun 08 2018 at 08:04):
And they have no plans to change it in Lean 4
Kevin Buzzard (Jun 08 2018 at 08:05):
Mario wrote all this letI and exactI and haveI when Leo made some non-trivial changes which broke a lot of stuff
Kevin Buzzard (Jun 08 2018 at 08:05):
For some reason, liberal type class inference was making Lean slow
Kevin Buzzard (Jun 08 2018 at 08:05):
for his application
Kevin Buzzard (Jun 08 2018 at 08:05):
so he made it stricter
Kevin Buzzard (Jun 08 2018 at 08:05):
and then a whole bunch of mathlib broke
Kevin Buzzard (Jun 08 2018 at 08:06):
and if this letI hack hadn't worked
Kevin Buzzard (Jun 08 2018 at 08:06):
then it would not surprise me if mathlib would still be broken
Kevin Buzzard (Jun 08 2018 at 08:07):
On the other hand
Kevin Buzzard (Jun 08 2018 at 08:07):
I'm not sure you can have "mathematician inference"
Kevin Buzzard (Jun 08 2018 at 08:07):
I think we're too clever
Kevin Buzzard (Jun 08 2018 at 08:08):
If you can formalise some nice MWE of something which you feel would be nice if it worked but doesn't work
Kevin Buzzard (Jun 08 2018 at 08:08):
then you could ask Sebastian or Mario why it doesn't work
Kevin Buzzard (Jun 08 2018 at 08:08):
but I fear the answer might be
Kevin Buzzard (Jun 08 2018 at 08:09):
something like "if that worked, then this important file would take 100 years to compile"
Kevin Buzzard (Jun 08 2018 at 08:09):
But I'm not sure, what happened with the changes to type class inference is beyond my pay grade
Last updated: Dec 20 2023 at 11:08 UTC