question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Change wildcards from `_` to `?` ?

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:68
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

6reactions
smartercommented, Feb 28, 2017

However, there is one thing which I think is worth trying to fix: preventing people from writing foo[M[_] <: List[_]] when they meant foo[M[X] <: List[X]], I opened an issue for that some times ago: https://github.com/lampepfl/dotty/issues/1809

3reactions
oderskycommented, Mar 1, 2017

If we had ? under an -Xfuture flag we could deprecate _ and rewrite in the first version of dotty, which would speed up the conversion.

The same holds for with --> &. If we could get & under -Xfuture we could deprecate and rewrite immediately in dotty.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Find and Replace in Word (and Use Wildcards)
Position the cursor at the location in the document where you want to start finding and replacing. · Click the Home tab in...
Read more >
Finding and replacing characters using wildcards
To begin, you must first turn Wildcards on in the Find/Replace dialog. To do so, bring up the Find dialog, click More and...
Read more >
How to Use Wildcards in Word - CustomGuide
1. Click the Find list arrow. 2. Select Advanced Find. 3. Click the More button.
Read more >
Replace using wildcards - Graham Mayor
Wildcard searches are case sensitive. ... Start by identifying the string you wish to replace and then pop up the replace function (CTRL+H)...
Read more >
How to use Wildcards to do Advanced Find and Replace in ...
Using Wildcards to Find and Replace in Microsoft Word · Choose the wildcard character · Type additional text in the Find box ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found