type-projection

What does Dotty offer to replace type projections?

ぐ巨炮叔叔 提交于 2020-01-24 17:52:19
问题 I have been reading about Dotty, since it looks like it is about to become scala 3, and noticed that type projections are deemed "unsound" and removed from the language ... This seems like a bummer, as I have seen several use cases where they were really useful. For example: trait Contents class Foo extends Contents class Bar extends Contents trait Container[T <: Contents] { type ContentType = T } class FooContainer extends Container[Foo] class BarContainer extends Container[Bar] trait

What does Dotty offer to replace type projections?

喜你入骨 提交于 2020-01-24 17:52:05
问题 I have been reading about Dotty, since it looks like it is about to become scala 3, and noticed that type projections are deemed "unsound" and removed from the language ... This seems like a bummer, as I have seen several use cases where they were really useful. For example: trait Contents class Foo extends Contents class Bar extends Contents trait Container[T <: Contents] { type ContentType = T } class FooContainer extends Container[Foo] class BarContainer extends Container[Bar] trait

F-bounded quantification through type member instead of type parameter?

陌路散爱 提交于 2019-12-29 08:55:08
问题 I would like to move a type parameter to a type member. This is the starting point which works: trait Sys[S <: Sys[S]] { type Tx type Id <: Identifier[S#Tx] } trait Identifier[Tx] { def dispose()(implicit tx: Tx): Unit } trait Test[S <: Sys[S]] { def id: S#Id def dispose()(implicit tx: S#Tx) { id.dispose() } } What annoys me is that I'm carrying around a type parameter [S <: Sys[S]] throughout my entire libraries. So what I was thinking is this: trait Sys { type S = this.type // ? type Tx

How do you use Type Projections to p1 and p2 are the same type in p1.assign(p2)

喜你入骨 提交于 2019-12-13 08:31:47
问题 abstract class A { type ThisType <: A def assign(other: ThisType): ThisType } class B extends A { override type ThisType = B override def assign(other: B): B = ??? } The possible places where p1 and p2 maybe declared. In essence they can be declared any where. I guess this would cover most of the usage scenarios: 1a) implicit val p1: /* ??? */ implicit val p2: /* ??? */ implicit val f = { p1, p2 => p1.assign(p2) } val c: => Unit = { p1, p2 => p1.assign(p2) } object R1a { apply(implicit p1: B,

Why do these type arguments not conform to a type refinement?

耗尽温柔 提交于 2019-12-07 15:22:27
问题 Why does this Scala code fail to typecheck? trait T { type A } trait GenFoo[A0, S <: T { type A = A0 }] trait Foo[S <: T] extends GenFoo[S#A, S] I don't understand why "type arguments [S#A,S] do not conform to trait GenFoo's type parameter bounds [A0,S <: T{type A = A0}]". Is there a work-around? Edit : As has been pointed out, the conformance error stems from the failure to verify S <: T{type A = S#A} . Daniel Sobral pointed to -explaintypes , which tells us: S <: T{type A = S#A}? S <: T?

Why do these type arguments not conform to a type refinement?

≡放荡痞女 提交于 2019-12-05 21:34:44
Why does this Scala code fail to typecheck? trait T { type A } trait GenFoo[A0, S <: T { type A = A0 }] trait Foo[S <: T] extends GenFoo[S#A, S] I don't understand why "type arguments [S#A,S] do not conform to trait GenFoo's type parameter bounds [A0,S <: T{type A = A0}]". Is there a work-around? Edit : As has been pointed out, the conformance error stems from the failure to verify S <: T{type A = S#A} . Daniel Sobral pointed to -explaintypes , which tells us: S <: T{type A = S#A}? S <: T? true S specializes type A? this.A = this.A? S = this.type? false false false false I'm not sure how to

investigation of `type` and `#` keywords in scala

走远了吗. 提交于 2019-12-04 08:46:08
问题 Could someone explain how the type keyword and # operator works in scala and how to use it? Please look at examples. //Example1 scala> type t1 = Option.type defined type alias t1 //Shouldn't this work since previous example simply works? scala> type t2 = String.type <console>:7: error: type mismatch; found : String.type required: AnyRef type t2 = String.type ^ //lets define custom trait T scala> trait T defined trait T //... and obtain it's type like in Example1. //Shouldn't this work since

How to infer the right type parameter from a projection type?

孤街醉人 提交于 2019-12-03 17:03:05
问题 I have some troubles having Scala to infer the right type from a type projection. Consider the following: trait Foo { type X } trait Bar extends Foo { type X = String } def baz[F <: Foo](x: F#X): Unit = ??? Then the following compiles fine: val x: Foo#X = ??? baz(x) But the following won't compile: val x: Bar#X = ??? baz(x) Scala sees the "underlying type String" for x , but has lost the information that x is a Bar#X . It works fine if I annotate the type: baz[Bar](x) Is there a way to make