Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

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

Closed
Baccata opened this issue Nov 19, 2022 · 2 comments

Comments

@Baccata
Copy link

Baccata commented Nov 19, 2022

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]]] = ???

}
@Baccata Baccata added the stat:needs triage Every issue needs to have an "area" and "itype" label label Nov 19, 2022
@smarter
Copy link
Member

smarter commented Nov 19, 2022

Moving this to feature request since we make no guarantees about -Ykind-projector, but contributions to reach parity with the scala 2 plugin are welcome!

@smarter smarter transferred this issue from scala/scala3 Nov 19, 2022
@smarter
Copy link
Member

smarter commented Nov 19, 2022

The relevant PRs are #7775 and #12378, see also #5379

@smarter smarter removed the stat:needs triage Every issue needs to have an "area" and "itype" label label Nov 19, 2022
@ckipp01 ckipp01 transferred this issue from lampepfl/dotty-feature-requests May 31, 2023
@scala scala locked and limited conversation to collaborators May 31, 2023
@ckipp01 ckipp01 converted this issue into discussion #17673 May 31, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants