Dotty: SIP: Underscore Syntax for Type Lambdas

Created on 3 Nov 2018  路  13Comments  路  Source: lampepfl/dotty

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.

needs spec

Most helpful comment

Created an issue in kind-projector:
https://github.com/non/kind-projector/issues/84

All 13 comments

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.

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

(for those who haven't seen or thought about this before, https://github.com/lampepfl/dotty/issues/2041 is an earlier iteration of this that explains the motivation more and has some discussion)

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

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 ?)

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

@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))).

My bad, nevermind ;)

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

@nightscape Yes.

Created an issue in kind-projector:
https://github.com/non/kind-projector/issues/84

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] = // ...

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

noti0na1 picture noti0na1  路  3Comments

ohze picture ohze  路  3Comments

liufengyun picture liufengyun  路  3Comments

dwijnand picture dwijnand  路  3Comments

NightMachinary picture NightMachinary  路  3Comments