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

RFC: Default type alias type parameters #61

Merged

Conversation

vegorov-rbx
Copy link
Collaborator

No description provided.

@vegorov-rbx vegorov-rbx added the rfc Language change proposal label Aug 6, 2021
@vegorov-rbx vegorov-rbx marked this pull request as ready for review August 6, 2021 18:12
@alexmccord
Copy link
Contributor

Interaction with default type arguments and variadic type parameters seems to be missing in this RFC.

Are we going to support that, or leave it out?
Should the syntax look like type F<R... = (string, number)> = () -> R...?

@vegorov-rbx
Copy link
Collaborator Author

Interaction with default type arguments and variadic type parameters seems to be missing in this RFC.

It's not left out, it's explicitly prohibited: Default type arguments are not allowed for type pack parameters.

@alexmccord
Copy link
Contributor

Ah, got it. What's the rationale for leaving it out to start with? Keeping the scope smaller on a as-needed basis?

@vegorov-rbx
Copy link
Collaborator Author

The reasoning behind the decision is that while we parse type<R...> right now, it's impossible to reference R on the right-hand-side.

I had this text in an unpublished draft:

Default type arguments are allowed for generic type pack parameters:

type A<T, U... = ...string> -- ok, variadic type pack
type B<T, U... = (number, number)> -- ok, type pack of two types
type B<T..., U... = T> -- ok
type A<T, U... = string> -- ok, variadic type pack of one type

@vegorov-rbx
Copy link
Collaborator Author

Since the only reason is a missing related feature, maybe I should bring default type pack values back and we'll fix that issue during implementation of this RFC (if it's accepted).

Copy link

@matthargett matthargett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see progress on this!

* improved motivation for the feature and noted additional languages with this feature
* fixed terminology between 'argument' and 'parameter'
* brought back support for default type pack parameter values
* removed alternative syntax and described the decision between ':' and '=' in the design section
* fixed drawback text and provided an example
@vegorov-rbx
Copy link
Collaborator Author

@alexmccord I've updated the RFC to include default values for type packs.

@vegorov-rbx vegorov-rbx merged commit 10a4072 into luau-lang:master Aug 20, 2021
@andyfriesen
Copy link
Collaborator

-- ambiguity, Type could mean Type<number, string> or Type<A, B>
type Type<A = number, B = string> = { x: number, b: Type? }

I don't like the idea that this could ever mean Type<A, B>. It might be mildly convenient shorthand, but I think it's much more valuable to be able to see Type? and know that it always means Type<number, string> no matter where in the source code you happen to see it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rfc Language change proposal
Development

Successfully merging this pull request may close these issues.

6 participants