-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
function return type special-syntax #6551
Comments
This needs more detail, but my understanding is that this essentially provides return-type overloading by caller request? So I could define
And these definitions will be somewhere in Did I get that right? |
i've left some of the implementation details for discussion. but I didn't initially intend to allow return-type overloading. the user has the option of dispatching to another function to add in that overloading, but this point would need more discussion first
|
I actually think the typeassert form of return type declaration is almost useless compared to the |
That depends on if you prefer to have the compiler complain at you or just do what you want. We tend to prefer the latter around these parts, but there are languages where that's not the preference. |
That's a fair point; if the declarations are just checks then you'd prefer those checks to be done as early as possible. |
I would vote for the convert behavior. The assertion would be handy while debugging performance issues but in "production code" one would (as Jeff said) have try/catch blocks around function calls that use return type annotations. |
agreed, I'm much more excited about having clean syntax for return-type declaration and conversion than typeassert. just thought it would be worth mentioning the possibility of future design work |
I think we will just do #1090. |
proposal:
f() :> A
declares that the result off()
must be object of typeA
(but usingconvert
, nottypeassert
)usage:
backward-compatible & default implementation:
f() :> A
callsconvert(A, f())
optional additional syntax
makes RT an optional 'hidden' parameter to the function, and allows the function to provide an optimized version using that information:
final comments
:>
operator is currently an unused, reserved keyword in the parserThe text was updated successfully, but these errors were encountered: