Skip to content

Missing Ykind-projector usecase that prevent cross-compilation with Scala 2 : higher-kind-parameterised type-lambdas #17672

Closed
@Baccata

Description

@Baccata

The documentation of kind-projector provides valuable information as to what is and what isn't possible to cross-compile. This is greatly appreciated, however, here's a usecase that doesn't seem to have a non-projection-based way of cross-compilng with Scala 2.

Compiler version

3.2.1

Minimized example

The problem can be described as a formulation a type lambda that depends on a method bound and that expresses partial application where of a parametric type, where the free type variable is higher-kinded.

We're trying to express when its F paramerter is fixed, PolyFunction forms a FunctorK

Scala 3 :

//> using option "-Ykind-projector"

object Test {
  trait PolyFunction[F[_], G[_]]
  trait FunctorK[Alg[_[_]]]

  def polyFunctionFunctorK[F[_]] : FunctorK[[G[_]] =>> PolyFunction[F, G]] = ???
}

Scala 2 (using the kind-projector compiler plugin)

//> using plugin "org.typelevel:::kind-projector:0.13.2"
//> using scala "2.13.10"

object Test {

  trait PolyFunction[F[_], G[_]]
  trait FunctorK[Alg[_[_]]]

  def polyFunctionFunctorK[F[_]] : FunctorK[PolyFunction[F, *[_]]] = ???

}

The only way I'm aware of cross-compiling this is to resort to the de-sugared Scala 2 encoding :

Desugared encoding, which compiles on both Scala 2 and Scala 3

object Test {

  trait PolyFunction[F[_], G[_]]
  object PolyFunction {
    type Curried[F[_]] = {
      type λ[G[_]] = PolyFunction[F, G]
    }
  }


  trait FunctorK[Alg[_[_]]]

  def polyFunctionFunctorK[F[_]] : FunctorK[PolyFunction.Curried[F]#λ] = ???
}

Expectation

I'd personally appreciate if the support for λ in Scala 3 was not limited to *-kinded type parameters, and if we could write the following, which compiles in Scala 2 using kind-projector.

object Test {

  trait PolyFunction[F[_], G[_]]
  trait FunctorK[Alg[_[_]]]

  def polyFunctionFunctorK[F[_]] : FunctorK[λ[G[_] => PolyFunction[F, G]]] = ???

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions