proposal: Allow omitting types in callbacks if they can be inferred from the parameters #65369
Closed
3 of 4 tasks
Labels
Milestone
Go Programming Experience
Intermediate
Other Languages Experience
JS, Java, Python, Delphi, C
Related Idea
Has this idea, or one like it, been proposed before?
#21498
This issue is more general in how anonymous functions should behave, but it is not clearly defined in that proposal what should be done.
Does this affect error handling?
No
Is this about generics?
No, this is about inferring types from context in anonymous functions.
Proposal
It is possible to omit types for parameters in anonymous functions when the types can be inferred from the context.
Return type can be omitted because it can be inferred from the returned value in the anonymous function.
Parameter types are omitted as they can be inferred from the outer function declaration.
Language Spec Changes
Anonymous functions used as parameters in other functions can be written without re-declaring the parameter and return types, making anonymous functions more concise.
Informal Change
While using anonymous functions as parameters for other functions, the type definitions for the parameters and return values can be omitted, because the can be inferred from the context.
Is this change backward compatible?
Yes.
Given these functions:
Their usage would currently looks like this:
Expected usage with this proposal:
Orthogonality: How does this change interact or overlap with existing features?
No response
Would this change make Go easier or harder to learn, and why?
No response
Cost Description
No response
Changes to Go ToolChain
No response
Performance Costs
No response
Prototype
No response
The text was updated successfully, but these errors were encountered: