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

Add option to use underscore symbol _ instead of * to define anonymous type lambdas #188

Merged
merged 5 commits into from
May 15, 2021

Commits on May 7, 2021

  1. Add option to use underscore symbol _ instead of * to define anon…

    …ymous type lambdas
    
    The syntax roughly follows the [proposed new syntax for wildcards and placeholders](https://dotty.epfl.ch/docs/reference/changed-features/wildcards.html#migration-strategy) for Scala 3.2+ and is designed to allow cross-compilation of libraries between Scala 2 and Scala 3 while using the new Scala 3 syntax for both versions.
    
    To enable this mode, add `-P:kind-projector:underscore-placeholders` to your scalac command-line. In sbt you may do this as follows:
    
    ```scala
    ThisBuild / scalacOptions += "-P:kind-projector:underscore-placeholders"
    ```
    
    This mode is designed to be used with scalac versions `2.12.14`+ and `2.13.6`+, these versions add an the ability to use `?` as the existential type wildcard ([scala/scala#9560](scala/scala#9560)), allowing to repurpose the underscore without losing the ability to write existential types. It is not advised that you use this mode with older versions of scalac or without `-Xsource:3` flag, since you will lose the underscore syntax entirely.
    
    Here are a few examples:
    
    ```scala
    Tuple2[_, Double]        // equivalent to: type R[A] = Tuple2[A, Double]
    Either[Int, +_]          // equivalent to: type R[+A] = Either[Int, A]
    Function2[-_, Long, +_]  // equivalent to: type R[-A, +B] = Function2[A, Long, B]
    EitherT[_[_], Int, _]    // equivalent to: type R[F[_], B] = EitherT[F, Int, B]
    ```
    
    Examples with `-Xsource:3`'s `?`-wildcard:
    
    ```scala
    Tuple2[_, ?]        // equivalent to: type R[A] = Tuple2[A, x] forSome { type x }
    Either[?, +_]          // equivalent to: type R[+A] = Either[x, A] forSome { type x }
    Function2[-_, ?, +_]  // equivalent to: type R[-A, +B] = Function2[A, x, B] forSome { type x }
    EitherT[_[_], ?, _]    // equivalent to: type R[F[_], B] = EitherT[F, x, B] forSome { type x }
    ```
    neko-kai committed May 7, 2021
    Configuration menu
    Copy the full SHA
    adbd336 View commit details
    Browse the repository at this point in the history

Commits on May 10, 2021

  1. Configuration menu
    Copy the full SHA
    02ab0b5 View commit details
    Browse the repository at this point in the history

Commits on May 14, 2021

  1. Configuration menu
    Copy the full SHA
    1556638 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    16dedbd View commit details
    Browse the repository at this point in the history

Commits on May 15, 2021

  1. Configuration menu
    Copy the full SHA
    7e78552 View commit details
    Browse the repository at this point in the history