Skip to content
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 #406

Open
serras opened this issue Dec 20, 2024 · 2 comments
Open

Nested (non-capturing) type aliases #406

serras opened this issue Dec 20, 2024 · 2 comments

Comments

@serras
Copy link
Contributor

serras commented Dec 20, 2024

This is an issue to discuss nested (non-capturing) type aliases. The current full text of the proposal can be found here.

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.

@revonateB0T
Copy link

revonateB0T commented Dec 21, 2024

I personally think this proposal is trivial and nothing to discuss(in design)(I support it, certainly).
Btw, sorry for the off-topic, @serras now that you mentioned them and you are in Jetbrains Kotlin team,

Going even further than capture, it is a non-goal of this KEEP to provide abstraction capabilities over type aliases, like abstract type members in Scala or associated type synonyms in Haskell. Roughly speaking, this would entail declaring a type alias without its right-hand side in an interface or abstract class, and "overriding" it in an implementing class.

interface Collection {
   typealias Element
}

interface List<T>: Collection {
   typealias Element = T
}

interface IntArray: Collection {
   typealias Element = Int
}

Will kotlin support these language features(i.e. capturing type alias, abstract type members, associated type synonyms, or let's say further, dependent functions) in future?

@serras
Copy link
Contributor Author

serras commented Dec 23, 2024

Will kotlin support these language features?

I cannot say for sure, although I highly doubt that anything resembling type-level computation would make it into the language. The only exception is many capturing type aliases (you can even see that the first iterations of the proposal in the Git history had those), but there are interesting questions like how would instantiation work for things like:

class Example<T> {
  inner typealias A = List<T>
}

Should one require an instance of A to call the List constructor? How does it relate to things like listOf? Because of those questions we've decided to go first with the obviously useful feature (non-capturing type aliases) and then move to capturing type aliases if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@serras @revonateB0T and others