|
1 | 1 | ---
|
2 | 2 | layout: doc-page
|
3 |
| -title: "Dropped: General Type Projection" |
4 |
| -nightlyOf: https://docs.scala-lang.org/scala3/reference/dropped-features/type-projection.html |
| 3 | +title: "Tightened Type Projection" |
| 4 | +nightlyOf: https://docs.scala-lang.org/scala3/reference/changed-features/type-projection.html |
5 | 5 | ---
|
6 | 6 |
|
7 |
| -Scala so far allowed general type projection `T#A` where `T` is an arbitrary type |
8 |
| -and `A` names a type member of `T`. |
| 7 | +Scala 2 allowed general type projection `T#A` where `T` is an arbitrary type and `A` names a type member of `T`. |
| 8 | +This turns out to be [unsound](https://github.com/scala/scala3/issues/1050) (at least when combined with other Scala 3 features). |
9 | 9 |
|
10 |
| -Scala 3 disallows this if `T` is an abstract type (class types and type aliases |
11 |
| -are fine). This change was made because unrestricted type projection |
12 |
| -is [unsound](https://github.com/scala/scala3/issues/1050). |
13 |
| - |
14 |
| -This restriction rules out the [type-level encoding of a combinator |
15 |
| -calculus](https://michid.wordpress.com/2010/01/29/scala-type-level-encoding-of-the-ski-calculus/). |
| 10 | +To remedy this, Scala 3 only allows type projection if `T` is a concrete type (any type which is not abstract), an example for such a type would be a class type (`class T`). |
| 11 | +A type is abstract if it is: |
| 12 | +* An abstract type member (`type T` without `= SomeType`) |
| 13 | +* A type parameter (`[T]`) |
| 14 | +* An alias to an abstract type (`type T = SomeAbstactType`). |
| 15 | +There are no restriction on `A` appart from the fact it has to be a member type of `T`, for example a subclass (`class T { class A }`). |
16 | 16 |
|
17 | 17 | To rewrite code using type projections on abstract types, consider using
|
18 | 18 | path-dependent types or implicit parameters.
|
| 19 | + |
| 20 | +This restriction rules out the [type-level encoding of a combinator |
| 21 | +calculus](https://michid.wordpress.com/2010/01/29/scala-type-level-encoding-of-the-ski-calculus/). |
0 commit comments