Skip to content
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

Type class inference failure in pi type #2011

Closed
1 task done
hrmacbeth opened this issue Jan 5, 2023 · 0 comments
Closed
1 task done

Type class inference failure in pi type #2011

hrmacbeth opened this issue Jan 5, 2023 · 0 comments

Comments

@hrmacbeth
Copy link

Prerequisites

  • Put an X between the brackets on this line if you have done all of the following:
    • Checked that your issue isn't already filed.
    • Reduced the issue to a self-contained, reproducible test case.

Description

This is a failure of type class inference (possibly relevant: in a pi-type), which did not occur in Lean 3.

Steps to Reproduce

class Zero (α : Type) where
  zero : α

notation "" => Zero.zero

class SMul (R α : Type) where
  smul : R → α → α

infixr:73 "" => SMul.smul

class SMulZeroClass (R α : Type) [Zero α] extends SMul R α where
  smul_zero : ∀ r : R, r • (◯ : α) = ◯

namespace pi
variable {I : Type}
variable {f : I → Type}

instance instZero [∀ i, Zero (f i)] : Zero (∀ i : I, f i) := ⟨fun _ => ◯⟩

instance instSMul [∀ i, SMul R (f i)] : SMul R (∀ i : I, f i) := ⟨fun s x i => s • x i⟩

instance (R) [∀ i, Zero (f i)] [∀ i, SMulZeroClass R (f i)] :
    SMulZeroClass R (∀ i, f i) :=
  { pi.instSMul with
    smul_zero := fun _ => funext fun _ => SMulZeroClass.smul_zero _ }

end pi

Expected behavior: [What you expect to happen]

No errors. (Note that this works in Lean 3.)

Actual behavior: [What actually happens]

"failed to synthesize instance SMulZeroClass R (f x✝)" on the SMulZeroClass.smul_zero _

Reproduces how often: [What percentage of the time does it reproduce?]

Always

Versions

Nightly 2023-01-04

Additional Information

Zulip: https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/type.20class.20inference.20failure.20in.20pi.20type
Mathlib PR where this arose: leanprover-community/mathlib4#1283

bors bot pushed a commit to leanprover-community/mathlib4 that referenced this issue Jan 7, 2023
One earlier failure was extensively discussed:
- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Performance.20issue.20with.20.60CompleteBooleanAlgebra.60/near/319019205
- https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/type.20class.20inference.20looping

and is fixed as of leanprover/lean4@70a6c06, in mathlib as of the bump #1335.

Another failure posted to Zulip and the Lean 4 repo
- https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/type.20class.20inference.20failure.20in.20pi.20type
- leanprover/lean4#2011

and is fixed as of leanprover/lean4@fedf235, in mathlib as of the bump #1397.

There is one more mysterious `apply` failure, now worked around; we should track this down someday.

- [x] depends on: #1397

Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
jcommelin pushed a commit to leanprover-community/mathlib4 that referenced this issue Jan 23, 2023
One earlier failure was extensively discussed:
- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Performance.20issue.20with.20.60CompleteBooleanAlgebra.60/near/319019205
- https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/type.20class.20inference.20looping

and is fixed as of leanprover/lean4@70a6c06, in mathlib as of the bump #1335.

Another failure posted to Zulip and the Lean 4 repo
- https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/type.20class.20inference.20failure.20in.20pi.20type
- leanprover/lean4#2011

and is fixed as of leanprover/lean4@fedf235, in mathlib as of the bump #1397.

There is one more mysterious `apply` failure, now worked around; we should track this down someday.

- [x] depends on: #1397

Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant