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

proposal: type casts and type inference syntax #9

Open
weiwenhao opened this issue May 14, 2023 · 1 comment
Open

proposal: type casts and type inference syntax #9

weiwenhao opened this issue May 14, 2023 · 1 comment
Labels

Comments

@weiwenhao
Copy link
Member

weiwenhao commented May 14, 2023

Due to the existence of the any type, type inference is necessary. However, the method similar to golang any.(Type) requires one small symbol, one large symbol, and two parentheses, which can be cumbersome. Therefore, I would like to refer to the as method in Rust and TypeScript.

Type casting

var foo = 1
var bar =  foo as bool  // bar type is bool 

Type assertion

any foo = 1
var bar = any is int // bar type is int 

One point that is quite tangled is whether the "is" syntax is necessary, or whether to use the "as" syntax uniformly, both for type assertions and type conversions. 🤔

@weiwenhao weiwenhao changed the title About casts and type inference syntax proposal: type casts and type inference syntax May 16, 2023
@weiwenhao
Copy link
Member Author

'is' syntax will be used for type checking, bool b = foo is int, checking if foo is of type int, and returning a bool type.

'as' will be used for both type assertion and type casting.

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

No branches or pull requests

1 participant