-
Notifications
You must be signed in to change notification settings - Fork 82
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
Make function types more general and symmetric #356
Comments
Personally, I like the symmetry in the abstract, and I can think of a few times where, when writing a WIT interface, I feel like I'm being forced to add a parameter name that adds no value (e.g., That being said, looking at all the WIT interfaces I'm seeing being written in practice, I basically never see use of non-empty I can see arguments for both cases; it makes me think that perhaps the current state of the proposal is stuck in a sort of uncanny valley between fully embracing symmetry or asymmetry, and so we should shift to one side or the other. But which one I'm not sure. I'd be interested to hear more thoughts on this! |
What confuses me is whether the return value with label is a tuple class or an anonymous class. If it is a tuple class, then you can actually express the real If it is an anonymous class, are |
As it is currently, since the string names of params and results are part of the function type and thus part of function-type-equality, the latter two are distinct (when used as a function's results), and so you'd think of them more like a |
FWIW, Go is the only language that I know to support named/unnamed multi-return without treating them as a tuple, unlike languages such as Python. Here is an example of "naked" named multi-return. func split(sum int) (x, y int) {
x = sum * 4 / 9
y = sum - x
return
} From Go's documentation, it says that "these names should be used to document the meaning of the return values." |
Another classic example is the Scheme/Lisp family of languages. |
Currently, the grammar for function types is as follows:
All parameters and results must be named, except a singleton result.
There is broad variety across programming languages in whether and how they allow/require/distinguish named vs unnamed parameters, as well as unnamed vs unnamed results, at a function's def site, use site, or both. The current design is rather specific in that regard and somewhat biased. From purely an interface perspective, there is no reason to treat parameters differently from results, or allow omitting names in some cases but not others. And at least for some languages, it would be useful to make explicit which components have "proper" names and which ones haven't, since that enables more idiomatic bindings.
See here for more discussion.
There are several degrees to which the grammar could be generalised:
or
or
I'd suggest one of the latter two, which make names uniformly optional, and then specify a canonical scheme for synthesised names in contexts/bind-gens that need them, for example,
"_1"
,"_2"
, etc. based on position. This would apply symmetrically to parameters and results.The text was updated successfully, but these errors were encountered: