-
Notifications
You must be signed in to change notification settings - Fork 437
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
passing instances to named arguments turns explicit args into implicit #1867
Comments
This issue was reported by Terry Tao in https://leanprover.zulipchat.com/#narrow/stream/217875-Is-there-code-for-X.3F/topic/Set.2EtoFinset.20without.20Fintype.20or.20Set.2EFinite/near/418374814 He found he had to write noncomputable def Set.toFinset' {α: Type*} (s: Set α) : Finset α :=
dite (h := Classical.dec (Set.Finite s)) Set.Finite.toFinset (fun _ ↦ ∅) instead of
|
Jireh Loreaux reported a similar error, but this wasn't for an instance argument, but an argument that depends on previous explicit arguments. https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/behavior.20of.20.60.28arg.20.3A.3D.20sorry.29.60.20syntax/near/421895074 theorem foo (n m : Nat) (h : m = n) : m = n := h
example (n m : Nat) (h' : m = n) : m = n :=
foo (h := h') -- succeeds, even without `n` and `m` passed to `foo`
example (n m : Nat) (h' : m = n) : m = n :=
foo _ _ (h := h') -- fails ("function expected" from too many arguments)
example (n m : Nat) (h' : m = n) : m = n :=
foo _ _ h' -- succeeds
|
This was also reported in https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/named.20arguments.20of.20dependent.20functions/near/443147810 structure D where
structure C (x : D) where
def f (x : D) (y : C x) := 0
example := f {} (y := {}) --fails
example := f (x := {}) (y := {}) --works
example := f (x := {}) {} --works
example := f {} {} --works
-- if our function is not dependent, all four cases work
def g (x y : D) := 0
example := g {} (y := {}) --works
example := g (x := {}) (y := {}) --works
example := g (x := {}) {} --works
example := g {} {} --works |
Another user was confused by this behavior here: https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/.40foo.20.28A.20.3A.3D.20bar.29.20_.20_/near/468564862 Related RFC #5386 and PR #5283 I argued here that I'm in favor of turning of the feature "argument suppression via named arguments". |
Recall that currently named arguments suppress all explicit parameters that are dependencies. This PR limits this feature to only apply to true structure projections, except in the case where it is triggered when there are no more positional arguments. This preserves the primary reason for generalizing this feature (issue #1851), while removing the generalized feature, which has led to numerous confusions (issue #1867). This also fixes a bug pointed out [on Zulip](https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/.40foo.20.28A.20.3A.3D.20bar.29.20_.20_/near/468564862) where in `@` mode, instance implicit parameter dependencies to named arguments would be suppressed unless the next positional argument was `_`. More detail: * The `NamedArg` structure now has a `suppressDeps : Bool` field. It is set to `true` for the `self` argument in structure projections. If there is such a `NamedArg`, explicit parameters that are dependencies to the named argument are turned into implicit arguments. The consequence is that *all* structure projections are treated as if their type parameters are implicit, even for class projections. This flag is *not* used for generalized field notation. * We preserve the suppression feature when there are no positional arguments remaining. This feature pre-dates the fix to issue #1851, and it is useful when combining named arguments and the eta expansion feature, since dependencies of named arguments cannot be turned into eta arguments. Plus, there are examples of the form `rw [lem (h := foo)]` where `lem` has explicit arguments that `h` depends on. * For instance implicit parameters in explicit mode, now `_` arguments register terminfo and are hoverable. * Now `..` is respected in explicit mode. This implements RFC #5397. The `suppressDeps` flag suggests a future possibility of a named argument syntax that can suppress dependencies.
It looks like this issue is fixed now due to #5283. |
This is a recent regression caused by a5ab59a (the fix for #1851), and came up in the std4 nightly bump leanprover-community/batteries#31.
Here is a proposal for how to handle app args that should fix both this issue and #1851:
_
and the rest are reverted.(I believe the only difference from current behavior being suggested here is that named parameters should be processed in order with explicit args rather than all at the beginning.)
This has the following behavior:
x.bla y (foo := ⟨⟩)
turns into@Bla.foo x y ⟨⟩
x.bla (foo := ⟨⟩) y
is an error, because they
argument was made implicitx.bla (y := y) (foo := ⟨⟩)
andx.foo (foo := ⟨⟩) (y := y)
both workx.bla
works and has type∀ (y : Int) [foo : Foo x y], Nat
and using the example from #1851:
f.val
works and results in@Approx.val (α → β) f' (X → Y) f : X → Y
f.val x.val
is an over-application becausef.val
has already filled all the explicit arguments, so this is handled as(f.val) x.val
which worksThe text was updated successfully, but these errors were encountered: