leanprover / leanprover/lean4

`CoeFun` and implicit arguments

Open
#6,124 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-low
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Prerequisites

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

Description

Function applications going through CoeFun do not respect the implicitness of the parameters declared in the instance head, rather they take the implicitness information from the instance implementation.

Context
Steps to Reproduce
structure Foo where app : ∀α, (x : α) → α

def foo := Foo.mk fun _ => id

instance : CoeFun Foo fun _ => ∀{α}, α → α where
  coe := Foo.app

/-- info: CoeFun.coe foo Nat : Type -/
#guard_msgs in
#check CoeFun.coe foo Nat
/-- info: foo.app Nat : Nat → Nat -/
#guard_msgs in
#check foo Nat

Expected behavior:

  • Both cases desugar as Foo.app foo (α:=Type) (x:=Nat), and infer the type Type

Actual behavior:

  • The first one infers the correct type, but the second desugars as Foo.app foo (α:=Nat) and infers the type Nat → Nat.
Versions

4.13.0

Additional Information

The problem can be reversed by making the structure field have implicit ∀{α} and the instance head have the explicit ∀α.
https://github.com/leanprover/lean4/issues/1891 seems relevant.

Impact

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the self-contained reproducer against Lean 4.13.0 and a current nightly, then compare the elaboration behavior with issue 1891. Trace the CoeFun application elaboration path; done means implicitness from the instance head is respected in both the direct coercion and function-application forms, including the reversed case.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.