-
Notifications
You must be signed in to change notification settings - Fork 363
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
Nested (non-capturing) type aliases #405
base: master
Are you sure you want to change the base?
Conversation
|
||
```kotlin | ||
class Dijkstra { | ||
typelias VisitedNodes = Set<Node> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typelias VisitedNodes = Set<Node> | |
typealias VisitedNodes = Set<Node> |
typo
// = capture(Inner<Int>, capture(Example<S>, { T })) | ||
// = capture(Inner<Int>, { S }) | ||
// = capture(Int) + { S } = { S } ⊆ { S } => OK | ||
typelias Boo<S> = Example<S>.Inner |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typelias Boo<S> = Example<S>.Inner | |
typealias Boo<S> = Example<S>.Inner |
same here
// capture(Inner<Int>, { T }) | ||
// = capture(Int) + { T } | ||
// = { T } ⊈ { T } => not allowed | ||
typealias Moo = Inner<Int> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// capture(Inner<Int>, { T }) | |
// = capture(Int) + { T } | |
// = { T } ⊈ { T } => not allowed | |
typealias Moo = Inner<Int> | |
// capture(Inner<Int>, { T }) | |
// = capture(Int, { T }) + { T } | |
// = { T } ⊈ { } => not allowed | |
typealias Moo = Inner<Int> |
capture
has two "parameters", Moo
has no type parameters
> [!TIP] | ||
> As a rule of thumb, a nested type alias is correct if it could be used as the supertype or a parameter type within a nested class living within the same classifier. | ||
|
||
We formally define the set of captured type parameters of a type `T` with enclosing parameters `P`, `captured(T, P)`, as follows. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We formally define the set of captured type parameters of a type `T` with enclosing parameters `P`, `captured(T, P)`, as follows. | |
We formally define the set of captured type parameters of a type `T` with enclosing parameters `P`, `capture(T, P)`, as follows. |
typo
// capture(Example<S>.Inner<Int>, { T }) | ||
// = capture(Inner<Int>, capture(Example<S>, { T })) | ||
// = capture(Inner<Int>, { S }) | ||
// = capture(Int) + { S } = { S } ⊆ { S } => OK | ||
typelias Boo<S> = Example<S>.Inner |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// capture(Example<S>.Inner<Int>, { T }) | |
// = capture(Inner<Int>, capture(Example<S>, { T })) | |
// = capture(Inner<Int>, { S }) | |
// = capture(Int) + { S } = { S } ⊆ { S } => OK | |
typelias Boo<S> = Example<S>.Inner | |
// capture(Example<S>.Inner<Int>, { T }) | |
// = capture(Inner<Int>, capture(Example<S>, { T })) | |
// = capture(Inner<Int>, { S }) | |
// = capture(Int, { S }) + { S } = { S } ⊆ { S } => OK | |
typelias Boo<S> = Example<S>.Inner<Int> |
capture
has two "parameters", Inner
has a type parameter
// correctUsage.kt | ||
import A.* // imports `I` | ||
import C.* // imports `D` | ||
|
||
val d = A().D() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems like this is missing the usage of I
:
val i = A().I()
Only comment here about the text itself. The discussion about the feature is done in #406.
Right now type aliases can only be used at the top level. The goal of this document is to propose a design to allow them within other classifiers, in case they do not capture any type parameters of the enclosing declaration.