-
Notifications
You must be signed in to change notification settings - Fork 1.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
Should there be a function type? #191
Comments
- [Proposal PR](#162) - [RFC topic](https://forums.carbon-lang.dev/t/rfc-basic-syntax/142) - [Decision request](https://forums.carbon-lang.dev/t/request-for-decision-basic-syntax-162/165) - [Decision announcement](https://forums.carbon-lang.dev/t/accepted-basic-syntax-162/170) Tracking issues filed as part of decision: - Should there be a function type? #191 - Should types be values? #192 Finalized on 2020-11-24
Given the concern with overload sets, a good next step would be to flesh out a proposal for overload sets, etc. |
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please comment or remove the |
I'm moving this to a question for leads because it's coming up a bit again on #912. Can we get a tentative decision on what function type syntax should look like? In executable_semantics at present, supported syntax is both of Note #188 raises one complaint with a
Note we could do the "desired" syntax there with roughly:
In Swift, function types look like IIUC I can think of a couple ways to get Swift behavior:
Note, both might confuse developers without an introducer. I'm not convinced I'd catch that In Rust, function types look like I think we could do this because In Go, |
My preference would be to follow a similar approach to Rust: there are a few function-call interfaces that can be implemented for types, much like |
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please comment or remove the |
- [Proposal PR](#162) - [RFC topic](https://forums.carbon-lang.dev/t/rfc-basic-syntax/142) - [Decision request](https://forums.carbon-lang.dev/t/request-for-decision-basic-syntax-162/165) - [Decision announcement](https://forums.carbon-lang.dev/t/accepted-basic-syntax-162/170) Tracking issues filed as part of decision: - Should there be a function type? #191 - Should types be values? #192 Finalized on 2020-11-24
I would prefer that we do not have function types as first-class types, if we can avoid it. Rather, I would like to see if we can follow an approach like the one that @josh11b outlined:
This seems like it would generalize nicely to lambdas (which would be new, unique types which are not necessarily empty) and callable user-defined class types. It would also mean that passing a plain function to an algorithm taking a callable would work the same as passing a function object or a lambda, and would monomorphize to making a direct call. We'll still need to support function pointers in some way for efficient C++ interoperability. I think that function pointers would precisely correspond to |
Beyond @zygoloid's comment, I'd like to add: as commented far above, it also seems good to flesh out function overloading first so that it can be fully incorporated into this story. However, I don't think there is anything more to say on this question at this time. The answer is simply "no" -- the rationale is that we'd prefer instead to pursue a model that generalizes more smoothly with lambdas, callable class objects, and potentially overload sets. I think that's sufficient rationale for the "no" answer and a clear direction. How exactly the callable interface and all the machinery for Given that I've not heard any concerns or counter arguments to the "no" as suggested here, lets call this decided for now. When we get to the callable design, that's when to fill in all of the needed details there. |
This stems from discussion on Basic syntax #162:
https://github.com/carbon-language/carbon-lang/pull/162/files#r513840204
To summarize: should there be a function type, and if so, what form should it take? tituswinters highlights concerns about overload sets.
I think that key questions are:
fn
,fnty
, or something else?-> return_type
isn't present, is that a syntax error or does it indicate that an empty tuple is being returned?The text was updated successfully, but these errors were encountered: