New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
typeclass inference failure #2074
Comments
A likely related issue appears here on Zulip, where example {α} [Ring α] : Module α α := inferInstance fails to work in mathlib4. |
I know you're not going to like this, but this is actually currently working as designed. |
That is actually what I expected the problem was when I've mentioned this being a "new-style-structure problem"; the same issue would occur in Lean3 with new-style structures, but doesn't occur with old-style structures as every base class unfolds to a constructor rather than a projection. I think I had hoped that structure eta made this not matter. So I think we either need to work out a way to make structure eta apply here, or we need to use old-style structures in mathlib4 (either via custom syntax we build ourselves, or by writing every base class instance manually. |
Here is a version of the issue that only uses class A (α : Type u)
class B (α : Type u) extends A α
class C (α : Type u) extends B α
class D (α : Type u) extends B α
class E (α : Type u) extends C α, D α
class F (α : Type u) extends A α
class G (α : Type u) extends F α, B α
class H (α : Type u) extends C α
class I (α : Type u) extends G α, D α
class J (α : Type u) extends H α, I α, E α
class StarRing' (R : Type 0) [B R]
def starGizmo [E R] [StarRing' R] : R → R := id
set_option pp.explicit true in
theorem starGizmo_foo [J R] [StarRing' R] (x : R) : starGizmo x = x := rfl
-- theorem T (i : J R) : (@D.toB.{0} R (@E.toD.{0} R (@J.toE.{0} R i))) = i.toB := rfl |
Can we re-enable this fix behind a set_option command, so that in the meantime we can diagnose whether inference failures would be fixed by this or are something else? |
|
Thanks! That was adcca17 I assume. |
This had some trouble with leanprover/lean4#2074 and leanprover/lean4#1926. There are also quite a few places where extra unfolding is needed in initializers for new-style structures. Co-authored-by: Johan Commelin <johan@commelin.net>
This can now be closed, as #2210 has been merged. |
Prerequisites
Description
It's possible to make the following happen:
even though the instance is right there in the local context. This is very confusing for users and is showing up in the mathlib port.
Steps to Reproduce
Here's a MWE with some debugging output. The classes are just stripped from mathlib.
Expected behavior: [What you expect to happen]
I would not expect the error.
Actual behavior: [What actually happens]
Looking at the logs, it seems that the
[tryResolve]
line is failing to unify two defeq terms of typeStarRing' R
Reproduces how often: [What percentage of the time does it reproduce?]
100%
Versions
Lean (version 4.0.0-nightly-2023-01-29, commit 38a0d1e3733e, Release)
on Ubuntu 22.04Additional Information
The issue shows up here and here in the mathlib port. Reported here on Zulip.
The text was updated successfully, but these errors were encountered: