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

match elaboration fails to unify definitionally equal types #6562

Open
3 tasks done
cppio opened this issue Jan 7, 2025 · 0 comments · May be fixed by #6577
Open
3 tasks done

match elaboration fails to unify definitionally equal types #6562

cppio opened this issue Jan 7, 2025 · 0 comments · May be fixed by #6577
Labels
bug Something isn't working P-medium We may work on this issue if we find the time

Comments

@cppio
Copy link
Contributor

cppio commented Jan 7, 2025

Prerequisites

Please put an X between the brackets as you perform the following steps:

Description

inductive Mem (a : α) : List α → Type
  | head (as : List α) : Mem a (a::as)
  | tail (b : α) {as : List α} : Mem a as → Mem a (b::as)

def del : @Mem α a as → List α
  | .head as => as
  | .tail b mem => b :: del mem

def memOfDel : (mem : Mem c as) → Mem a (del mem) → Mem a as
  | .head _, mem => .tail _ mem
  | .tail _ mem, .head _ => .head _
  | .tail _ mem, .tail _ mem' => .tail _ (memOfDel mem mem')

The above code gives the following error:

type mismatch
  Mem.head ?m.1321
has type
  Mem ?m.1320 (?m.1320 :: ?m.1321) : Type
but is expected to have type
  Mem a (del (Mem.tail ?m.1316 mem)) : Type

However, the definitional equation for the tail case of del should result in the solution ?m.1316 = ?m.1320 = a and ?m.1321 = del mem.
Separating out the second match and adding a type ascription results in an even more inscrutable error:

def memOfDel' : (mem : Mem c as) → Mem a (del mem) → Mem a as
  | .head _, mem => .tail _ mem
  | .tail b mem, (mem' : Mem a (b :: del mem)) =>
    match mem' with
    | .head _ => .head _
    | .tail _ mem' => .tail _ (memOfDel' mem mem')
type mismatch
  mem'
has type
  Mem a (b :: del mem) : Type
but is expected to have type
  Mem a (del (Mem.tail b mem)) : Type

It is easy to verify that these are definitionally equal:

example : Mem a (b :: del mem) = Mem a (del (Mem.tail b mem)) := rfl

Using .tail (as := _as) b mem in memOfDel' succeeds, but it is not clear from the error message why this is necessary.

Steps to Reproduce

Run the code above.

Expected behavior: The code succeeds with no errors.

Actual behavior: The code gives the errors above.

Versions

Lean 4.16.0-nightly-2025-01-06

Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

@cppio cppio added the bug Something isn't working label Jan 7, 2025
@cppio cppio linked a pull request Jan 8, 2025 that will close this issue
@leanprover-bot leanprover-bot added the P-medium We may work on this issue if we find the time label Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P-medium We may work on this issue if we find the time
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants