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

The motive argument to False.rec is explicit but elaboration does not use a supplied positional argument as the motive #4347

Closed
kmill opened this issue Jun 4, 2024 · 3 comments · Fixed by #4817
Labels
bug Something isn't working

Comments

@kmill
Copy link
Collaborator

kmill commented Jun 4, 2024

Description

One normally expects the motive argument for eliminators to be implicit, but for False.rec it is explicit. This interacts in a confusing way with the app eliminator since this explicit argument does not make use of the supplied positional arguments.

Context

This question has come up a couple times recently: Zulip discussion 1 and discussion 2

Steps to Reproduce

As one can see, the type of False.rec is

#check False.rec -- False.rec.{u} (motive : False → Sort u) (t : False) : motive t

It has an explicit argument for the motive.

However, using False.rec with an explicit motive throws an error:

def bar (h : False) : Nat := False.rec (fun _ => Nat) h
/-
application type mismatch
  False.rec ?m.29 fun x => Nat
argument
  fun x => Nat
has type
  ?m.31 → Type : Sort (max 2 ?u.30)
but is expected to have type
  False : Prop
-/

This is because it's being elaborated as an eliminator, which causes the elaborator to solve for the motive and ignore that it's a positional argument.

The expected behavior is for explicit arguments to be filled positionally from supplied arguments.

A workaround is to write @False.rec (fun _ => Nat) h instead to disable elaborating as an eliminator.

Versions

4.8.0-rc2

Discussion

These are some potential solutions:

  1. Make sure that the motive argument for False.rec is implicit.
  2. Make the ElabAsElim code check to see if the motive argument is explicit, and if it is, use a positional argument. Users can supply _ if it is meant to be solved for. If x : False, then x.rec on its own should be the same as False.rec _ x.

They are not mutually exclusive, and even if the first is implemented, the second could still be useful for user @[elab_as_elim] declarations.

Impact

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

@kmill kmill added the bug Something isn't working label Jun 4, 2024
@leodemoura
Copy link
Member

@kmill Thanks. Let's go with option 2.

@faenuccio
Copy link

@leodemoura If you have time, can you explain briefly why this seems more reasonable to you?

@leodemoura
Copy link
Member

@faenuccio This is an elaboration issue. False.rec is generated by the kernel. We should not modify the kernel to fix an elaboration issue.

kmill added a commit to kmill/lean4 that referenced this issue Jul 24, 2024
Some eliminators (such as `False.rec`) have an explicit motive argument. The `elabAsElim` elaborator assumed that all motives are implicit.

Closes leanprover#4347
kmill added a commit to kmill/lean4 that referenced this issue Jul 29, 2024
Some eliminators (such as `False.rec`) have an explicit motive argument. The `elabAsElim` elaborator assumed that all motives are implicit.

Closes leanprover#4347
github-merge-queue bot pushed a commit that referenced this issue Jul 29, 2024
Some eliminators (such as `False.rec`) have an explicit motive argument.
The `elabAsElim` elaborator assumed that all motives are implicit.

If the explicit motive argument is `_`, then it uses the elab-as-elim
procedure, and otherwise it falls back to the standard app elaborator.

Furthermore, if an explicit elaborator is not provided, it falls back to
treating the elaborator as being implicit, which is convenient for
writing `h.rec` rather than `h.rec _`. Rationale: for `False.rec`, this
simulates it having an implicit motive, and also motives are generally
not going to be available in the expected type.

Closes #4347
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants