Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

Allow eta-expansion for creator applications #232

Closed
neko-kai opened this issue Jul 28, 2021 · 3 comments
Closed

Allow eta-expansion for creator applications #232

neko-kai opened this issue Jul 28, 2021 · 3 comments
Assignees

Comments

@neko-kai
Copy link

Compiler version

3.0.1

Minimized code

class Pair(a: Int, b: Int)
case class CasePair(a: Int, b: Int)

def a[A](f: (Int, Int) => A) = f(1, 2)

def xa = println(a(Pair.apply)) // boom
def xb = println(a(Pair.apply _)) // boom
def xc = println(a(Pair)) // boom

def ya = println(a(CasePair.apply)) // fine
def yb = println(a(CasePair.apply _)) // fine
def yc = println(a(CasePair)) // fine

@main def main = { xa; xb; xc; ya; yb; yc }

Output

def xa = println(a(Pair.apply)) // boom
// missing arguments for method apply in object Pair

def xb = println(a(Pair.apply _)) // boom
// Only function types can be followed by _ but the current expression has type Pair

def xc = println(a(Pair)) // boom
// Found:    Pair.type
// Required: (Int, Int) => Any

Expectation

Expected implicit apply to eta-expand, which would allow using a class's constructor as a function without having to supply (and later change) a placeholder for each constructor parameter, as in Pair(_, _) (prior discussion/motivation in
https://contributors.scala-lang.org/t/let-constructors-to-be-considered-as-functions/3798)

@odersky
Copy link

odersky commented Jul 29, 2021

That would be a language enhancement and a quite complicated one. I think this should go to feature suggestions, and ideally be accompanied with a PR.

@odersky odersky closed this as completed Jul 29, 2021
@neko-kai
Copy link
Author

Could anyone please transfer this issue to https://github.com/lampepfl/dotty-feature-requests/ in that case? If I open a new issue there, it would be identical to this one or refer to it, so it would probably better to avoid duplication.

@bishabosha bishabosha transferred this issue from scala/scala3 Jul 29, 2021
@bishabosha bishabosha reopened this Jul 29, 2021
@bishabosha
Copy link
Member

now a feature request

@neko-kai neko-kai changed the title Creator applications for non-case classes are not eta-expanded Allow eta-expansion for creator applications Jul 29, 2021
@lampepfl lampepfl locked and limited conversation to collaborators Jun 5, 2023
@ckipp01 ckipp01 converted this issue into a discussion Jun 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants