Skip to content

Change wildcards from _ to ? ? #2041

Closed
Closed
@odersky

Description

@odersky

Using the underscore for wildcards in types was unfortunate, because it causes a notational discrepancy for types and for values.

  • For types, C[_] means an existential: ex(T).C[T]
  • For values, c(_) means a universal: x => c(x).

We'd also like to use some notation for projecting types, but _ is already taken. So @non's kind projector uses ? instead. But now things get really confusing.

  • For higher kinded definitions, you write F[_], but for partial applications it's F[?].
  • ? is the same as Java's wildcard, but Java's wildcard means _ in Scala.
  • Function placeholders are written _ for terms but ? for types.

It seems we have everything wrong here and it's no wonder people are confused.

Everything would be so much nicer if we could go back in time and express wildcards with ? instead of _.

  • We could then use _ as a placeholder for type parameters.
  • This would make F[_] and f(_) mean the same thing.
  • It also means that F[_] produces a higher-kinded type at definition sites as well as use sites.
  • The wildcard notation would be aligned with Java

Changing to dotty might give us the one and only chance to actually achieve that.

  • We have a rewrite tool that could automatically rewrite all wildcard occurrences of _ to ?.
  • We could at the same time do the opposite rewrite to _ for kind projector's ?.

It's still a large step, though. So I am on the fence whether we should do it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions