-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
x as T
shorthand for T(x)::T
?
#57857
Comments
x as T
shorthand for T(x)::T
x as T
shorthand for T(x)::T
?
The only reason for writing this is pretty much solely for the invalidation case and adding syntax just for that feels a bit excessive. |
Yeah, maybe so. I would rather be allowed to restrict the type behavior of generic function, but that's going to be a breaking change. Not the feature, but using it on widely used functions like conversion and constructors. |
I'll note that the only real reason this is a problem is that assignment returns the rhs of an expression, which is (IMO) really confusing and unfortunate. Fixing that (I know it'd require 2.0) would also fix some other stuff like letting us do things like Personally, I'd rather see the return value of assignment fixed than add an Maybe a compromise could be to have a |
I guess a "simple" solution would be something like Although I would probably prefer Either of these can be done simply enough user-side, without any changes to |
It's become fairly common for people to write code like this:
This is kind of verbose and redundant. I had always hoped that we might add type signatures for generic function such that the
::Int
part is implied by the signature ofInt(...)
but that seems unlikely in the Julia 1.x timeframe. Perhaps a more pragmatic solution would be to have syntax sugar for the "convert and assert" pattern. We could haveOf course, in this case, I think you could just as well write
n::Int = length(items)
but that's not always doable.The text was updated successfully, but these errors were encountered: