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

pre-SIP: Underscore Syntax for Type Lambdas #5379

Open
odersky opened this issue Nov 3, 2018 · 16 comments
Open

pre-SIP: Underscore Syntax for Type Lambdas #5379

odersky opened this issue Nov 3, 2018 · 16 comments

Comments

@odersky
Copy link
Contributor

odersky commented Nov 3, 2018

We'd like to eventually use F[_] as a short-hand syntax for the type lambda [X] => F[X]. It would mean we have to switch regular wildcard syntax to F[?]. The problem is that this is the syntax currently used by KindProjector, because _ was unavailable. The tricky bit is how to shift things around?

We need a multi-version strategy for this. I am starting the version count at 3.0, but it could also be something else, 2.14, or even 2.13.

  • Scala 3.0: Both _ and ? mean "wildcard". Native type lambdas remove the most pressing need for kind projector. If kind projector is still needed, it would use something else ("__" maybe?)

  • Scala 3.1: _ is deprecated for wildcards

  • Scala 3.2: _ is removed for wildcards

  • Scala 3.3: _ is introduced as a shorthand for type lambdas

If type lambdas get introduced in 2.13, and 2.14, we could also start this process sooner.

@odersky odersky changed the title Wildcard Syntax for Type Lambdas SIP: Wildcard Syntax for Type Lambdas Nov 3, 2018
@kubukoz
Copy link
Contributor

kubukoz commented Nov 3, 2018

So, just to be clear, in Scala 3.3:

Functor[Either[String, _]] will be the equivalent of

Functor[[X] => Either[String, X]], or what's currently known (with kind-projector) as

Functor[Either[String, ?]]? Sounds good to me. Especially with the suggested roadmap of incremental changes.

@SethTisue
Copy link
Member

SethTisue commented Nov 3, 2018

it's too late for native type lambdas to make 2.13, but 2.14 seems like a strong possibility

@SethTisue
Copy link
Member

(for those who haven't seen or thought about this before, #2041 is an earlier iteration of this that explains the motivation more and has some discussion)

@Jasper-M
Copy link
Contributor

Jasper-M commented Nov 5, 2018

Why not do "_is deprecated for wildcards" in 3.0 and then do the last 2 changes a version earlier?

@smarter smarter changed the title SIP: Wildcard Syntax for Type Lambdas SIP: Underscore Syntax for Type Lambdas Nov 5, 2018
@smarter
Copy link
Member

smarter commented Nov 7, 2018

Why not do "_is deprecated for wildcards" in 3.0 and then do the last 2 changes a version earlier?

We'd like to be able to cross-compile code between 2.14 and 3.0 without warnings (but their might be better ways to achieve this, such as getting 2.14 to understand ?)

@Krever
Copy link

Krever commented Nov 7, 2018

Functor[Either[String, _]] will be the equivalent of
Functor[[X] => Either[String, X]]

I would rather expect [X] => Functor[Either[String, X]] to be precise

@smarter
Copy link
Member

smarter commented Nov 7, 2018

@Krever but that wouldn't match how the underscore syntax works for term lambdas (foo(bar(a, _)) is equivalent to foo(x => bar(a, x)), not x => foo(bar(a, x))).

@Krever
Copy link

Krever commented Nov 7, 2018

My bad, nevermind ;)

@nightscape
Copy link

Wouldn't it be possible that kind-projector uses another symbol first and deprecates and removes the ? before Scala 3.0 is out?

@smarter
Copy link
Member

smarter commented Nov 30, 2018

@nightscape Yes.

@nightscape
Copy link

Created an issue in kind-projector:
typelevel/kind-projector#84

@LPTK
Copy link
Contributor

LPTK commented Jan 6, 2019

For the record, a cool use case for type-level underscore syntax I mentioned on the forum.

Being able to write:

def foo[A: _ <:< Int] = // ...

instead of:

def foo[A](implicit ev: A <:< Int] = // ...

or instead of the following, which already works but is clumsy:

def foo[A: [T] => T <:< Int] = // ...

TomasMikula added a commit to TomasMikula/kind-projector that referenced this issue Feb 21, 2019
Motivation:
There is a proposal for F[?] to denote a wildcard (currently F[_])
in Scala 3.0+ and F[_] to be a shorthand syntax for type lambda
(F[?] with current kind-projector syntax) in Scala 3.3+ (see
scala/scala3#5379).

Supporting an additional placeholder will allow users to gradually move
from `?` to `*` before Scala 3.0 is out.
TomasMikula added a commit to TomasMikula/kind-projector that referenced this issue Feb 21, 2019
Motivation:
There is a proposal for F[?] to denote a wildcard (currently F[_])
in Scala 3.0+ and F[_] to be a shorthand syntax for type lambda
(F[?] with current kind-projector syntax) in Scala 3.3+ (see
scala/scala3#5379).

Supporting an additional placeholder will allow users to gradually move
from `?` to `*` before Scala 3.0 is out.

Resolves typelevel#84.
@esarbe
Copy link
Contributor

esarbe commented Mar 21, 2019

I would prefer * for wildcard types. Would that be possible?

@odersky
Copy link
Contributor Author

odersky commented Apr 5, 2022

We should try to make the next step (deprecation of wildcards now).

@smarter
Copy link
Member

smarter commented Apr 5, 2022

Before that I'd like to see Scala 2 support the new syntax by default (right now it's still under -Xsource:3, but using a type named ? without backticks has been deprecated for a while so I think it's safe to change the default). Also 3.2 is already slated to deprecate non-exhaustive pattern bindings without case (#14294) and I think we should try not to pile up too many disruptive changes at once, so I'd vote for deprecating only in 3.3

@odersky odersky removed this from the 3.2.0-RC1 milestone Apr 5, 2022
@odersky odersky added this to the 3.3.0-RC1 milestone Apr 5, 2022
smarter added a commit to smarter/scala that referenced this issue Apr 5, 2022
Like scala#9721, the goal here is to ease
cross-compilation between Scala 2 and 3 code as we prepare for `_` as wildcard
to be deprecated in Scala 3 (cf scala/scala3#5379).

This is technically a source-breaking change, but using a type named ? without
backticks is deprecated since 2.13.6 (scala#9626) and defining a type named ? without
backticks is disallowed since 2.13.7 (scala#9735). The only known user of ? as a type
name was the kind-projector plugin, but support for this syntax was removed from
the plugin a year ago (typelevel/kind-projector#186),
so I believe this change won't be disruptive.
@smarter
Copy link
Member

smarter commented Apr 5, 2022

I'd like to see Scala 2 support the new syntax by default

PR: scala/scala#9990

@Kordyjan Kordyjan modified the milestones: 3.3.0-RC1, Future versions Dec 12, 2022
@ckipp01 ckipp01 changed the title SIP: Underscore Syntax for Type Lambdas pre-SIP: Underscore Syntax for Type Lambdas May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants