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

Typeclass inference failure with lambda #509

Closed
1 task done
kbuzzard opened this issue Jun 4, 2021 · 0 comments
Closed
1 task done

Typeclass inference failure with lambda #509

kbuzzard opened this issue Jun 4, 2021 · 0 comments

Comments

@kbuzzard
Copy link
Contributor

kbuzzard commented Jun 4, 2021

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

Typeclass inference fails to discover an instance which I can create manually using instances known to Lean, and there does not seem to be a type class diamond or loop involved.

class has_note (M : Type) where
  note : M

notation "♩" => has_note.note

class has_note2 (M : Type) extends has_note M

variable {ι : Type} (β : ι → Type)

structure foo [∀ i, has_note (β i)] : Type where
  to_fun : ∀ i, β i

instance foo.has_note [∀ i, has_note (β i)] : has_note (foo (λ i => β i)) where
  note := { to_fun := λ _ => ♩ }

instance foo.has_note2 [∀ i, has_note2 (β i)] : has_note2 (foo (λ i => β i)) where
  note := ♩

variable (α : Type) (M : Type)

structure bar [has_note M] where
  to_fun : α → M

instance bar.has_note [has_note M] : has_note (bar α M) where
  note := { to_fun := λ _ => ♩ }

instance bar.has_note2 [has_note2 M] : has_note2 (bar α M) where
  note := ♩

example [has_note2 M] : has_note2 (foo (λ (i : ι) => bar (β i) M)) :=
inferInstance -- fails

example [has_note2 M] : has_note2 (foo (λ (i : ι) => bar (β i) M)) :=
foo.has_note2 _ -- works

The trace for the failing inferInstance is

  [Meta.synthInstance.generate] instance foo.has_note2
  [Meta.synthInstance.tryResolve] 
    [Meta.synthInstance.tryResolve] has_note2
      (foo fun (i : ι) => bar (β i) M) =?= has_note2 (foo fun (i : ?m.1321) => ?m.1322 i)
    [Meta.synthInstance.tryResolve] failure
  [Meta.synthInstance] failed

This also fails in Lean 3. [This shows up when building algebraic instances for finsupp and dfinsupp (finitely supported functions, i.e. functions which take the note value (0 or 1) for all but finitely many inputs)].

Expected behavior: [What you expect to happen]

I am expecting type class inference to succeed but my understanding of Lean 4's type class system is poor.

Versions

Lean (version 4.0.0-nightly-2021-06-03, commit c47fff1, Release)
Linux bob 5.4.0-74-generic #83-Ubuntu SMP Sat May 8 02:35:39 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
DISTRIB_DESCRIPTION="Ubuntu 20.04.2 LTS"

ChrisHughes24 pushed a commit to ChrisHughes24/lean4 that referenced this issue Dec 2, 2022
This is a quick and dirty port of `abel1`, just a direct translation of what is in Lean 3, with minimal modifications to use the new `norm_num`. (This PR depends on leanprover#507, integer operations for norm_num.)

Recall `abel1` is the tactic that solves equations; I haven't done the normalizer tactic `abel` yet, but hopefully it's straightforward from here.

- [x] depends on: leanprover#507

Co-authored-by: Mario Carneiro <di.gama@gmail.com>
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