leanprover / lean4

Lean 4 programming language and theorem prover
https://lean-lang.org
Apache License 2.0
4.74k stars 427 forks source link

`CoeFun` and implicit arguments #6124

Closed mniip closed 3 days ago

mniip commented 6 days ago

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

#check CoeFun.coe foo Nat
#check foo Nat

Expected behavior:

Actual behavior:

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 :+1: to issues you consider important. If others are impacted by this issue, please ask them to add :+1: to it.

Kha commented 3 days ago

CoeFun Foo fun _ => ∀{α}, α → α tells the elaborator to coerce the former type into the latter. I don't see why it should adjust the second type with any other information, at least without further motivation. Thus I'm closing this as by design.

mniip commented 3 days ago

@Kha I think there's a misunderstanding.

CoeFun Foo fun _ => ∀{α}, α → α tells the elaborator to coerce the former type into the latter.

That's exactly what it fails to do, hence this issue.

Instead of coercing to "the latter" -- whatever is written in the instance head, it coerces to what is actually the type of the instance body.