-
Notifications
You must be signed in to change notification settings - Fork 21
Ignoring a type constructor requires rocket science #8039
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
Comments
Imported From: https://issues.scala-lang.org/browse/SI-8039?orig=1 |
@adriaanm said: scala> trait Foo[CC[+X], +A]
warning: there were 1 feature warning(s); re-run with -feature for details
defined trait Foo
scala> trait FooChill { type CC[+X]; type A; type Apply = Foo[CC, A] }
warning: there were 1 feature warning(s); re-run with -feature for details
defined trait FooChill
scala> def x: (FooChill{type A = Int})#Apply = ???
x: Foo[_1.CC,Int] forSome { val _1: FooChill{type A = Int} }
|
@adriaanm said: scala> def x[B]: (FooChill{type A = B})#Apply = ???
x: [B]=> Foo[_3.CC,B] forSome { val _3: FooChill{type A = B} }
|
@paulp said: |
@adriaanm said: |
@retronym said: |
@paulp said: Not to mention it's disingenuous to suggest one is ever likely to have such freedom that one can hop between type members and type parameters. There are a billion things which constrain this choice - most of them are implementation bugs or inadequacies by design - never once will anyone be so free of those constraints that they'll be able to say "I'll make this a type member because I expect it to be partial once in a while." |
@paulp said: |
@adriaanm said: |
@paulp said: Hey wait a minute, "outstanding tickets" could mean "excellent tickets" or it could mean "the tickets which aren't closed yet." I'm going to infer the first meaning, no need for corrections. |
Alexander Abdugafarov (frozenspider) said: |
Any chance this will be fixed for Scala 2 or possibly Scala 3? |
Scala 2, doubtful. Scala 3, https://dotty.epfl.ch/docs/reference/other-new-features/kind-polymorphism.html |
Not sure if
|
even more fixed-in-Dotty than I realized, then! |
I tried to make that work with my own code but without much luck. This is ideally what I want: sealed trait Expr[F[_], V, R, P] {
def visit[G[_]](v: Expr.Visitor[F, V, P, G]): G[R]
}
object Expr {
trait Visitor[F[_], V, P, G[_]] extends (Expr[F, V, *, P] ~> G) {
override final def apply[R](fa: Expr[F, V, R, P]): G[R] = fa.visit(this)
def visitNode[R](node: Expr.Node[F, V, R, P]): G[R]
// other visit Expr subclass methods...
}
// Expr subclasses....
}
import io.circe.Json
object ConvertExprToJson {
type Out[R] = Json
}
// Is it possible to remove these class type parameters too?
class ConvertExprToJson[F[_], V, P](
encodeSubNodes: Boolean = true
) extends Expr.Visitor[F, V, P, ConvertExprToJson.Out] {
// This signature doesn't compile.
private def encodeSubNode(name: String, subNodes: List[Expr[_, _, _, _]]): Json = {
if (encodeSubNodes) {
val subNodesJson = subNodes.map(_.visit(new ConvertExprToJson[_, _, _, _])).asJson
Json.obj(name -> subNodeJson)
}
else Json.obj()
}
// I currently work around this issue by using G[_] here
private def encodeNode[G[_]](node: Expr[G, _, _, _]): Json = {
Json.obj(
"className" -> node.getClass.getSimpleName.asJson
// encode common Expr fields...
)
}
override def visitNode[R](node: Expr.Node[F, V, R, P]): Json = {
encodeSubNode("subNodes" -> List(expr.subNode))).deepMerge(encodeNode(expr))
}
} |
I think it's pretty reasonable to expect to be able to write a method like this:
If Thing's first type argument is kind *, you can. If it isn't, then god help you. There's no way most people will ever come up with this. The usual surrender probably involves adding an otherwise pointless type parameter to method f. This is not always an option and definitely shouldn't be mandated.
Here are a few things one might try before hitting upon the syntax which actually works.
Colonel Mustard in the conservatory:
The text was updated successfully, but these errors were encountered: