Skip to content

Phase consistency involving higher-kinded types #5962

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

Closed
liufengyun opened this issue Feb 21, 2019 · 4 comments
Closed

Phase consistency involving higher-kinded types #5962

liufengyun opened this issue Feb 21, 2019 · 4 comments
Assignees

Comments

@liufengyun
Copy link
Contributor

When a higher-kinded type S is used in quote/splice, do we need an evidence of Type[S] or Type[S[X]]? Neither type checks.

import scala.quoted._
import scala.tasty._

class MatchFactory1[T, S[_]]

object MatcherFactory1 {
  def impl[T: Type, S[_]](self: Expr[MatchFactory1[T, S]])(implicit refl: Reflection, tpS: Type[S[T]]) =
    '{ ~self }
}
@liufengyun
Copy link
Contributor Author

Related: phase consistency for path-dependent types #5961 (comment)

@nicolasstucki
Copy link
Contributor

You can encode the missing type tag with M >: MatchFactory1[T, S] <: MatchFactory1[T, S] : Type

import scala.quoted._
import scala.tasty._

class MatchFactory1[T, S[_]] {
  def f: Int = 2
}

object MatcherFactory1 {

  def impl[T: Type, S[_], M >: MatchFactory1[T, S] <: MatchFactory1[T, S] : Type](self: Expr[M])(implicit refl: Reflection, tpS: Type[S[T]]) =
    '{ val a = ~self; a.f }

}

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 21, 2019
@liufengyun
Copy link
Contributor Author

@nicolasstucki The encoding does not compile when there is inner class, type projection only allowed on non-concrete types under Scala2 mode:

import scala.quoted._
import scala.tasty._

class MatchFactory1[T, S[_]] { outer =>
  class Inner {
    val owner = outer
  }
}

object MatcherFactory1 {

  def impl[T: Type, S[_], M >: MatchFactory1[T, S] <: MatchFactory1[T, S] : Type](self: Expr[M#Inner])(implicit refl: Reflection, tpS: Type[S[T]]): Expr[M] =
    '{ (~self).owner }

}

We could move #Inner to the bounds as well, but it becomes a little verbose.

@liufengyun
Copy link
Contributor Author

@odersky Mentioned we could change the parameter of Type to poly-kinded:

sealed abstract class Type[T <: AnyKind] {
  type unary_~ = T
}

class Test {
  def foo(ev: Type[List]): Int = ???
}

However, this requires enable the flag -Ykind-polymorphism.

@nicolasstucki nicolasstucki self-assigned this Feb 25, 2019
nicolasstucki added a commit that referenced this issue Mar 4, 2019
@liufengyun liufengyun mentioned this issue Mar 19, 2019
66 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants