# Deaing with the removal of type projections

**URL:** <https://users.scala-lang.org/t/deaing-with-the-removal-of-type-projections/1495>\
**Category:** Question\
**Created:** [August 3, 2017, 9:32am UTC](https://users.scala-lang.org/t/deaing-with-the-removal-of-type-projections/1495 "2017-08-03T09:32:25Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![hmf](https://users.scala-lang.org/user_avatar/users.scala-lang.org/hmf/32/426_2.png) [@hmf](https://users.scala-lang.org/u/hmf)\
**Post date:** [August 3, 2017, 9:32am UTC](https://users.scala-lang.org/t/deaing-with-the-removal-of-type-projections/1495/1 "2017-08-03T09:32:25Z")

</div>

Hello,

While looking at the Scala days presentation videos, someone mentioned that in the future generic type projections will be removed (seems inference is not complete/sound). In a code base I am working on I have something like this:

```
  trait Base {
    type A
    type B
 }

  class ExtBase(a: ExtBase#A, b: ExtBase#B) extends Base {
    type A = Int
    type B = Double
  }

```

The idea is that in `ExtBase` I only change types `A` and `B` if/when needed and follow the compilation errors to correct the code. So I have two questions:

1. Is what I am doing incorrect, ill advised or simply not idiomatic Scala
2. When projection are removed how can one refer to the types `A` and `B` in the parameters (aside from simply using the types directly)?

TIA,

---

<div class="post-metadata">

**Author:** ![Jasper-M](https://users.scala-lang.org/user_avatar/users.scala-lang.org/jasper-m/32/872_2.png) [@Jasper-M](https://users.scala-lang.org/u/Jasper-M)\
**Post date:** [August 3, 2017, 12:58pm UTC](https://users.scala-lang.org/t/deaing-with-the-removal-of-type-projections/1495/2 "2017-08-03T12:58:27Z")

</div>

I don’t think that what you are doing will become impossible. Only projections on type parameters or abstract types will be removed. For instance a type projection like this will no longer be possible, because `X` is a type parameter:

```auto
trait A { type B }
class Foo[X <: A](b: X#B)

```

However your code currently doesn’t compile with dotty, but I think that’s a [bug](https://github.com/lampepfl/dotty/issues/2949), and not the intended behavior.

---

<div class="post-metadata">

**Author:** ![casper](https://users.scala-lang.org/user_avatar/users.scala-lang.org/casper/32/94_2.png) [@casper](https://users.scala-lang.org/u/casper)\
**Post date:** [August 3, 2017, 1:15pm UTC](https://users.scala-lang.org/t/deaing-with-the-removal-of-type-projections/1495/3 "2017-08-03T13:15:48Z")

</div>

I have huge consideration towards the same problem.

The first usage that comes to mind is type lambdas, but they would become redundant after adopting the feature directly in the dotty.

Other usage that currently I have a little clues how to transcribe to dotty is TList (type-level list of types). Example of how it is defined:

```auto
sealed trait TListI[Self <: TListI[Self]] { this : Self =>
  type Merge[X <: TList] <: TList
}
sealed trait TListN extends TListI[TListN] {
  override type Merge[X <: TList] = X
}
sealed trait TListC[H, T <: TList] extends TListI[TListC[H,T]] {
  override type Merge[X <: TList] = TListC[H, T#Merge[X]]
}

type TNil = TListN
type TList = X forSome {type X <: TListI[X]}
type |[H, T <: TList] = TListC[H, T]
type ||[L <: TList, R <: TList] = L#Merge[R]

```

Here type projection is essential for type level computation. And we have zero objects to depend on and dotty is focused on dependent objects (as I conclude from the name) not on types which has no representing objects.

---

<div class="post-metadata">

**Author:** ![Jasper-M](https://users.scala-lang.org/user_avatar/users.scala-lang.org/jasper-m/32/872_2.png) [@Jasper-M](https://users.scala-lang.org/u/Jasper-M)\
**Post date:** [August 3, 2017, 1:39pm UTC](https://users.scala-lang.org/t/deaing-with-the-removal-of-type-projections/1495/4 "2017-08-03T13:39:15Z")

</div>

I suspect you’ll have to encode them with implicits instead. Since there are no runtime objects you might be able to do it with [phantom types](https://github.com/lampepfl/dotty/issues/2040); that will probably erase all the runtime overhead that you might otherwise get with implicits.

---

<div class="post-metadata">

**Author:** ![hmf](https://users.scala-lang.org/user_avatar/users.scala-lang.org/hmf/32/426_2.png) [@hmf](https://users.scala-lang.org/u/hmf)\
**Post date:** [August 4, 2017, 8:27am UTC](https://users.scala-lang.org/t/deaing-with-the-removal-of-type-projections/1495/5 "2017-08-04T08:27:50Z")

</div>

Thanks @Jasper-M for the feedback. I will stick to this assuming compilation failure is due to a bug.

---

<div class="post-metadata">

**Author:** ![Jasper-M](https://users.scala-lang.org/user_avatar/users.scala-lang.org/jasper-m/32/872_2.png) [@Jasper-M](https://users.scala-lang.org/u/Jasper-M)\
**Post date:** [August 8, 2017, 3:33pm UTC](https://users.scala-lang.org/t/deaing-with-the-removal-of-type-projections/1495/6 "2017-08-08T15:33:12Z")

</div>

It should be fixed now: [https://github.com/lampepfl/dotty/pull/2963](https://github.com/lampepfl/dotty/pull/2963)

---

<div class="post-metadata">

**Author:** ![casper](https://users.scala-lang.org/user_avatar/users.scala-lang.org/casper/32/94_2.png) [@casper](https://users.scala-lang.org/u/casper)\
**Post date:** [August 8, 2017, 11:30pm UTC](https://users.scala-lang.org/t/deaing-with-the-removal-of-type-projections/1495/7 "2017-08-08T23:30:20Z")

</div>

> I suspect you’ll have to encode them with implicits instead.

I could encode anything with implicits. I could reimplement OOP in pure implicits. But it is makes me develop certain language features that should be already presented in core.

Implicits are always cumbersome and takes more code to express than normal type-level solutions. And they lead to pretty cryptic error messages. And implicits works counter-intuitive sometimes due to lack of backtrack feature, require from programmer to understand clearly order of expansion. I personally not a very good programmer, so I forced to supply every implicit code with tests to check if they would expand as I imagined.

Implicits propagate through your code like plague. I’d like to avoid them as much as I can.

Finally I’m not sure if implicits would not introduce larger problems than type projections. If some feature is non-secure in core, there are chances that manual encoding would give the same or larger problems, which would be only hidden deeper inside your custom code which had never be verified formally.

---

<div class="post-metadata">

**Author:** ![hmf](https://users.scala-lang.org/user_avatar/users.scala-lang.org/hmf/32/426_2.png) [@hmf](https://users.scala-lang.org/u/hmf)\
**Post date:** [August 9, 2017, 8:43am UTC](https://users.scala-lang.org/t/deaing-with-the-removal-of-type-projections/1495/8 "2017-08-09T08:43:38Z")

</div>

Already seen the the pull request (had subscribed to the issue). Thanks.

---

<div class="post-metadata">

**Author:** ![Jasper-M](https://users.scala-lang.org/user_avatar/users.scala-lang.org/jasper-m/32/872_2.png) [@Jasper-M](https://users.scala-lang.org/u/Jasper-M)\
**Post date:** [August 9, 2017, 8:51am UTC](https://users.scala-lang.org/t/deaing-with-the-removal-of-type-projections/1495/9 "2017-08-09T08:51:43Z")

</div>

Well I think that if you want to get any good use out of your typelevel list, beyond the most basic usecase of checking that one tlist is exactly equal to another tlist, you would need implicits anyway.

---

<div class="post-metadata">

**Author:** ![casper](https://users.scala-lang.org/user_avatar/users.scala-lang.org/casper/32/94_2.png) [@casper](https://users.scala-lang.org/u/casper)\
**Post date:** [August 9, 2017, 2:16pm UTC](https://users.scala-lang.org/t/deaing-with-the-removal-of-type-projections/1495/10 "2017-08-09T14:16:20Z")

</div>

Checking if some type belongs to a TList, if a TList is completely in super/sub type realtion to the type, if one Tlist is a sublist of another Tlist could be easily implemented with type level computations. I doubt if there is need for more complex stuff.

---

<div class="post-metadata">

**Author:** ![Jasper-M](https://users.scala-lang.org/user_avatar/users.scala-lang.org/jasper-m/32/872_2.png) [@Jasper-M](https://users.scala-lang.org/u/Jasper-M)\
**Post date:** [August 9, 2017, 2:49pm UTC](https://users.scala-lang.org/t/deaing-with-the-removal-of-type-projections/1495/11 "2017-08-09T14:49:08Z")

</div>

I would be genuinely interested to see how you would do all that without implicits.

For instance:

```auto
trait Foo[Flags <: TList]
def onlyForInt[Flags <: TList](foo: Foo[Flags]) = ???

```

How do you ensure (by adapting the method signature of `onlyForInt` or the implementation of `TList`) that `onlyForInt` can only be called if `Flags` contains `Int`?

Anyway, I’m just the messenger here 🙂 Abstract type projections seem to be unsound, so in Dotty the (probably only) alternative will be implicits.

---

<div class="post-metadata">

**Author:** ![Harika](https://users.scala-lang.org/letter_avatar_proxy/v4/letter/h/45deac/32.png) [@Harika](https://users.scala-lang.org/u/Harika)\
**Post date:** [August 9, 2017, 3:29pm UTC](https://users.scala-lang.org/t/deaing-with-the-removal-of-type-projections/1495/12 "2017-08-09T15:29:54Z")

</div>

Here is my problem:  
I have main method in it written a method1.  
From other main method i am trying to call method1.  
They were in objects.  
In both objects i am using spark context.  
Its throwing error for multiple spark context.  
How could i resolve this?  
I tried using “multiple spark context set true”
