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
can type inference be made to work for f-bounded type params? #4745
Comments
Imported From: https://issues.scala-lang.org/browse/SI-4745?orig=1 |
@paulp said: object +: {
import collection.LinearSeqLike
def unapply[T, Coll <: LinearSeqLike[T, Coll]](t : Coll with LinearSeqLike[T, Coll]) : Option[(T, Coll)] = {
if (t.isEmpty) None
else Some(t.head -> t.tail) // TODO - Try to remove cast.
}
} A more pasteable version. |
@retronym said (edited on Mar 30, 2013 10:18:12 PM UTC): qbin/scala -classpath /Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/jfxrt.jar
Welcome to Scala version 2.11.0-20130330-204812-2a6e83a85e (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_37).
scala> type CircleBuilderF = ({type CB <: CircleBuilder[CB]; type CB1 = CB with CircleBuilder[CB]})#CB1
defined type alias CircleBuilderF
scala> def newCircleBuilder: CircleBuilderF = CircleBuilder.create.asInstanceOf[CircleBuilderF]
newCircleBuilder: CircleBuilderF
scala> newCircleBuilder.centerX(0).centerX(0).build()
res28: javafx.scene.shape.Circle = Circle@38b9a306 Compare with: scala> CircleBuilder.create.centerX(0).centerX(0).build()
<console>:14: error: value centerX is not a member of ?0
CircleBuilder.create.centerX(0).centerX(0).build()
^ I was unable to a come up shorthand to express scala> trait FBounded[M[_]] { type F <: M[F]; type Apply = F with M[F] }
warning: there were 1 feature warning(s); re-run with -feature for details
defined trait FBounded
scala> CircleBuilder.create.asInstanceOf[FBounded[CircleBuilder]#Apply].centerX(0).centerX(0).build()
<console>:15: error: kinds of the type arguments (javafx.scene.shape.CircleBuilder) do not conform to the expected kinds of the type parameters (type M) in trait FBounded.
javafx.scene.shape.CircleBuilder's type parameters do not match type M's expected parameters:
type B's bounds <: javafx.scene.shape.CircleBuilder[B] are stricter than type _'s declared bounds >: Nothing <: Any
CircleBuilder.create.asInstanceOf[FBounded[CircleBuilder]#Apply].centerX(0).centerX(0).build()
|
@retronym said (edited on Mar 31, 2013 10:38:38 AM UTC): scala> implicit class RichFBoundBuilder[B[X <: B[X]]](val _builder: B[_]) {
type B1 = X forSome { type X <: B[X] }
def asScala: B1 = _builder.asInstanceOf[B1]
}
warning: there were 2 feature warning(s); re-run with -feature for details
defined class RichFBoundBuilder
scala> import javafx.scene.shape._
import javafx.scene.shape._
scala> CircleBuilder.create.asScala.centerX(0).centerX(0).build()
res0: javafx.scene.shape.Circle = Circle@6c60efe7 |
Someone should add the "fixed in dotty" label for this issue |
works fine, but if we remove the seemingly redundant second constituent in
t : Coll with LinearSeqLike[T, Coll]
, type inference fails, because Coll is f-bounded (?)can we generalise this pattern to make type inference work for f-bounds?
The text was updated successfully, but these errors were encountered: